【发布时间】:2020-04-07 05:40:57
【问题描述】:
我对使用 Moq 还是很陌生,我遇到了一个问题,即我的一个方法调用返回 null,尽管我已经模拟了它。
我正在模拟以下接口。
public interface IUnitOfWorkFactory
{
IUnitOfWork Create(KnownDbContexts knownDbContexts);
}
public interface IUnitOfWork : IDisposable
{
Task SaveChanges();
IRepository Repository { get; }
}
然后在我的单元测试代码中它看起来像这样。
_uowFactoryMock.Setup(x => x.Create(It.IsAny<KnownDbContexts>()))
.Returns(It.IsAny<IUnitOfWork>());
我正在测试的代码如下所示。
using (var uow = _unitOfWorkFactory.Create(KnownDbContexts.UserDefined1))
{
// At this point 'uow' is null.
}
为什么 IUnitOfWorkFactory.Create 返回 null?
【问题讨论】:
标签: c# unit-testing moq