A simple e-commerce store application
I'll use a simple ecommerce store application to demonstrate how the asp.net MVC framework works. In today's post, I will implement a product list, as well as related browsing application scenarios.
Specifically, we will build an online store that allows users to browse the product Category list when they visit the/products/categories URL on the site:
When the user clicks on the Product category link on the above page, they will go to a product Category List Url/products/list/categoryname, which lists the products that are still being sold in the specified category:
When users click on individual products, they will go to the product Details Url/products/detail/productid, this page will show the user selected products more details:
We will use the new ASP.net MVC framework to implement all of these features. This will allow us to maintain a "clear separation of concerns" between the different components of the application, allowing us to integrate unit testing and test-driven development more easily.
Create a new asp.net MVC application
The ASP.net MVC framework contains a Visual Studio project template that makes it easy for you to create new MVC Web applications. Select the file-> new Item menu, select the "ASP.net MVC Web Application" template, and use it to create a new Web application.
By default, when you use this option to generate a new application, Visual Studio creates a new solution for you and then adds 2 projects to it. The first project is a Web project in which you implement the functionality of your Web application. The second project is a test project where you can write unit tests to test your application code:
You can use any of the unit test frameworks in the ASP.net MVC framework, including NUnit, Mbunit, MSTest, Xunit, and other frameworks. The VS 2008 Professional Edition now includes support for MSTest's built-in test projects (VS 2005 version of MSTest requires you to have the Visual Studio Team System version to use), and when you use VS 2008, the default ASP.net MVC The project module automatically generates such a test project.
We will also publish project templates that can be used with NUnit, Mbunit, and other unit test frameworks, so if you prefer those frameworks, you can easily click on them to generate your application and the corresponding test project that can be used immediately.