Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mocking stored procedure's output parameter

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.

like image 781
Alex K Avatar asked Sep 29 '22 03:09

Alex K


1 Answers

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;
        });
like image 191
Alex K Avatar answered Nov 09 '22 01:11

Alex K