Tuesday, April 15, 2008
So I also made the a similar template with structuremap support included.

Wich looks something like this

Imports Nunit.FrameWork
Imports StructureMap

Namespace $NAMESPACE$
    ''' <summary>
     ''' A TestClass
      ''' </summary>
       ''' <remarks></remarks>
     <TestFixture()> _
     Public Class $CLASSNAME$
    
#Region " Setup and TearDown "
        ''' <summary>
         ''' Sets up the Tests
          ''' </summary>
           ''' <remarks></remarks>
         <Setup()> _
          Public Sub Setup()
                       StructureMapConfiguration.UseDefaultStructureMapConfigFile = False
                   StructureMapConfiguration.ScanAssemblies.IncludeTheCallingAssembly()
            End Sub

        ''' <summary>
         ''' Tears down the test. Is executed after the Test is Completed
          ''' </summary>
           ''' <remarks></remarks>
         <TearDown()> _
          Public Sub TearDown()
                ObjectFactory.ResetDefaults()        
             End Sub      
#End Region     

#Region " Tests "
                   ''' <summary>
         ''' A Test
          ''' </summary>
           ''' <remarks></remarks>
             <Test()> _
              Public Sub $Test_Name$()
           
               End Sub
#End Region

     End Class
End Namespace
And of course I also made an XmlFile so you can easily import it.

NunitTestFixtureWithStructureMapSupport.xml (2,44 KB)
4/15/2008 2:52 PM Romance Daylight Time  #    Disclaimer  |  Comments [0]  |  Trackback
I made a file template for resharper to make it eassier to create a TestClass

it looks like this.

Imports Nunit.FrameWork

Namespace $NAMESPACE$
    ''' <summary>
     ''' A TestClass
      ''' </summary>
       ''' <remarks></remarks>
     <TestFixture()> _
     Public Class $CLASSNAME$
    
#Region " Setup and TearDown "
        ''' <summary>
         ''' Sets up the Tests
          ''' </summary>
           ''' <remarks></remarks>
         <Setup()> _
          Public Sub Setup()
    
            End Sub

        ''' <summary>
         ''' Tears down the test. Is executed after the Test is Completed
          ''' </summary>
           ''' <remarks></remarks>
         <TearDown()> _
          Public Sub TearDown()
            
        End Sub      
#End Region     

#Region " Tests "
                   ''' <summary>
         ''' A Test
          ''' </summary>
           ''' <remarks></remarks>
             <Test()> _
              Public Sub $Test_Name$()
           
               End Sub
#End Region

     End Class
End Namespace
I also made an xmlFile so you can easily import it into Resharper.

NunitTestFixture.xml (2,15 KB)
.Net | Nunit | Resharper
4/15/2008 2:49 PM Romance Daylight Time  #    Disclaimer  |  Comments [0]  |  Trackback
 Monday, April 14, 2008
Sometimes we just add references and never use them or use them and then remove it all again. And sometimes it is hard to say which reference we don't use anymore. Well MS has provided us with a button that looks up the unused references and if it finds ione you can remove the unused references.

So how do we do it.

First we right clikc on our project and select properties.



Then we go to the tab references and click on the button Unused References.




This will open a dialog with either a list of unused references (see below) or nothing in it.




And now you can just click remove and the references will be gone.


4/14/2008 1:48 PM Romance Daylight Time  #    Disclaimer  |  Comments [0]  |  Trackback
Changing the targeted framework of a project in VB.NET 2008 with the Visual Studio IDE goes like this.

First we click right on the project name and choose properties.



Then we select the compile tab and click on the "Advanced Compile Options..." Button.



And last but not least we select the desired framework from the list "Target framework (all configurations)".





4/14/2008 1:32 PM Romance Daylight Time  #    Disclaimer  |  Comments [0]  |  Trackback
 Sunday, April 13, 2008
After reading A post by Sergio Pereira I thought about translating his code to VB.Net because as usual all the cool things are written in C#.
So this piece
    using(StreamReader rd = File.OpenText("Data.txt"))  
{
string line = rd.ReadLine();
while(line != null)
{
DoSomething(line);
// do more stuff with the line text

//move on
line = rd.ReadLine();
}
}
Becomes

Dim rd As System.IO.StreamReader = System.IO.File.OpenText("Data.txt")
Using (rd)

Dim line As String = rd.ReadLine()
While (line IsNot Nothing)

dosomething(line)
' do more stuff with the line text

'move on
line = rd.ReadLine()
End While
End Using

and the next bit

    public static class FileUtil  
{
public static void EachLine(string fileName, Action<string> process)
{
using(StreamReader rd = File.OpenText(fileName))
{
string line = rd.ReadLine();
while(line != null)
{
process(line);
line = rd.ReadLine();
}
}
}
}

will translate in

Public Class FileUtil

Public Shared Sub EachLine(ByVal fileName As String, ByVal process As Action(Of String))
Dim rd As System.IO.StreamReader = System.IO.File.OpenText(fileName)
Using (rd)

Dim Line As String = rd.ReadLine()
While (Line IsNot Nothing)

process(Line)
Line = rd.ReadLine()
End While
End Using
End Sub
End Class

And we call that last piece of code like this

FileUtil.EachLine("Data.txt", AddressOf dosomething)

The doSomething method would look something like this

Private Sub dosomething(ByVal line As String)
        MessageBox.Show(line)
    End Sub


And that's it.



4/13/2008 9:59 PM Romance Daylight Time  #    Disclaimer  |  Comments [0]  |  Trackback