Setting up the projects

In this scenario, we will use the Microsoft Unit Test (MSTest) framework. This section provides some instructions to create the initial project using the .NET Core command-line interface (CLI) tools. These steps could have been completed using an integrated development environment (IDE) such as Visual Studio or Visual Studio Code. The instructions are supplied here to illustrate how the CLI can be used to complement the IDE.

CLI
.NET Core CLI tools are cross-platform utilities for developing .NET applications and are the basis for more sophisticated tooling, such as IDEs. Please see the documentation for more information: https://docs.microsoft.com/en-us/dotnet/core/tools.

The solution for this chapter will consist of three projects: a console application, a class library, and a test project. Let's create the solution directory, FlixOne, to contain the solution and sub-directories for the three projects. Within the created directory, the following command will create a new solution file:

dotnet new sln

The following screenshot illustrates creating the directory and solution (note: only an empty solution file has been created so far):

The class library, FlixOne.InventoryManagement, will contain our business entities and logic. In later chapters, we will split these into separate libraries but, as our application is still small, they are contained in a single assembly. The dotnet core CLI command to create the project is shown here:

dotnet new classlib --name FlixOne.InventoryManagement

Note, in the following screenshot, that a new directory is created containing the new class library project file:

References should be made from the solution to the new class library with the following command:

dotnet sln add .FlixOne.InventoryManagementFlixOne.InventoryManagement.csproj

To create a new console application project, the following command should be used:

dotnet new console --name FlixOne.InventoryManagementClient

The following screenshot shows the console template being restored:

The console application requires a reference to the class library (note: the command needs to be run in the directory with the project file that will have the reference added to it):

dotnet add reference ..FlixOne.InventoryManagementFlixOne.InventoryManagement.csproj

A new MSTest project will be created using the following command:

dotnet new mstest --name FlixOne.InventoryManagementTests

The following screenshot shows the creation of the MSTest project and should be run in the same folder as the solution, FlixOne (note the packages restored as part of the command containing the required MSTest NuGet packages):

The test project also requires a reference to the class library (note: this command needs to be run in the same folder as the MSTest project file):

dotnet add reference ..FlixOne.InventoryManagementFlixOne.InventoryManagement.csproj

Finally, both the console application and the MSTest project should be added to the solution by running the following commands in the same directory as the solution file:

dotnet sln add .FlixOne.InventoryManagementClientFlixOne.InventoryManagementClient.csproj
dotnet sln add .FlixOne.InventoryManagementTestsFlixOne.InventoryManagementTests.csproj

Visually, the solution is shown as follows:

Now that the initial structure of our solution is ready, let's first start by adding to our unit test definitions.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.51.3