< Summary - Code Coverage

Information
Class: Plainquire.Page.EntityPage<T>
Assembly: Plainquire.Page
File(s): /home/runner/work/plainquire/plainquire/Plainquire.Page/Plainquire.Page/Pages/EntityPage.cs
Tag: 64_13932151703
Line coverage
66%
Covered lines: 4
Uncovered lines: 2
Coverable lines: 6
Total lines: 126
Line coverage: 66.6%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage
66%
Covered methods: 4
Total methods: 6
Method coverage: 66.6%

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%11100%
.ctor(...)100%110%
.ctor(...)100%11100%
.ctor(...)100%110%
Clone()100%11100%
Cast()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 />
 43018    public EntityPage() { }
 19
 20    /// <inheritdoc />
 21    public EntityPage(PageConfiguration configuration)
 022        : base(configuration) { }
 23
 24    /// <inheritdoc />
 25    public EntityPage(int? pageNumber, int? pageSize)
 1426        : base(pageNumber, pageSize) { }
 27
 28    /// <inheritdoc />
 29    public EntityPage(int? pageNumber, int? pageSize, PageConfiguration configuration)
 030        : base(pageNumber, pageSize, configuration) { }
 31
 32    /// <summary>
 33    /// Creates a deep clone of this page.
 34    /// </summary>
 35    public new EntityPage<TEntity> Clone()
 8236        => 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>()
 143        => JsonSerializer.Deserialize<EntityPage<TDestination>>(JsonSerializer.Serialize(this))!;
 44}
 45
 46/// <inheritdoc cref="EntityPage{TEntity}" />
 47[JsonConverter(typeof(EntityPageConverter))]
 48public class EntityPage : ICloneable
 49{
 50    internal string PageNumberValue = string.Empty;
 51    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    {
 63        get => int.TryParse(PageNumberValue, NumberStyles.None, CultureInfo.InvariantCulture, out var page) ? page : nul
 64        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    {
 72        get => int.TryParse(PageSizeValue, NumberStyles.None, CultureInfo.InvariantCulture, out var pageSize) ? pageSize
 73        set => PageSizeValue = value?.ToString(CultureInfo.InvariantCulture) ?? string.Empty;
 74    }
 75
 76    /// <summary>
 77    /// Number of rows to skip when fetching the page.
 78    /// </summary>
 79    public int? Skip => (PageNumber - 1) * PageSize;
 80
 81    /// <summary>
 82    /// Number of rows to take when fetching the page.
 83    /// </summary>
 84    public int? Take => PageSize;
 85
 86    /// <summary>
 87    /// Creates a new instance of <see cref="EntityPage"/>.
 88    /// </summary>
 89    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)
 96        : this()
 97        => 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    {
 106        PageNumber = pageNumber;
 107        PageSize = pageSize;
 108    }
 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    {
 118        PageNumber = pageNumber;
 119        PageSize = pageSize;
 120        Configuration = configuration;
 121    }
 122
 123    /// <inheritdoc />
 124    public object Clone()
 125        => JsonSerializer.Deserialize<EntityPage>(JsonSerializer.Serialize(this))!;
 126}