0

I'm using MoQ to test some controllers I have. I'm not able to set the expectations. This is the code I have:

        var rep = new Mock<IUserRepository>();
        rep.Setup(r => r.Save());

The problem is that my Save() method expects a User object which I cannot set in the expectation because an instance of it will be created by the controller. Is it possible to set expectation without passing a specific parameter, and just check if the method was called no matter what parameter was passed?

Pops
  • 30,199
  • 37
  • 136
  • 151
tucaz
  • 6,524
  • 6
  • 37
  • 60

1 Answers1

4

Can you explain what you mean by "the Save() method expects a User object"? Does it expect it as a parameter? If so, you can define that in the setup:

rep.Setup(r => r.Save(It.IsAny<SomeObjectType>())

And it'll take in any object as long as its type is SomeObjectType.

If you meant something else, then please show a code sample of what the expected behavior is.

Eilon
  • 25,582
  • 3
  • 84
  • 102
  • That's correct. I just found it myself. I was trying with It.IsAny() while my method expected a User parameter. I used It.IsAny() and it worked. Thanks a lot! – tucaz Dec 30 '09 at 19:23