Testable object wrapper

Have started experimenting with a way of wrapping the ‘system under test’ in a wrapper-class that also contains the mocked dependencies. The class is instantiated the same way as Brad Wilson’s Testable Object Pattern with a static Create method. The big difference from his pattern is that the system under test is a public Sut-property instead […]

Serialize .NET objects as camelCase JSON

ASP.NET MVC is amazing how easy it is to serialize from a .NET POCO to JSON and the other way around using the model binder. But one thing I really don’t like is how serializing .NET objects to JSON returns the properties PascalCase. Net has PascalCase coding convention for properties and JavaScript uses camelCase. The […]

Create Html.DropdownListFor without magic strings

Using magic strings are bad practice. Changes could lead to code compiling but containing lots of errors (appearing during runtime). And refactoring your code is a lot harder if you have to globally search and replace. Using dropdown lists with ASP.NET MVC has a Html-helper that wants you to use magic strings. Having a Category […]

Category: C#

Creating and intitializing ArrayList in one line

There are multiple ways of creating a ArrayList and adding a couple of items to it.  The usual way to do it: List<String> normal = new ArrayList<String>(); normal.add("one"); normal.add("two"); normal.add("three"); Or you could use the double braces. The inner pair of braces creates a anonymous innner class List<String> doubleBraces = new ArrayList<String>() {{ add("one"); add("two"); […]