views:

19

answers:

2

I was watching a screencast of someone using Resharper (on VS 2010 or 2008, not sure) where they were able to fill in a test name with a string literal:

public class FooTest
{
    public void "runs backgrounnd process until complete"

and then some command transformed it to

public class FooTest
{
    public void runs_backgrounnd_process_until_complete()
    {

I was wondering if anyone knew what that command was.

A: 

Looks like a "live template". If you notice, he types in fact, which is then replaced by the test method's skeleton. Edit, looks like it comes from the xUnit.net contrib project. You should be able to do something similar for an nUnit test case as well.

Nader Shirazie
A: 

It is a visual studio macro that originally came from JP Boodhoo's Nothing But .NET Boot Camp class. This is it:

 Sub ConvertLine()
        If DTE.ActiveDocument Is Nothing Then Return

        Dim isOpen As Boolean = OpenUndo("ConvertLine")

        Dim selection As TextSelection = CType(DTE.ActiveDocument.Selection(), EnvDTE.TextSelection)
        selection.SelectLine()
        If selection.Text = "" Then Return

        Dim classKeyword As String = "class """
        Dim methodKeyword As String = "void """
        Dim classIndex As Integer = selection.Text.IndexOf(classKeyword)
        Dim methodIndex As Integer = selection.Text.IndexOf(methodKeyword)
        If classIndex + methodIndex < 0 Then Return

        Dim index = CType(IIf(classIndex >= 0, classIndex, methodIndex), Integer)
        Dim prefix = selection.Text.Substring(0, index) + CType(IIf(classIndex >= 0, classKeyword, methodKeyword), String)
        Dim description As String = selection.Text.Replace(prefix, String.Empty)

        Dim conversion As String = Common.ReplaceSpacesWithUnderscores(description)
        conversion = Common.ReplaceApostrophesWithUnderscores(conversion)
        conversion = Common.ReplaceQuotesWithUnderscores(conversion)

        selection.Text = prefix.Replace("""", String.Empty) + conversion
        If prefix.Contains(methodKeyword) Then selection.LineDown() Else selection.LineUp()
        selection.EndOfLine()

        CloseUndo(isOpen)
    End Sub
NotMyself
Ahh and here is JP's original post on it. http://blog.jpboodhoo.com/MacroToAidBDDTestNamingStyle.aspx
NotMyself

related questions