patterns-group / code-patterns

Code Patterns: lots of reusable goodies for your .NET project
tribesoftware.org/code-patterns/
BSD 2-Clause "Simplified" License
9 stars 9 forks source link

IMoqContainer bug: Mock<TObject> does not allow behavior overrides #125

Closed TheTribe closed 11 years ago

TheTribe commented 11 years ago

Sometimes I want to be able to set the MockBehavior to Strict instead of using Default / Loose. If I want to do that, I have to do something like:

var mock = new Mock<IService>(MockBehavior.Strict);

mock.Setup(service => service.Method(It.IsAny<Parameter>())
  .Returns(new ReturnValue());

container.Update(mock.Object);

It seems like I should be able to do this instead:

container.Mock<IService>(MockBehavior.Strict)
  .Setup(service => service.Method(It.IsAny<Parameter>())
  .Returns(new ReturnValue());