Attention: We are retiring the ASP.NET Community Blogs. Learn more >

Contents tagged with C#

  • Moq with NameValueCollection

    Mocking HttpRequest and HttpResponse is not complicated with HttpRequestBase and HttpResponseBase introduced in ASP.NET. I had to mock ServerVariables property of HttpRequest and run into an issue – I was accessing an indexer property and didn’t know how to do this. Gladly, ran into a post that mentioned that indexer is actually utilizing a virtual Get() method. Reflector has confirmed that.

  • Writing a Custom ConfigurationSection

    Writing a Custom ConfigurationSection is not a big task, but can be very challenging if you forget some details. I loved this post as it reminded me that you have to have both the Section tag and the collection within it tag… dah!

  • Stop Asserting Arguments by Name

    Asserting arguments is essentially a healthy practice. What I don’t like, is the fact that since day one ArgumentNullException used a string for argument name, and now with .NET 4.5 almost knocking on the door, there’s still only string option.

  • Creating collection with no code (almost)

    When doing testing, I tend to create an object mother for the items generated multiple times for specifications. Quite often these objects need to be a part of a collection. A neat way to do so is to leverage .NET params mechanism:

  • MbUnit–Hidden Gem

    Row tests are fun. You can simulate various inputs with expected outputs and execute them all with a single observation (test). The problem for myself was always the fact that when this was done, the only way to accomplish it was to merge the logical because which operates on system under test behaviour and the observation itself (assertion). This leads to a slightly less readable code IMO.