This is a mirror of official site: http://jasper-net.blogspot.com/

Enums and inheritance in .Net

| Thursday, February 10, 2011
In one of my current projects I had the following code (I simplified the code a bit):

public string ConnectionString
{
   get
   {
       switch(this.Importer)
       {
           case Importer.SqlServer:
               return "Server=localhost;Database=Northwind";
           case Importer.SqlServerOleDb:
               return"Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=Northwind";
           default:
               throw new NotSupportedException(
               string.Format("Importer {0} is not supported yet.", this.Importer));
       }
   }
}

After running the code coverage tool (dotCover from JetBrains) I received the following picture:

First idea

So, my code was clear and understandable, but obviously not fully tested (green: covered by tests, red: not covered). I asked me the question, how could I test the rest of the method.

My idea was to extend the enum:

[TestFixture]
public class ConfigurationTest
{
       #region Test methods
       

Posted via email from Jasper-net

0 comments: