< Summary - Code Coverage

Information
Class: Plainquire.Page.EntityPage
Assembly: Plainquire.Page
File(s): /home/runner/work/plainquire/plainquire/Plainquire.Page/Plainquire.Page/Pages/EntityPage.cs
Tag: 64_13932151703
Line coverage
68%
Covered lines: 13
Uncovered lines: 6
Coverable lines: 19
Total lines: 126
Line coverage: 68.4%
Branch coverage
62%
Covered branches: 10
Total branches: 16
Branch coverage: 62.5%
Method coverage
81%
Covered methods: 9
Total methods: 11
Method coverage: 81.8%

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%11100%
.ctor(...)100%110%
.ctor(...)100%11100%
.ctor(...)100%110%
Clone()100%11100%

File(s)

/home/runner/work/plainquire/plainquire/Plainquire.Page/Plainquire.Page/Pages/EntityPage.cs

#LineLine coverage
 1using Plainquire.Page.Abstractions;
 2using Plainquire.Page.JsonConverters;
 3using System;
 4using System.Globalization;
 5using System.Text.Json;
 6using System.Text.Json.Serialization;
 7
 8namespace Plainquire.Page;
 9
 10/// <summary>
 11/// Hub to create pagination for <typeparamref name="TEntity"/>.
 12/// </summary>
 13/// <typeparam name="TEntity">The entity type to be paged.</typeparam>
 14[JsonConverter(typeof(EntityPageConverter.Factory))]
 15public class EntityPage<TEntity> : EntityPage
 16{
 17    /// <inheritdoc />
 18    public EntityPage() { }
 19
 20    /// <inheritdoc />
 21    public EntityPage(PageConfiguration configuration)
 22        : base(configuration) { }
 23
 24    /// <inheritdoc />
 25    public EntityPage(int? pageNumber, int? pageSize)
 26        : base(pageNumber, pageSize) { }
 27
 28    /// <inheritdoc />
 29    public EntityPage(int? pageNumber, int? pageSize, PageConfiguration configuration)
 30        : base(pageNumber, pageSize, configuration) { }
 31
 32    /// <summary>
 33    /// Creates a deep clone of this page.
 34    /// </summary>
 35    public new EntityPage<TEntity> Clone()
 36        => JsonSerializer.Deserialize<EntityPage<TEntity>>(JsonSerializer.Serialize(this))!;
 37
 38    /// <summary>
 39    /// Casts this page to a different entity type (by creating a deep clone).
 40    /// </summary>
 41    /// <typeparam name="TDestination">The type of the destination entity to page.</typeparam>
 42    public EntityPage<TDestination> Cast<TDestination>()
 43        => JsonSerializer.Deserialize<EntityPage<TDestination>>(JsonSerializer.Serialize(this))!;
 44}
 45
 46/// <inheritdoc cref="EntityPage{TEntity}" />
 47[JsonConverter(typeof(EntityPageConverter))]
 48public class EntityPage : ICloneable
 49{
 24250    internal string PageNumberValue = string.Empty;
 24251    internal string PageSizeValue = string.Empty;
 52
 53    /// <summary>
 54    /// Gets or sets the default configuration. Can be used to set a system-wide configuration.
 55    /// </summary>
 56    public PageConfiguration? Configuration { get; internal set; }
 57
 58    /// <summary>
 59    /// The page number to get.
 60    /// </summary>
 61    public int? PageNumber
 62    {
 39763        get => int.TryParse(PageNumberValue, NumberStyles.None, CultureInfo.InvariantCulture, out var page) ? page : nul
 1664        set => PageNumberValue = value?.ToString(CultureInfo.InvariantCulture) ?? string.Empty;
 65    }
 66
 67    /// <summary>
 68    /// The page size to use.
 69    /// </summary>
 70    public int? PageSize
 71    {
 70772        get => int.TryParse(PageSizeValue, NumberStyles.None, CultureInfo.InvariantCulture, out var pageSize) ? pageSize
 1673        set => PageSizeValue = value?.ToString(CultureInfo.InvariantCulture) ?? string.Empty;
 74    }
 75
 76    /// <summary>
 77    /// Number of rows to skip when fetching the page.
 78    /// </summary>
 479    public int? Skip => (PageNumber - 1) * PageSize;
 80
 81    /// <summary>
 82    /// Number of rows to take when fetching the page.
 83    /// </summary>
 484    public int? Take => PageSize;
 85
 86    /// <summary>
 87    /// Creates a new instance of <see cref="EntityPage"/>.
 88    /// </summary>
 23289    public EntityPage() { }
 90
 91    /// <summary>
 92    /// Creates a new instance of <see cref="EntityPage"/>.
 93    /// </summary>
 94    /// <param name="configuration">The configuration to use.</param>
 95    public EntityPage(PageConfiguration configuration)
 096        : this()
 097        => Configuration = configuration;
 98
 99    /// <summary>
 100    /// Creates a new instance of <see cref="EntityPage"/>.
 101    /// </summary>
 102    /// <param name="pageNumber">Page number.</param>
 103    /// <param name="pageSize">Page size.</param>
 104    public EntityPage(int? pageNumber, int? pageSize)
 105    {
 10106        PageNumber = pageNumber;
 10107        PageSize = pageSize;
 10108    }
 109
 110    /// <summary>
 111    /// Creates a new instance of <see cref="EntityPage"/>.
 112    /// </summary>
 113    /// <param name="pageNumber">Page number.</param>
 114    /// <param name="pageSize">Page size.</param>
 115    /// <param name="configuration">The configuration to use.</param>
 116    public EntityPage(int? pageNumber, int? pageSize, PageConfiguration configuration)
 117    {
 0118        PageNumber = pageNumber;
 0119        PageSize = pageSize;
 0120        Configuration = configuration;
 0121    }
 122
 123    /// <inheritdoc />
 124    public object Clone()
 1125        => JsonSerializer.Deserialize<EntityPage>(JsonSerializer.Serialize(this))!;
 126}