Having the ability to mock date/time constructs seems long overdue. .NET 8 only recently addressed the capability gap through the abstraction. RCommon has had the ISystemTime abstraction for many years now.
Copy builder.Services.AddRCommon()
.WithDateTimeSystem(dateTime => dateTime.Kind = DateTimeKind.Utc)
Copy public class CreateLighthouseProfileCommandHandler : IAppRequestHandler<CreateLighthouseProfileCommand, LighthouseProfileResponse>
{
private readonly ISystemTime _systemTime;
public CreateLighthouseProfileCommandHandler(ISystemTime systemTime)
{
_systemTime = systemTime;
}
public async Task<LighthouseProfileResponse> HandleAsync(CreateLighthouseProfileCommand request, CancellationToken cancellationToken)
{
LighthouseProfile profile = new LighthouseProfile(_systemTime.Now, request.WebsiteUrl, request.CreatedByEmail);