Okay.
So now pay attention because that's very important.
We have just created a new project and that project is only for test scenarios.
Here we have our calculator method, right?
If we would have a calculator, the calculator should have that functional method, right?
And not our test project.
So this is called domain layer.
So we will now create a real calculator project and bring that method into there and then reference
it instead of having the functional calculator code inside of the test project.
Right?
So what we do is you right click on your solution, very important, not on your project and we add
a new project to our solution.
And this is what you will see in a lot of real world applications.
You have a test project and you have another project which actually contains the algorithms and the
functional code.
So here we search next up for a class library.
Simply write down class library.
There we go.
A project for creating a class library that targets dot net or dot net standard.
So select that one and hit next.
Let me call that domain.
Domain always means that inside of the domain layer, you can find the actual well logic behind an application.
So if we have a calculator, we would find the mathematical operation handling inside of the domain
layer.
Now let's hit next select net six again and let's hit create.
So next up, we will rename class one here.
So right click rename.
So this is very important because we want to update all references and let's call it calculator.
Let's hit apply.
And now every reference got changed, so never go ahead and simply write down a different name.
Always right click and update all the references by right clicking and setting rename just as I said,
move to unit test one and here we got our actual logical code.
We have a method here which should be inside of the calculator and not inside of the testing project.
Right?
So let's take that method here.
I will just select it and hit ctrl x to cut it out.
Now I got that copied right, save it and bring it inside the calculator class because here we should
have the logical code for the calculator, right?
So if you see it from that side, totally makes sense, right?
Now let's switch over to our unit test.
You can see that the sum method for sure is not available.
Let's add a reference to our test project.
So on the right side, make a right click on the calculator project.
This is our testing project.
You can see that indicated by that small flask sign here.
So right click on it, hit add and then add a project reference.
And for sure, we want to add our domain project, which is actually the calculator.
So hit.
Okay, awesome.
So we now wired them both together, switch over to the calculator and make that sum method public so
that we can access it.
Now inside of the testing project, start using domain and inside of domain.
We for sure got our calculator which has the sum method.
Now, if you are familiar with C-sharp, you can tell that we for sure cannot only call the sum method
like this.
We have to create an instance of the calculator, right?
So let's create a new object.
Var calculator equals to new.
Calculator and that will you have seen that just right now?
The reference is for sure wrong because if we say calculator, well, if we do it like this, it will
try to create an instance like that of our namespace, which is for sure not working.
So our namespace, let's just rename it, let's hit right click, rename and call the calculator test.
Now hit apply.
So the namespace got now adjusted to calculate the test and we can now instead of calculator test here
say new calculator.
Right, new calculator.
There we go.
And now it's referencing for sure the correct class.
So instead of calling sum here directly we now say calculator dot sum and that will work.
Okay, so basic C-sharp going on here.
Just to make that clear, we have two projects.
One is the domain which actually contains the calculator class, and the second one is our calculator
test project, which is just like a not so nice set name here.
We now adjusted the calculator test namespace so we give it a new name which will avoids that sort of
double reference.
So let's also rename our test project.
So right click on Calculator and let's rename it, let's call it calculator test.
Awesome.
So in that way the namings are clear.
Now instead of our unit test project, again, right click the test one method.
We will also rename that just in a second and hit run tests.
Always make sure in test driven development that you for sure run your test if you change something
inside of your code.
So here we added a new project, we added a new class, we added references.
It's a very good approach to now go ahead and run the actual test, right?
So you can see it passed.
So our implementation is working fine, even though it might get a little bit complicated, right?
So we changed something here, we added something there, we wired some stuff together.
We needed to resolve some reference issues.
However, in the end, we simply run a test and see everything works fine.