How can I test return await _propertyRepository.UnitOfWork.SaveEntitiesAsync();?
AddCommandHandler
public async Task<bool> Handle(AddCommand message, CancellationToken cancellationToken)
{
_logger.LogInformation("----- Adding Property - Property: {@Property}", property);
_propertyRepository.Add(property);
return await _propertyRepository.UnitOfWork.SaveEntitiesAsync();
}
Anyone please guide me to write test case for that only. I am writing like this. But the test case fails.
PropertyRepository
public class PropertyRepository : IPropertyRepository
{
private readonly RealxContext _realxContext;
public IUnitOfWork UnitOfWork
{
get
{
return _realxContext;
}
}
public PropertyRepository(RealxContext realxContext)
{
_realxContext = realxContext ?? throw new ArgumentNullException(nameof(realxContext));
}
AddCommandHandlerTests.cs
_propertyRepository.Setup(propertyRepo => propertyRepo.UnitOfWork.SaveEntitiesAsync(default(CancellationToken))).Returns(Task.FromResult(true));