LotusIsWorking
❔ How do you properly register NLog with .NET 6?
services.AddLogging(builder =>
{
builder.ClearProviders();
builder.AddConsole();
builder.AddDebug();
builder.AddNLogWeb("nlog.config");
});
services.AddLogging(builder =>
{
builder.ClearProviders();
builder.AddConsole();
builder.AddDebug();
builder.AddNLogWeb("nlog.config");
});
5 replies
❔ Proper mocking for Unit Testing (NUnit)
public class TargetServiceSetEndDateAsTwoMonthsOut : PreProcessorAction<CreateTargetServiceCommand>
{
private readonly IDateTime _dateTime;
public TargetServiceSetEndDateAsTwoMonthsOut(IDateTime datetime)
{
this._dateTime = datetime;
}
public override Task<bool> CanProcessAsync(CreateTargetServiceCommand command)
{
if (command != null && command.ServiceType == ServiceType.STR)
return Task.FromResult(true);
else
return Task.FromResult(false);
}
public override async Task ProcessAsync(CreateTargetServiceCommand command)
{
command.EndDate = DateOnly.FromDateTime(this._dateTime.Now).AddMonths(2);
await Task.CompletedTask;
}
}
[Test]
public async Task TargetServiceSetStartDateAsToday_EqualProcessTest()
{
var mockRepo = new Mock<IDateTime>();
var rule = new TargetServiceSetStartDateAsToday(mockRepo.Object);
var command = GetCommandWithReferenceTarget();
await rule.ProcessAsync(command);
Assert.AreEqual(command.StartDate, DateOnly.FromDateTime(mockRepo.Object.Now));
}
public class TargetServiceSetEndDateAsTwoMonthsOut : PreProcessorAction<CreateTargetServiceCommand>
{
private readonly IDateTime _dateTime;
public TargetServiceSetEndDateAsTwoMonthsOut(IDateTime datetime)
{
this._dateTime = datetime;
}
public override Task<bool> CanProcessAsync(CreateTargetServiceCommand command)
{
if (command != null && command.ServiceType == ServiceType.STR)
return Task.FromResult(true);
else
return Task.FromResult(false);
}
public override async Task ProcessAsync(CreateTargetServiceCommand command)
{
command.EndDate = DateOnly.FromDateTime(this._dateTime.Now).AddMonths(2);
await Task.CompletedTask;
}
}
[Test]
public async Task TargetServiceSetStartDateAsToday_EqualProcessTest()
{
var mockRepo = new Mock<IDateTime>();
var rule = new TargetServiceSetStartDateAsToday(mockRepo.Object);
var command = GetCommandWithReferenceTarget();
await rule.ProcessAsync(command);
Assert.AreEqual(command.StartDate, DateOnly.FromDateTime(mockRepo.Object.Now));
}
4 replies