以下内容对于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);