Thursday, November 4, 2010

XmlTidy

Needed a tool to tidy some Xml in "Programmer's Notepad" and could not resist to created my own version of XmlTidy. :-) using System; using System.Xml; using System.Xml.XPath; namespace XmlTidy { public class Program { private enum ExitCodes { Success = 0, Failure = 1 } private static...
Share:

Wednesday, November 3, 2010

Programmer's Notepad

Got a new laptop today and have started to install all the cool and useful tools I need. Previously I have used TextPad and Notepad++ as my notepad replacements, but this time I decided to see if there was some other text editors out there. Found "Programmer's Notepad" that looks...
Share:

Tuesday, October 19, 2010

Creating a self-signed certificate with private key

Needed to make a self-signed certificate with a private key for a project I working on. After some research I found that the combination of makecert and pvk2pfx did the trick. Use the following commands in Visual Studio Command Prompt makecert -r -pe -n "CN=Test" -b 01/01/2010 -e 01/01/2020 -sky exchange Test.cer -sv Test.pvk pvk2pfx.exe -pvk Test.pvk...
Share:

Monday, October 11, 2010

Friday, October 1, 2010

Howto create unit test for privat, internal, and friend methods

Problem: You have a class with a private method that you wish to test. public class ClassUnderTest { private int DoSomePrivateStuff() { // Something is happening here } } Since the method is private you can not access the it from the outside of the object. How I solved this earlier was to make a testable class that inherited from the class...
Share:

Wednesday, September 29, 2010

Testing exceptions in unit test

NUnit has a nice feature (Assert.Throws) that makes it possible to assert that a exception is thrown inside some code. Visual Studio Unit Testing Framework seem to miss this feature and to check that the correct exception is thrown you would could use the following code: [TestMethod] public void WithTryCatch() { // Arrange ApplicationException...
Share:

Wednesday, September 15, 2010

Thursday, June 17, 2010

Variable number of arguments

The params keyword is very handy when you don't know the number of arguments is variable. Note! No additional parameters are permitted after the params keyword. // This method can take a variable number of ints public int Sum(params int[] values) { int sum = 0; foreach(int value in values) { sum += value; } return sum; } // Method...
Share:

Monday, June 7, 2010

AD LDS for Windows 7

On XP machines there was a a service called ADAM that could be used when you needed a lightweight ActiveDirectory. This was extremely useful when developing applications that used AD. You could test your application without the need to modify your client/company AD. But this service was not supported in Vista or Win7. But now Microsoft have released...
Share:

Wednesday, March 3, 2010

Comandline argument parser

Class that parses the commandline arguments. using System; using System.Collections.Generic; using System.Text; using System.Diagnostics; namespace TestArgumentParser { public class ArgumentParser { public string QuoteChars { get; set; } public string ValueSeparatorChars { get; set; } public string PrefixChars { get;...
Share:

Monday, February 22, 2010

Expression trees

Howto get the name of a property or class. To minimize magic strings Usage: // This code will return "MyProperty". ObjectHelper.GetMemberName(() => someEntity.MyProperty); using System; using System.Linq.Expressions; /// /// Extensions to object class /// public static class ObjectHelper { /// /// Gets the name og the property og class...
Share:

Wednesday, January 27, 2010

SMTP server for development purposes

Needed to test some code sending emails, but did not find the local SMTP sever on Windows 7. Did a quick search and found this one.. sweet.. http://smtp4dev.codeplex.com/ Dummy SMTP server that sits in the system tray and does not deliver the received messages. The received messages can be quickly viewed, saved and the source/structure inspected....
Share:

Tuesday, January 19, 2010

WCF Client wrapper

The using statment and WCF are a bad combo.. Instead use the following class. With some lambda together with this class it's almost like a using statement. using System; using System; using System.ServiceModel; /// /// Helper class for WCF clients /// public class WcfClientUtils { /// /// Execute actions...
Share: