我想检查是否执行Update
了对对象方法的调用RealtyObjectEntityRepository
。我的服务中有以下方法:
public void UpdateRealtyObject(RealtyObjectDTO realtyObject)
{
List<Tuple<string, string>> changedItems = new List<Tuple<string, string>>();
RealtyObject before = this.unit.RealtyObjectRepository.GetById(realtyObject.RealtyObjectId);
var realtyObjectEntity = Converter.FromDTO(realtyObject);
this.unit.RealtyObjectRepository.Update(realtyObjectEntity);
}
如果方法被调用,我已经编写了测试来测试 if 方法:
[TestMethod]
public void UpdateRealtyObject()
{
IWindsorContainer container = new WindsorContainer();
var originalObject = new RealtyObject() { RealtyObjectId = 1, Description = "W", KOATUUId = "495857566455" };
var updatedObject = new RealtyObject() { RealtyObjectId = 1, Description = "Wa", KOATUUId = "495857566456" };
var mock = new Mock<RealtyObjectEntityRepository>();
mock.Setup<RealtyObject>(x => x.GetById(originalObject.RealtyObjectId)).Returns(originalObject);
container.Register(Component.For<IRepository<RealtyObject>>().Instance(mock.Object).LifeStyle.Transient);
var service = new RealEstateService(container);
service.UpdateRealtyObject(updatedObject.ToDTO());
mock.Verify(m=>m.Update(updatedObject));
}
但是我有一个例外
对模拟的预期调用至少一次,但从未执行过:m => m.Update(.updatedObject)。未配置任何设置。
有人可以建议我这里有什么问题吗?