Category Archives: Testing

NSubstitute and functions calls in setup

I am getting a behaviour I didnt expect from NSubstitute when setting up my mocks to call a function. A simplified version of this [Test] public void NSubstituteTest() { var mockedFoo = Substitute.For <IFoo>(); mockedFoo.GenerateString(Arg.Any<string>()).Returns(x => GetValue(x.Args()[0])); mockedFoo.GenerateString(“0″).Returns(“hi”); string result1 = mockedFoo.GenerateString(“0″); string result2 = mockedFoo.GenerateString(“1″); Assert.AreEqual(“hi”, result1); Assert.AreEqual(“1″, result2); } private string GetValue(object val) [...]

One way to mock Request.QueryString and Request.Form

I often find it convenient to test Asp.Net MVC application on the controllers. One thing I find myself repeat over and over again is mocking the HttpContext and setting Request.QueryString and Request.Form values. It brings great value to the tests being able to test how the model binders behave given certains posted values or how [...]

SpecFlow – getting up and running

SpecFlow is by far the BDD framework I like the best in the .NET ecosystem. It uses gherkin as natural language to describe features and scenarios. It has really good integration with visual studio. Under the hood it uses T4 templates to generate code that can be run using your favorite test runner like NUnit, [...]