使用 TimeProvider 类注入时间

This commit is contained in:
administrator committed 2025-03-15 21:15:59 +08:00
1 parent 81c8f608dc
commit c10d9726a2
13 files changed
+28 -61

No files matched your search

@@ -9,6 +9,7 @@ using HelloShop.ProductService.Infrastructure;
using HelloShop.ProductService.Models.Products;
using HelloShop.ProductService.UnitTests.Helpers;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Time.Testing;
namespace HelloShop.ProductService.UnitTests
{
@@ -60,5 +61,16 @@ namespace HelloShop.ProductService.UnitTests
Assert.Equal(productName, result?.Name);
});
}
[Fact]
public async Task UseTimeProviderTestService()
{
FakeTimeProvider fakeTimeProvider = new();
fakeTimeProvider.SetUtcNow(fakeTimeProvider.GetUtcNow().AddDays(1));
Assert.Equal(DateTime.UtcNow.AddHours(1), fakeTimeProvider.GetUtcNow());
await Task.CompletedTask;
}
}
}