Moq – Mocking the same method call with multiple results

The Scenario I have a loop in production code that has evolved into processing batches of records. I need to modify an existing unit test to accommodate mocking the same method call each time through the loop returning different results on each loop (as…

Moq Vs Rhino Mocks

Just some rough notes I made coming from a Moq framework and converting to Rhino Mocks: Asserting a method call ISomethingRepository mockedSomethingRepository = MockRepository.GenerateMock(); var person = new Person { name = “Bob” }; // Act var something = new Something(mockedSomethingReporsitory); // Assert mockedSomethingRepository.AssertWasCalled(x…

Moq – Mocking a cast on an interface

Mocking a Cast on a Mocked Interface The Setup var mockedInterface = new Mock<IInterface>(); mockedInterface.As().Setup(i => i.MethodOnTheInterface()); Easy as that!

Moq – Mocking the Request context and verifying SQLException is raised.

Mocking the Request on an API Controller Had an API controller under unit test which made use of the¬†HttpMessageRequest which I needed to mock.How do I get a handle on this? Again pretty simple really (my initial train of thought was back to front…

Moq – Verifying parameter values on a mocked method call.

Was going down a rabbit hole trying to figure out how to check param value on a mocked method¬†(pretty simple if truth be told). I need to ensure that when an exception was raised my logger would be called Times.Once and would log the…