Can someone please look at the code below and see what's wrong?
[TestInitialize]
public void SetupMockRepository()
{
var memberId = "34345235435354545345";
var title = "test";
var url = "dafdsfdsfdsfdsafd";
_mockPropertySearchRepository = new Mock<IPropertySearchRepository>(MockBehavior.Strict);
_mockPropertySearchRepository
.Setup(p => p.SaveSearchURL(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
.Callback<string,string,string>((id,t,u) => )
.Returns(new SavedSearchReturnResult() );
}
Thanks
A callback is a piece of code that is passed into to a method parameter to be executed from within that method. Callbacks allow you to extend the functionality of such methods. When using Moq to create test doubles, you can supply callback code that is executed when an expectation is met.
Verifiable is to enlist a Setup into a set of "deferred Verify(...) calls" which can then be triggered via mock. Verify() .
I managed to solve the problem myself as below
[TestInitialize]
public void SetupMockRepository()
{
var memberId = "34345235435354545345";
var title = "test";
var url = "dafdsfdsfdsfdsafd";
_mockPropertySearchRepository = new Mock<IPropertySearchRepository>(MockBehavior.Strict);
_mockPropertySearchRepository
.Setup(p => p.SaveSearchURL(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
.Callback<string,string,string>(
(id, t, u) =>
{
memberId = id;
title = t;
url = u;
})
.Returns(new SavedSearchReturnResult());
}
For each parameter that the method takes, pass a type parameter to the Callback
method.
someMock
.Protected()
.Setup("SomeMethod", ItExpr.IsAny<string>(), ItExpr.IsAny<string>())
.Callback<string, string>((x, y) => {});
The above works both with Protected
and normal callbacks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With