< Summary - Code Coverage

Information
Class: Plainquire.Page.EntityPageExtensions
Assembly: Plainquire.Page
File(s): /home/runner/work/plainquire/plainquire/Plainquire.Page/Plainquire.Page/Extensions/EntityPageExtensions.cs
Tag: 64_13932151703
Line coverage
100%
Covered lines: 27
Uncovered lines: 0
Coverable lines: 27
Total lines: 66
Line coverage: 100%
Branch coverage
100%
Covered branches: 30
Total branches: 30
Branch coverage: 100%
Method coverage
100%
Covered methods: 3
Total methods: 3
Method coverage: 100%

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
GetSkipAndTake(...)100%88100%
ParsePageNumber(...)100%1010100%
ParsePageSize(...)100%1212100%

File(s)

/home/runner/work/plainquire/plainquire/Plainquire.Page/Plainquire.Page/Extensions/EntityPageExtensions.cs

#LineLine coverage
 1using Plainquire.Page.Abstractions;
 2using System;
 3using System.Globalization;
 4
 5namespace Plainquire.Page;
 6
 7/// <summary>
 8/// Extension methods for <see cref="EntityPage"/>
 9/// </summary>
 10public static class EntityPageExtensions
 11{
 12    /// <summary>
 13    /// Get the skip and take values for the given <paramref name="page"/>.
 14    /// </summary>
 15    /// <param name="page"></param>
 16    /// <exception cref="InvalidOperationException"></exception>
 17    public static (int? Skip, int? Take) GetSkipAndTake(this EntityPage page)
 18    {
 25619        var configuration = page.Configuration ?? PageConfiguration.Default ?? new PageConfiguration();
 20
 25621        var pageNumber = ParsePageNumber(page, configuration);
 23222        var pageSize = ParsePageSize(page, configuration);
 23
 20124        var skip = (pageNumber - 1) * pageSize;
 25
 20126        return (skip, pageSize);
 27    }
 28
 29    private static int? ParsePageNumber(EntityPage page, PageConfiguration configuration)
 30    {
 25631        var pageNumberNotSet = string.IsNullOrEmpty(page.PageNumberValue);
 25632        if (pageNumberNotSet)
 6033            return null;
 34
 19635        var parseFailed = !int.TryParse(page.PageNumberValue, NumberStyles.None, CultureInfo.InvariantCulture, out var p
 19636        if (parseFailed && !configuration.IgnoreParseExceptions)
 1837            throw new FormatException($"Error while parsing page number '{page.PageNumberValue}'");
 38
 17839        if (pageNumber >= 1)
 15440            return pageNumber;
 41
 2442        if (configuration.IgnoreParseExceptions)
 1843            return 1;
 44
 645        throw new FormatException($"{nameof(EntityPage.PageNumber)} must be a positive integer, found: {page.PageNumber}
 46    }
 47
 48    private static int? ParsePageSize(EntityPage page, PageConfiguration configuration)
 49    {
 23250        var pageSizeNotSet = string.IsNullOrEmpty(page.PageSizeValue);
 23251        if (pageSizeNotSet && !configuration.IgnoreParseExceptions)
 1252            throw new InvalidOperationException("Page size not set");
 53
 22054        var parseFailed = !int.TryParse(page.PageSizeValue, NumberStyles.None, CultureInfo.InvariantCulture, out var pag
 22055        if (parseFailed && !configuration.IgnoreParseExceptions)
 1356            throw new FormatException($"Error while parsing page size '{page.PageSizeValue}'");
 57
 20758        if (pageSize >= 1)
 16859            return pageSize;
 60
 3961        if (configuration.IgnoreParseExceptions)
 3362            return int.MaxValue;
 63
 664        throw new FormatException($"{nameof(EntityPage.PageSize)} must be a positive integer, found: {page.PageSize}.");
 65    }
 66}