I have the following test code.
var test = "Test";
var command = new MyCommand { V = test };
var mock = new Mock<IRepository>(); // IRepository has the method of Save()
var p = new P(test);
mock.Setup(x => x.Save(p)).Verifiable();
var sut = new C(mock.Object);
var result = await sut.M(command);
mock.Verify();
The test should pass. However, it failed with the error of,
Message: Moq.MockException : Mock: This mock failed verification due to the following: IRepository x => x.Save(P): This setup was not matched. Stack Trace: Mock.Verify()
sut.M()
will convert a string X to type P
with value of P(X)
.
()))` otherwise it expects the exact same `P` to be passed and I doubt `P` has value equality setup.
– juharr Dec 19 '19 at 22:28(), Times.Never));`. Other options include `Once`, `AtLeastOnce`, and others that specify a specific number of times or range of times it can be called.
– juharr Dec 19 '19 at 22:40())).Callback
(p => Assert.Equal(p.Whaterver, test))`
– juharr Dec 19 '19 at 22:45`?
– ca9163d9 Dec 19 '19 at 22:48