55 lines
1.9 KiB
C#
55 lines
1.9 KiB
C#
using System.Net;
|
|
using FluentAssertions;
|
|
using Moq;
|
|
using Oms.Application.Dtos.Shared;
|
|
using Oms.Application.Dtos.System;
|
|
using Oms.Domain.SystemAggregate.Entities;
|
|
using Oms.Domain.SystemAggregate.Repositories;
|
|
using SimpleAdmin.Api.IntegrationTests.Support;
|
|
|
|
namespace SimpleAdmin.Api.IntegrationTests;
|
|
|
|
public class DictApiIntegrationTests
|
|
{
|
|
[Fact]
|
|
public async Task GetDictList_ShouldReturnPagedResultFromRepository()
|
|
{
|
|
var repository = new Mock<IDictRepository>();
|
|
repository
|
|
.Setup(x => x.GetPagedListAsync(
|
|
It.IsAny<System.Linq.Expressions.Expression<Func<Dict, bool>>>(),
|
|
It.IsAny<int>(),
|
|
It.IsAny<int>(),
|
|
It.IsAny<Dictionary<string, bool>>(),
|
|
It.IsAny<CancellationToken>()))
|
|
.ReturnsAsync([
|
|
new Dict
|
|
{
|
|
Id = 9,
|
|
DictType = "orderStatus",
|
|
DictSort = 1,
|
|
DictCode = "draft",
|
|
DictName = "草稿",
|
|
CreateTime = new DateTime(2026, 4, 28, 10, 0, 0)
|
|
}
|
|
]);
|
|
repository
|
|
.Setup(x => x.CountAsync(
|
|
It.IsAny<System.Linq.Expressions.Expression<Func<Dict, bool>>>(),
|
|
It.IsAny<CancellationToken>()))
|
|
.ReturnsAsync(1);
|
|
|
|
await using var host = await SimpleAdminApiTestHost.CreateAsync(dictRepository: repository.Object);
|
|
|
|
var response = await host.Client.GetAsync("/system/dict/list?Page=1&PageSize=20");
|
|
|
|
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
|
var payload = await response.Content.ReadFromJsonAsync<OmsPageResult<DictOutput>>();
|
|
payload.Should().NotBeNull();
|
|
payload!.Total.Should().Be(1);
|
|
payload.Items.Should().ContainSingle();
|
|
payload.Items[0].DictCode.Should().Be("draft");
|
|
payload.Items[0].DictName.Should().Be("草稿");
|
|
}
|
|
}
|