📜 ⬆️ ⬇️

NerdDinner. Step 1: New Project

This is the first step of the free NerdDinner tutorial , which shows how to build a small but full-fledged web application using ASP. NET MVC.

We start our application NerdDinner (dinner for nerds) with the menu item File> New Project.

We will see the "New Project" window. To create an ASP.NET MVC application, we will select the “Web” item on the left side of the window, and then the “ASP.NET MVC Web Application” project template on the right side.
')
image


Make sure you have installed ASP. NET MVC, otherwise you will not see this item in the " New Project". This can also be done through the Microsoft Web Platform Installer ( ASP. NET MVC is available in the “Web Platform> Frameworks and Runtimes” section)

We will call the new project “NerdDinner”. After clicking “OK”, Visual Studio will offer to selectively create a project for unit testing for a new project. This project allows us to create automated tests that test the functionality and behavior of our application (we will look at this topic in the next steps).

clip_image002[6]

The drop-down list “Test framework” contains all the available unit-test patterns for ASP.NET MVC on this machine. You can use the Nunit, MBUnit and XUnit, as well as the built-in Visual Studio Unit Test framework.

Visual Studio Unit Test framework is available in the Professional version and above, for the Standard and Express versions you need to install a third-party add-on. If no test framework is installed, the selection window does not appear.

We will use the default test project name, “NerdDinner.Tests,” and select the “Visual Studio Unit Test” framework. After confirmation, Visual Studio will create a solution with two projects, one for the web application, the second for unit testing:

clip_image003[8]

Exploring the directory structure NerdDinner


When you create a new ASP.NET MVC application with Visual Studio, it automatically adds the necessary list of directories and files to the project:

clip_image004[6]

The ASP.NET MVC project has, by default, six high-level directories:

/ Controllers - Where do you place the Controller classes to handle URL requests

/ Models - Where do you place classes to provide and manipulate data

/ Views - Where do you store the UI template files that are responsible for drawing the result

/ Scripts - Where you locate javascript library files and scripts (.js)

/ Content - Where you place CSS files and images, as well as other static objects.

/ App_ Data - Where you store data files for writing and reading.

ASP.NET MVC does not require you to adhere to this structure. In fact, working on large applications, developers usually divide the application into several projects for flexibility. For example: data model classes are placed in a separate library project. However, the default project structure provides a convenient solution to keep the structure clean and transparent.

When we expand the / Controllers directory, we’ll find that Visual Studio has added two controller classes — HomeController and AccountController, by default:

clip_image005[6]

In the / Views directory there are three subdirectories: / Home, / Account and / Shared, as well as several template files in each:

clip_image006[6]

The / Content and / Scripts directories store the Site.css file, which is used to decorate all HTML on the site, as well as JavaScript libraries that provide the application with jQuery and ASP.NET AJAX support:

clip_image007[6]

The NerdDinner.Test project stores only two classes that contain unit tests for our controller classes:

clip_image008[6]

The listed files that Visual Studio adds to the project by default provide us with the basic structure of the running application, complementing the home page, about page, registration / logging in / out pages, and the raw errors page.

Starting the NerdDinner application


We can start a project by choosing Debug> StartDebugging or Debug> Start Without Debugging from the menu:

clip_image009[6]

The project will start using the Web server built into Visual Studio ASP.NET:

clip_image010[6]

Below is the home page of our new project (URL: “/”) after launch:

clip_image011[6]

Clicking on the “About” link you will see the about page (URL: “/ Home / About”):

clip_image012[6]

Clicking on “Log On” in the upper right corner, we are taken to the login page (URL: “/ Account / LogOn”):

clip_image013[6]

If we have no login, we can go to the registration (URL: “/ Account / Register”):

clip_image014[7]

The code that is responsible for implementing the home, about and logout / register functionality is added by default during project creation. You will use it as a starting point in our project.

Testing NerdDinner Applications



If we use the Professional version of Visual Studio and higher, we can use the built-in support for unit testing in the IDE:

clip_image016[7]

Selecting one of the options will open the Test Results panel, which gives us the status of each of the 27 built-in unit tests in the form Passed / failed.

clip_image017[6]

Later in this guide we will talk about automated testing and add additional unit tests that will cover the functionality of the application implemented by us.

Next step


And so, we have the basic structure of the application and can proceed to create a database for storing application data.

Source: https://habr.com/ru/post/98902/


All Articles