Solving ‘unable to open site’ in WebMatrix

As you all know, I have been working with Web matrix for last month or so. I find it very easy to develop web sites and manage web sites. One thing, I started to like more is the ability to launch Visual Studio from web matrix. Now back to the problem at hand. I downloaded a web site template from dream template web site since I am not good at any kind of design aspect of it.  It downloaded the full template including the style sheets and bunch of htmls. First thing you have to remember to do is to unblock the zip files before extracting all the files. Once you unblock and extracted. If you would launch Web Matrix and try to open the site with ‘open site from folder’, it will not open the site, I tried opening existing web sites using that open and it does not open. I tried coping the files around to see if it might be because of the directory placement etc., nothing worked. Finally I opened the Web Matrix in admin mode and try opening the sites and all opened properly without any problems. So I guess IISExpress might be blocking opening files from locations that is not opened in admin mode. Anyway, if any of you run into this problem, try opening it as Admin mode you should be all set.

One thing I noticed, even though I was able to open the web sites with this model, my changes does not reflect on the pages, that is something I am working on. It might be as simple as this problem. If I find something new like this, I will post it here.


NUnit vs MSTest

Couple of things I want to add on my observation on using MSTest vs NUnit. I always like to keep my deployment project and test project separate so that when I deploy my application there will be no test code sitting in production. By setting up a environment like this have a limitation when using NUnit. I might have some method private which if I want to test them using NUnit I can’t, since it can not find it. Only way I can test in NUnit is by exposing all the methods as public. On the other hand, with VS2010, I can right click on a private method and it creates test for me in the test project. So my class is clean and I am not exposing the helper methods as public. On this aspect, MSTest is awesome. This is a debatable . If you are creating API then you should be fine by exposing them public, but I do not like the idea to make methods public to support external tool. I like to keep the class clean. On the other hand,  MSTest lacks some of the simple fundamental assertion NUnit have, like collection assertion (without looking for separate method) and able to use TestCase to capture multiple test case against single test to keep the test DRY.

I am still using MSTest and NUnit in different project. MSTest along with Gallio really good, on the other hand, NUnit/NSpec/Growl is so cool as well. I hope MSTest will come up to speed on NUnit so that I can stay on MSTest.

How to create code snippets using Snippet Designer?

I am working with my friend on creating a demo to show TDD. The whole demo took more than 30 minute, we were asked to reduce the time. When we write tests, we tend to write method names as long as possible so that when someone reads it, the name make perfect sense. So one thing I noticed, I spend most of the time typing large method names. One suggestion was not to type rather paste them and explain what the test does. Which led to the question, why not we use snippets? A good excuse for blog.

To start with go to snippet designer codeplex page and download the snippet designer. There is another way you can do it by creating XML etc., I like snippet designer very much and once you start using it, you may not go to XML format. Once it is installed, when you right click on the code, you should see an option to Export as Snippet


Select the option and export a snippet, it will open up a tab with the content you selected like the following


Two points are important here. Make sure you name the snippet (green circle) and then give name for shortcut (black circle). This is the name you are going to use to bring the snippet when you are in a code. Now save this file. There are two places you can save the snippet, one place is default visual studio snippet area. I will not save my snippet in there since it is specific to a project. If you are creating a snippet that you want to use a whole a lot, then you put it in Visual Studio directory. In my case I put it in the solution folder itself.  By default, snippet manager will show all the snippets stored in default visual studio directory so you need to tell snippet manager to look it up not only in visual studio default directory but also additional directories. To do that, go to tools –> snippet manager like the following


When you choose code snippet manager, it will show a dialog like the following


Change the language to C# and select Visual C# and select add to add the directory where you placed your snippets. Now that all pieces in place, go to your program and start typing ‘finalkata’ (Remember, this is the short cut name we gave?), as you type the intellisense should find your snippet and show up.


select it and double tab and bring the code. That’s about it. Very simple and easy to use. What I did not show is how to create the replaceable content inside the snippet, for what I did, it was not required. When I come around to use it, I will do another blog.