I have an Interface
public interface IRequester
{
void Check(Check check);
}
I want to mock this using Moq
which is obviously easy. The issue I have is that I want the Check
passed in to be modified (as it is a reference) after the mocked call. As you can see Check
is just a simple POCO.
public class Check
{
public string Url { get; set; }
public int Status { get; set; }
}
Ideally I want to change the value of the Status
property on the Check
passed in.
Is this possible?
Use the Callback
method. I think it will be something like:
yourMock.Setup(x => x.Check(It.IsAny<Check>()))
.Callback((Check c) => { c.Status = 1234567; });
You can leave out the braces { }
and the first semicolon ;
if you only need one assignment.
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