36 lines
1.8 KiB
C#
36 lines
1.8 KiB
C#
using System.Net;
|
|
using Jiaowu.Api.Infrastructure.AcademicCalendar;
|
|
|
|
namespace Jiaowu.Api.Tests;
|
|
|
|
public sealed class HolidayCnClientTests
|
|
{
|
|
private sealed class StubHandler(string body) : HttpMessageHandler
|
|
{
|
|
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) =>
|
|
Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(body) });
|
|
}
|
|
|
|
private static HolidayCnClient Client(string body) => new(new HttpClient(new StubHandler(body)) { BaseAddress = new Uri("https://example.test/") });
|
|
|
|
[Fact]
|
|
public async Task Accepts_holidays_and_makeup_workdays()
|
|
{
|
|
const string json = """{"year":2026,"papers":[],"days":[{"name":"holiday","date":"2026-01-01","isOffDay":true},{"name":"makeup","date":"2026-01-04","isOffDay":false}]}""";
|
|
var result = await Client(json).GetYearAsync(2026, CancellationToken.None);
|
|
Assert.True(result.Days[0].IsOffDay);
|
|
Assert.False(result.Days[1].IsOffDay);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("{")]
|
|
[InlineData("{\"year\":2026,\"papers\":[],\"days\":null}")]
|
|
[InlineData("{\"year\":2026,\"papers\":[],\"days\":[{\"name\":\"holiday\",\"date\":\"2026-01-01\"}]}")]
|
|
[InlineData("{\"year\":2026,\"papers\":[],\"days\":[{\"name\":\"holiday\",\"date\":\"2027-01-01\",\"isOffDay\":true}]}")]
|
|
[InlineData("{\"year\":2026,\"papers\":[],\"days\":[{\"name\":\"a\",\"date\":\"2026-01-01\",\"isOffDay\":true},{\"name\":\"b\",\"date\":\"2026-01-01\",\"isOffDay\":false}]}")]
|
|
public async Task Rejects_malformed_or_ambiguous_source_data(string json)
|
|
{
|
|
await Assert.ThrowsAsync<InvalidOperationException>(() => Client(json).GetYearAsync(2026, CancellationToken.None));
|
|
}
|
|
}
|