< Summary - Code Coverage

Information
Class: Plainquire.Page.JsonConverters.EntityPageConverter<T>
Assembly: Plainquire.Page
File(s): /home/runner/work/plainquire/plainquire/Plainquire.Page/Plainquire.Page/JsonConverters/EntityPageConverter.cs
Tag: 64_13932151703
Line coverage
100%
Covered lines: 2
Uncovered lines: 0
Coverable lines: 2
Total lines: 83
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage
100%
Covered methods: 2
Total methods: 2
Method coverage: 100%

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
Read(...)100%11100%
Write(...)100%11100%

File(s)

/home/runner/work/plainquire/plainquire/Plainquire.Page/Plainquire.Page/JsonConverters/EntityPageConverter.cs

#LineLine coverage
 1using System;
 2using System.Text.Json;
 3using System.Text.Json.Serialization;
 4
 5namespace Plainquire.Page.JsonConverters;
 6
 7/// <summary>
 8/// <see cref="EntityPage{TEntity}"/> specific JSON converter for Microsoft (System.Text.Json) JSON.
 9/// Implements <see cref="JsonConverter{T}" />
 10/// </summary>
 11/// <typeparam name="TEntity">The type of the entity be paged.</typeparam>
 12/// <seealso cref="JsonConverter{T}" />
 13public class EntityPageConverter<TEntity> : JsonConverter<EntityPage<TEntity>>
 14{
 15    /// <inheritdoc />
 16    public override EntityPage<TEntity> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions option
 8317        => EntityPageConverter.Read<EntityPage<TEntity>>(ref reader, options);
 18
 19    /// <inheritdoc />
 20    public override void Write(Utf8JsonWriter writer, EntityPage<TEntity> value, JsonSerializerOptions options)
 8321        => EntityPageConverter.Write(writer, value, options);
 22}
 23
 24/// <summary>
 25/// <see cref="EntityPage"/> specific JSON converter for Microsoft (System.Text.Json) JSON.
 26/// Implements <see cref="JsonConverter{T}" />
 27/// </summary>
 28/// <seealso cref="JsonConverter{T}" />
 29public class EntityPageConverter : JsonConverter<EntityPage>
 30{
 31    /// <inheritdoc />
 32    public override EntityPage Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
 33        => Read<EntityPage>(ref reader, options);
 34
 35    /// <inheritdoc />
 36    public override void Write(Utf8JsonWriter writer, EntityPage value, JsonSerializerOptions options)
 37        => Write(writer, value, options);
 38
 39    internal static TEntityPage Read<TEntityPage>(ref Utf8JsonReader reader, JsonSerializerOptions options)
 40        where TEntityPage : EntityPage, new()
 41    {
 42        var entityPageData = JsonSerializer.Deserialize<EntityPageData>(ref reader, options) ?? new EntityPageData();
 43        return new TEntityPage
 44        {
 45            PageNumberValue = entityPageData.PageNumber ?? string.Empty,
 46            PageSizeValue = entityPageData.PageSize ?? string.Empty,
 47            Configuration = entityPageData.Configuration
 48        };
 49    }
 50
 51    internal static void Write<TEntityPage>(Utf8JsonWriter writer, TEntityPage value, JsonSerializerOptions options)
 52        where TEntityPage : EntityPage
 53    {
 54        var entityPageData = new EntityPageData
 55        {
 56            PageNumber = value.PageNumberValue,
 57            PageSize = value.PageSizeValue,
 58            Configuration = value.Configuration
 59        };
 60
 61        JsonSerializer.Serialize(writer, entityPageData, options);
 62    }
 63
 64    /// <summary>
 65    /// <see cref="EntityPage{TEntity}"/> specific JSON converter factory for Microsoft (System.Text.Json) JSON.
 66    /// Implements <see cref="JsonConverterFactory" />
 67    /// </summary>
 68    /// <seealso cref="JsonConverterFactory" />
 69    public class Factory : JsonConverterFactory
 70    {
 71        /// <inheritdoc />
 72        public override bool CanConvert(Type typeToConvert)
 73            => typeToConvert.IsEntityPage();
 74
 75        /// <inheritdoc />
 76        public override JsonConverter? CreateConverter(Type typeToConvert, JsonSerializerOptions options)
 77        {
 78            var entityType = typeToConvert.GetGenericArguments()[0];
 79            var entityPageConverterType = typeof(EntityPageConverter<>).MakeGenericType(entityType);
 80            return (JsonConverter?)Activator.CreateInstance(entityPageConverterType);
 81        }
 82    }
 83}