You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
haoliang-net/tests/CncModels.Tests/PagedQueryTests.cs

104 lines
2.6 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using Xunit;
using CncModels.Dto;
using CncModels.Dto.Login;
using CncModels.Dto.Machine;
namespace CncModels.Tests
{
/// <summary>
/// PagedQuery 单元测试:覆盖默认值、偏移计算与自动修正逻辑
/// </summary>
public class PagedQueryTests
{
[Fact]
/// <summary>
/// 默认值正确page=1, pageSize=20, offset=0
/// </summary>
public void Page_Defaults_Are_Correct()
{
// Arrange/Act
var q = new PagedQuery();
// Assert
Assert.Equal(1, q.Page);
Assert.Equal(20, q.PageSize);
Assert.Equal(0, q.Offset);
}
[Fact]
/// <summary>
/// 标准赋值Page=3, PageSize=10 -> Offset=20
/// </summary>
public void Page_And_PageSize_Normal_Assignments()
{
// Arrange
var q = new PagedQuery
{
Page = 3,
PageSize = 10
};
// Assert
Assert.Equal(3, q.Page);
Assert.Equal(10, q.PageSize);
Assert.Equal(20, q.Offset);
}
[Fact]
/// <summary>
/// 边界Page=100, PageSize=20
/// </summary>
public void Page_Boundary_Normal()
{
var q = new PagedQuery { Page = 100, PageSize = 20 };
Assert.Equal(100, q.Page);
Assert.Equal(20, q.PageSize);
Assert.Equal(1980, q.Offset);
}
[Fact]
/// <summary>
/// 自动修正Page=0 -> 1
/// </summary>
public void Page_AutoFix_When_Zero()
{
var q = new PagedQuery { Page = 0 };
Assert.Equal(1, q.Page);
}
[Fact]
/// <summary>
/// 自动修正Page=-5 -> 1
/// </summary>
public void Page_AutoFix_When_Negative()
{
var q = new PagedQuery { Page = -5 };
Assert.Equal(1, q.Page);
}
[Fact]
/// <summary>
/// 自动修正PageSize=0 -> 20
/// </summary>
public void PageSize_AutoFix_When_Zero()
{
var q = new PagedQuery { PageSize = 0 };
Assert.Equal(20, q.PageSize);
}
[Fact]
/// <summary>
/// 自动修正PageSize=101 -> 100
/// </summary>
public void PageSize_AutoFix_When_Over_Max()
{
var q1 = new PagedQuery { PageSize = 101 };
Assert.Equal(100, q1.PageSize);
var q2 = new PagedQuery { PageSize = 999 };
Assert.Equal(100, q2.PageSize);
}
}
}