如何为等待_propertyRepository.UnitOfWork.SaveEntitiesAsync()创建xUnit测试用例?

时间:2019-07-02 09:25:50

标签: c# asp.net-web-api .net-core microservices

如何测试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();
}

任何人都请引导我为此编写测试用例。我这样写。但是测试用例失败。

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));

0 个答案:

没有答案