ReSharper is a wonderful tool that makes writing code much easier. One of the features of this tool is ability to create templates. With ReSharper you can create Live, Surround With, and File Template. In this post I want to share with you how to create a File Template for MbUnit Test Fixture.
Step 1: Open ReSharper – Options dialog.
Start Visual Studio and from menu bar select ReSharper – Options (you also can get there by pressing Alt-R + O).
Step 2: Create a new template.
- In the left panel select File Templates under Templates section.
- Then select User Templates in Available templates.
- In this sample we’re going to create C# template, so select Class (C#) in Quick access list (it should be the first item in the list).
- Last click on Create Template icon to see Edit Template dialog box.
Step 3: Create and save MbUnit Test Fixture template.
- In Name text box enter MbUnit Fixture. It’s a name that will appear in the menu when you add a new test fixture.
- In File name prefix text box enter MbTest. It’s going to be a suggestion for your test file / class.
Next click on everywhere link next to the word Available to see the Template Options dialog box. Select Only in projects for language radio button and chose C# projects including ASP.NET C#projects) from the drop-down control. Extension for created files leave as cs.
Now we are ready to create actual template.
Enter the code below into Template text.
I’m sure that you noticed $NAMESPACE$, $CATEGORY$, and $CLASS$. These three are ReSharper variables. You declare a variable by surrounding a word with $ sign.
The reason we created variables because we want to do something with them.
Click on Choose macro link and choose following options in Choose Macro dialog box.
|$NAMESPACE$||Default namespace for current file|
|$CLASS$||Current file name without extension|
Uncheck Editable Occurrence check box for NAMESPACE variable.
You can see that CATEGORY variable has a red link Constant value. Click on it and enter Category in String value text box of Choose Parameter Value dialog box.
Now you can start using this template.
Next time I’ll show how to create a Live Template for tests, test SetUp(s) and TearDown(s).