Testing code snippets for Visual Studio
October 30th, 2009If you create many test classes and test methods you probably repeat some code many times.
Here are some code snippets that I use every day at work, feel free to modify them if you want.
If you create many test classes and test methods you probably repeat some code many times.
Here are some code snippets that I use every day at work, feel free to modify them if you want.
If you use log4net you have probably noticed that this logger does not write information from exception's "Data" property. Here is the renderer which does:
and the configuration needed for this to work is:
Sample output for NullReferenceException with Data["configPath"] = "myconfig.config":
2009-06-12 22:22:04,038 INFO [LoggerTest.Program] - Exception during init
System.NullReferenceException: Something was null
at LoggerTest.Program.Main(String[] args) in G:\C#\Temp\LoggerTest\Program.cs:line 26
Exception Data:
configPath = myconfig.config
Feel free to use and modify it.
We create many enumerations in our programs. But sometimes we can make a mistake that drives somebody else mad.
Let's suppose that the first programmer created an enum like this:
It does not look bad at the first look, yet another enum.
Another programmer created a list:
Then he would like to find there a first mood type which is a part of "good mood" group and pass the result to another layer of an application. He wrote the code:
Now he realized that it cannot work because Find method of a List(T) class returns default(T) when a list does not contain desired item. In this case he would get Mood.Awesome because it is the default value of the enum. I do not need to add that the Mood.Awesome is not even the part of the list.
We can solve this problem by several different approaches.
The question to discuss - which programmer made a mistake? The first one who created "unfortunate" enum or the second one who used wrong structure / wrong searching method?