using System;
using System.Collections.Generic;
using Xunit;
using CncModels.Dto;

namespace CncModels.Tests
{
    /// <summary>
    /// PagedResult<T> 单元测试
    /// </summary>
    public class PagedResultTests
    {
        [Theory]
        [InlineData(20, 20, 1)]
        [InlineData(21, 20, 2)]
        [InlineData(0, 10, 0)]
        public void TotalPages_Calculation_Works(int total, int pageSize, int expectedPages)
        {
            // Arrange
            var r = new PagedResult<string>
            {
                Total = total,
                PageSize = pageSize,
                Page = 1
            };

            // Act & Assert
            Assert.Equal(expectedPages, r.TotalPages);
        }

        [Fact]
        /// <summary>
        /// Items 属性默认应为空列表而非 null
        /// </summary>
        public void Items_Should_Be_Empty_List_By_Default()
        {
            // Arrange
            var r = new PagedResult<string>();

            // Assert
            Assert.NotNull(r.Items);
            Assert.Empty(r.Items);
        }

        [Fact]
        /// <summary>
        /// 属性赋值正确
        /// </summary>
        public void Properties_Assigned_Correctly()
        {
            // Arrange
            var items = new List<string> { "a", "b" };
            var r = new PagedResult<string>
            {
                Items = items,
                Total = 2,
                Page = 1,
                PageSize = 2
            };

            // Assert
            Assert.Equal(items, r.Items);
            Assert.Equal(2, r.Total);
            Assert.Equal(1, r.Page);
            Assert.Equal(2, r.PageSize);
            Assert.Equal(1, r.TotalPages); // 2/2 = 1
        }
    }
}
