【发布时间】:2014-03-13 12:11:54
【问题描述】:
我是 MOQ 的新手,我已阅读快速入门 here。我正在使用 MOQ v4.2.1402.2112。我正在尝试创建一个用于更新人员对象的单元测试。 UpdatePerson 方法返回更新后的人员对象。谁能告诉我如何纠正这个问题?
我收到此错误:
Moq.MockException was unhandled by user code
HResult=-2146233088
Message=Error updating Person object
Expected invocation on the mock once, but was 0 times: svc => svc.UpdatePerson(.expected)
Configured setups: svc => svc.UpdatePerson(It.IsAny<Person>()), Times.Never
No invocations performed.
Source=Moq
IsVerificationError=true
这是我的代码:
[TestMethod]
public void UpdatePersonTest()
{
var expected = new Person()
{
PersonId = new Guid("some guid value"),
FirstName = "dev",
LastName = "test update",
UserName = "dev@test.com",
Password = "password",
Salt = "6519",
Status = (int)StatusTypes.Active
};
PersonMock.Setup(svc => svc.UpdatePerson(It.IsAny<Person>()))
.Returns(expected)
.Verifiable();
var actual = PersonProxy.UpdatePerson(expected);
PersonMock.Verify(svc => svc.UpdatePerson(It.IsAny<Person>()), Times.Once(), "Error updating Person object");
Assert.AreEqual(expected, actual, "Not the same.");
}
【问题讨论】:
-
向我们展示您正在测试的方法。
标签: unit-testing moq