This shows my initial setup of an MVC 2 RC 2 application. Using Visual Studio 2010 RC I selected File –> New –> Project… then under Visual C#, Web, I selected the ASP.NET MVC 2 Web Application.
Then when I click OK I get the following dialog. Since I’m a very strong believer in Unit Tests I of course do create an associated Unit Test project.
The first thing I did then was to run the unit tests… there were 18. I like to know the code coverage too… So I have to create some test settings and turn on the code coverage. Right clicking on the solution I add a new item:
Out of habit I call it Local.testsettings because I usually end up with a Build.testsettings that is set up differently.
Under Data and Diagnostics I turn on code coverage and configure it. This is a bit tricky for the moment. For this to really work you need to add an assembly and select the actual .dll. Here are those screen shots for my project:
I don’t select any of the items that show up by default:
but instead I select the Add Assembly…
I navigated to the bin folder of my MVC application and selected that dll. Go ahead and select OK on the next message:
Click OK on the next dialog:
Then hit Apply and Close on the Test Settings window. Now when I run all my tests again I can open the code coverage window:
And when I do, I see that I have about 50{f073afa9b3cad59b43edffc8236236232bb532d50165f68f2787a3c583ed137f} code coverage.
There are several other things that I do before I consider the project initially setup…
I turn on Code Analysis and select the Microsoft All Rules rule set.
After that I run the code analysis (Analyze –> Run Code Analysis on KarlZMvcGallery) to see there are 14 warnings. I’ll breeze through getting rid of these but I will highlight some important items. The first is to create a Code Analysis Dictionary. I’m not sure why it is not as easy as merely adding a new item to the project, but you have to create a new file and type in it yourself. I created one from someone’s post so long ago that I don’t recall where that post is, but I copy that file from project to project. Here is the file I have to get rid of the “CA1704 : Microsoft Naming: Correct the spelling of …” warnings:
- <?xml version="1.0" encoding="utf-8" ?>
- <Dictionary>
- <Words>
- <Unrecognized>
- <Word>cb</Word>
- </Unrecognized>
- <Recognized>
- <Word>Mvc</Word>
- </Recognized>
- <Deprecated>
- <Term PreferredAlternate="EnterpriseServices">ComPlus</Term>
- </Deprecated>
- </Words>
- <Acronyms>
- <CasingExceptions>
- <Acronym>GEDCOM</Acronym>
- </CasingExceptions>
- </Acronyms>
- </Dictionary>
After you add CodeAnalysisDictionary.xml to your project, you need to change the Build Action for the file to Code Analysis Dictionary:
I don’t know why the AssemblyInfo.cs file does not already have these two lines, but I need to add them each time:
- using System;
- [assembly: CLSCompliant(true)]
With a bit more work and some suppression of messages such as “Consider consolidating the namespace” in your project suppression file you have a project that has 0 Errors, 0 Warnings, and 0 Messages!
Now I feel like I’ve got a project initially setup.
Leave a Reply