我想检查是否已执行对象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);
}
我已经编写了测试方法来测试方法是否被调用:
[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 =&gt; m.Update(.updatedObject)。没有配置设置。
有人能告诉我这里的问题是什么吗?