I have following method
public bool IsUserAllowedToDoThings(string userName, string thingToDo)
{
var outputParameter = new ObjectParameter("IsAllowed", typeof(bool?));
_context.SP_IsUserAllowedToDoThings(userName, thingToDo, outputParameter);
return (bool)outputParameter.Value;
}
The method just calls SP using EF and return SP's output result. But I'm having problems to mock SP's output for unit testing. P.S. I'm using MOQ framework for mocking.
After reading the MOQ's manual 3rd time I finally was able to find the way to do this. That was surprisingly simple:
mockObjectContext.Setup(m => m.SP_IsUserAllowedToDoThings(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<ObjectParameter>())).Callback<string, string, ObjectParameter>((a, b, c) =>
{
c.Value = true;
});
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