Moq验证从未调用实体框架核心的更新



以下内容对于MockBehavior.Loose不会失败(即不需要安装)

void IContentDataStore.Update<T>(T entity)
{
GetDbSet<T>().Update(entity);
}
[Test]
...
ContentStoreMock.Verify(repo => repo.Update(existingRequest), Times.Never );

对于MockBehavior.Strict,需要特定的设置。

如果这个检查是有意义的,那么任何设置将是什么?对于期望的结果字符串,已经存在expectedStatusCode: HttpStatusCode.BadRequest和某些Assert.That

在我的情况下,即使对于MockBehavior.Strict也不需要安装,因为Verify纯粹是针对Times.Never的(即没有更新发生)

各自的Rest Put方法在执行其他操作之前返回BadRequest。

测试自身Update_Should_ReturnBadRequest_When_NameIsInvalid()

以下更改使测试通过:

ContentStoreMock.Verify(repo => repo.Update(It.IsAny<MonitoringRequest>()), Times.Never);

最新更新