Posted by Jon on 2011/08/11
There are several ways to get the path to the running assembly in c#. I used to do something like Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName); However when running unit tests etc this would cause pain and some old dirty solutions included injecting a hardcoded path for testing. I recently found a much better way to do this when googling [...]
Posted by Jon on 2011/08/09
I always forget the syntax so here it is for reference Lets say we want to generate a schema for the class User in the assembly SomeCodez.dll C:\Somepath\SomeCoedz\bin\Debug>xsd.exe -t:User SomeCodez.dll /o:c:\temp\
Posted by Jon on 2011/08/02
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) [...]
Posted by Jon on 2011/03/13
I have used asp.net mvc since beta and uploaded files without any problems until yesterday. I kept getting null from Request.Files (Actually I use HttpPostedFile as inparameter to the action). Nevertheless both Request.Files and the inparamer was null. In the form: File In the controller: [HttpPost] public ActionResult UploadFile(HttpPostedFileBase file) { if (file != null [...]
Posted by Jon on 2011/01/05
I find defensive coding a really great way to improve the quality of a codebase. Code contracts is an implementation of Design by contract (dbc). Dbc was introduced in 1986 by Bertrand Mayer for use with Eiffel. The concept is simple, check that the input to a method is valid and that the return values [...]
Posted by Jon on 2010/09/02
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, [...]
Posted by Jon on 2009/09/17
We are using Caliburn in our current project. Its a great framwork and cuts away much plumbing. You can use all the common DI containers for setting up dependencies. We use Structuremap in other parts of the application. Here is how to set it up for use with Caliburn: (code tags a bit wierd) using [...]
Posted by Jon on 2009/05/07
We recently added support for automatically generating distrubution groups in ILM 2007 FP1 for a customer. Initially we were getting som errors because of bad Aliases. After some digging around I found exactly what letters are valid in an Alias. Valid leter are strings formed with characters from a to z (uppercase or lowercase), digits [...]
Posted by Jon on 2009/04/16
A nice way to develop sevices is to start your project with an ordinary console application. Within the console application you can swith input arguments. If there are no input arguments you can start the service and if there is for example “/test” you could do some processing or debug into some code. Some example [...]
Posted by Jon on 2009/02/14
Mocking and dependency injection can seem overwhelming the first time you read about and try to implement them. Two nice and clean frameworks are moq and ninject They are very easy to get into and both has good basic tutorials. For a beginner they cover what you want to do. I will try to show [...]