5
votes

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.

1
What problems are you having?nana
I just don't know how to to setup mocked output parameter.Alex K
I was suggesting you add more info to the question, but if you think it's perfect just the way it is leave it that way ;) I won't be able to help I don't know C# or Moqnana

1 Answers

4
votes

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;
        });