Contents tagged with unit-testing

  • Mocking with NSubstitute

    My previous C# mocking framework of choice was MOQ. It's very powerful and fairly easy to use, but I recently started using NSubstitute and fell in love with how easy and intuative it was to use.

    The cleverest part is that unlike MOQ the mocks produced actually implement the interface they're mocking and this makes the code much clearer and a little bit shorter.

    Here is a very simple example:

    var mockThing = Substitute.For<IThing>();mockThing.DoThingy().Returns("Something");// Use mock thingUseThing(mockThing);

    In MOQ this is also quite straightforward but the setup code to change … more

  • 1