Monthly Archives: August 2011

Finding the path to the running assembly

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 [...]

Generating xsd schema from class

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\

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) [...]