Welcome to the fifth chapter of the test driven development course.
And in this chapter we are going to see how to test application services.
But what even is an application service?
We have learned to test a single class so far.
That single class can be an entity and it's crucial to test entities.
But testing entities is not enough.
We load an entity from a database, modify it, and finally save it to the database.
Again, we should also test the code that loads and saves entities into the database.
Loading and saving data into databases is the job of the application layer.
So we need to test the application layer from an architectural side of view.
The application layer is responsible for orchestrating other components.
The most usual job of the application layer is to load entities from the database, call their API to
modify them and then save them back to the database.
Again, if you are familiar with web development or ASP.Net Core, for example, for C-sharp, you definitely
know how data is loaded from databases and saved back in again using entity framework.
We need to make sure that the application layer orchestrates different components properly.
And in this chapter we are going to see how to test the application layer in practice.
So right click on the solution, we will add two new projects, one for the application layer itself,
we will call it application and one for the application layer tests.
So let's start with the application layer test.
So add a new project search for ECS unit, take that ECS unit test project hit next and let's call it
application dot tests, click next dot net six and let's create the project.
Awesome.
So here we got the first one.
Now let's create another project.
Right click on the solution, add a new project, Let's select a simple class library.
There we go.
Class library hit next and call it application.
That's all we have to do next again.
And now we have two new projects inside of our solution.
One for the application layer.
You can see that right here and one for the application layer, but test specifically also.
Now let's switch over in our unit Test one class, which is in the applications test project, and let's
remove that name here.
Public void test one, let's name it books, flights, saving, let's save it and rename the class unit
test one to flight application specifications.
All right.
That sounds like a nice naming.
Since we want to build like a real world scenario, we have to add one more class library, which is
then for the actual data.
So the application layer is for saving data, but the actual data objects, for example, they should
be included inside of a new data library.
Well, I know you might get confused if you have never ever really written a real world application
which uses such an architecture, but don't get too confused because you will see this in any scenario.
So if you get a job as a C-sharp developer or if you well are already a C-sharp developer, but you're
inside of a small company, you maybe do not see such architectures.
But if you go to bigger companies, it's very, very usual that you see well applications that use really
a lot of sub projects.
So you have one solution and many sub projects.
Let's go ahead, right click on the solution and add again a new project one more time.
We add a class library.
There we go.
And this one is for data.
Let's hit next dot net six again.
There you go.
All right.
And that's all we have to do for the preparation for this chapter.
So next up, we will discover a new scenario and write a test for the application layer Logic.