< Summary

Information
Class: MyNet.Observable.Collections.Paging.PagingEngine
Assembly: MyNet.Observable
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Observable/Collections/Paging/PagingEngine.cs
Tag: 323_28699572109
Line coverage
83%
Covered lines: 10
Uncovered lines: 2
Coverable lines: 12
Total lines: 59
Line coverage: 83.3%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
get_State()100%11100%
Set(...)50%2266.66%
Clear()100%11100%
Dispose()100%11100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Observable/Collections/Paging/PagingEngine.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="PagingEngine.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Reactive.Subjects;
 9
 10namespace MyNet.Observable.Collections.Paging;
 11
 12/// <summary>
 13/// Maintains the active paging window applied after filtering and sorting.
 14/// </summary>
 15public sealed class PagingEngine : IDisposable
 16{
 18617    private readonly BehaviorSubject<(int Page, int PageSize)?> _state = new(null);
 18
 19    /// <summary>
 20    /// Gets an observable paging state consumed by the collection pipeline.
 21    /// A <see langword="null"/> value disables paging.
 22    /// </summary>
 37223    public IObservable<(int Page, int PageSize)?> State => _state;
 24
 25    /// <summary>
 26    /// Gets a value indicating whether paging is currently active.
 27    /// </summary>
 28    public bool IsEnabled { get; private set; }
 29
 30    /// <summary>
 31    /// Sets the active page window.
 32    /// </summary>
 33    /// <param name="page">The one-based page index.</param>
 34    /// <param name="pageSize">The page size.</param>
 35    public void Set(int page, int pageSize)
 36    {
 6037        if (pageSize <= 0)
 38        {
 039            Clear();
 040            return;
 41        }
 42
 6043        IsEnabled = true;
 6044        _state.OnNext((Math.Max(page, 1), pageSize));
 6045    }
 46
 47    /// <summary>
 48    /// Disables paging and exposes the full filtered collection through the paged view.
 49    /// </summary>
 50    public void Clear()
 51    {
 5452        IsEnabled = false;
 5453        _state.OnNext(null);
 5454    }
 55
 56    /// <inheritdoc />
 15657    public void Dispose() => _state.Dispose();
 58}
 59