3
我是新來的最小起訂量,我已閱讀快速入門here。我正在使用MOQ v4.2.1402.2112。我正在嘗試創建一個更新人物對象的單元測試。 UpdatePerson
方法返回更新的人員對象。有人能告訴我如何糾正這個問題嗎?最小起訂量錯誤預期的模擬調用一次,但是0次
我收到此錯誤:
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 = "[email protected]",
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.");
}
顯示我們要測試的方法。 –