mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-10-07 16:19:07 +00:00
Align week presets to Mon-Fri, treat types=Other as past-due, expand text search, whitelist sortBy, and use 0-based paging for advanced search without breaking 1-based PagedResult consumers.
51 lines
1.8 KiB
C#
51 lines
1.8 KiB
C#
using FluentAssertions;
|
|
using SeaHaven.Services.DTOs;
|
|
using Xunit;
|
|
|
|
namespace SeaHaven.Services.Tests;
|
|
|
|
public class PagedResultTests
|
|
{
|
|
[Theory]
|
|
[InlineData(0, 10, 0)]
|
|
[InlineData(1, 10, 1)]
|
|
[InlineData(10, 10, 1)]
|
|
[InlineData(11, 10, 2)]
|
|
[InlineData(100, 25, 4)]
|
|
public void TotalPages_IsCeilingOfCountOverPageSize(int totalCount, int pageSize, int expectedPages)
|
|
{
|
|
var result = new PagedResult<string> { TotalCount = totalCount, PageSize = pageSize, Page = 1 };
|
|
|
|
result.TotalPages.Should().Be(expectedPages);
|
|
}
|
|
|
|
[Fact]
|
|
public void HasPrevious_IsFalseOnFirstPage_TrueAfterward_OneBased()
|
|
{
|
|
new PagedResult<string> { Page = 1, PageSize = 10, TotalCount = 30 }.HasPrevious.Should().BeFalse();
|
|
new PagedResult<string> { Page = 2, PageSize = 10, TotalCount = 30 }.HasPrevious.Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void HasNext_IsTrueBeforeLastPage_FalseOnLastPage_OneBased()
|
|
{
|
|
new PagedResult<string> { Page = 2, PageSize = 10, TotalCount = 30 }.HasNext.Should().BeTrue();
|
|
new PagedResult<string> { Page = 3, PageSize = 10, TotalCount = 30 }.HasNext.Should().BeFalse();
|
|
}
|
|
|
|
[Fact]
|
|
public void HasPrevious_And_HasNext_ZeroBased_WhenPageBaseIsZero()
|
|
{
|
|
var first = new PagedResult<string> { Page = 0, PageSize = 10, TotalCount = 30, PageBase = 0 };
|
|
first.HasPrevious.Should().BeFalse();
|
|
first.HasNext.Should().BeTrue();
|
|
|
|
var middle = new PagedResult<string> { Page = 1, PageSize = 10, TotalCount = 30, PageBase = 0 };
|
|
middle.HasPrevious.Should().BeTrue();
|
|
middle.HasNext.Should().BeTrue();
|
|
|
|
var last = new PagedResult<string> { Page = 2, PageSize = 10, TotalCount = 30, PageBase = 0 };
|
|
last.HasPrevious.Should().BeTrue();
|
|
last.HasNext.Should().BeFalse();
|
|
}
|
|
}
|