Great.
So now, just to make that clear, right now we have two projects, one for testing, and the second
one is actually the domain layer, which contains all of the functional stuff from the calculator.
And this is how you really should build a professional applications.
Now, in order to make that complete, because as I said, we want to focus on real world applications
here, we are going to create even another project because that's how professional software is built
out there in the industry.
So right click on your solution and add a new project, and this time we will add an ASP.Net Core Web
API.
You can see that here, ASP.Net Core Web API.
If you have never, ever touched anything with ASP.Net Core in C C-sharp, you are definitely missing
out, right?
So go ahead and check out our ASP.Net Core six course on YouTube or you can find the complete course
inside of our full access subscription from tutorials for you.
Right?
It contains so much content and if you are interested in C sharp Right.
And if you really work as a C sharp developer, you need to learn ASP.Net Core.
I can definitely promise that.
So let's go ahead ASP.Net Core Web API, we select that one and hit on next.
Now let's simply call it Web.
Let's hit next again.
Again, we select Dotnet six configure for Https, no authentication and we don't need Docker right
now.
So simply hit create now just to make that very, very easy.
What is a web API?
Well, just think about that.
What we will do is we will bring our calculator online.
So later on everyone can call our calculator methods.
That's what we are doing, right?
So we're offering an application interface on the web where someone else can send requests to our calculator
right from a theoretical part.
We will not host the application here because we are really just interested in how to build such applications,
not how to host them right now because we are focusing on test driven development, right?
So don't forget that.
Now the first thing that we have to do, we need to add a reference of the domain library to the web
project.
So I will switch to the Web project.
I got that right here.
Right.
It's indicated by that nice Internet logo or Internet icon here.
And again, we do a right click and add a project reference.
There we go.
And we want to add the domain layer because just think about that.
Now pay attention.
Our web interface, which is actually for the actual user, and that interface calls the actual functional
stuff, which is inside the domain.
Now, our web project does not need any reference to testing because only test and domain should be
connected.
So test and domain are connected and domain and web project are connected.
Never forget domain is our functional code.
So let's go ahead and add the domain reference because if someone wants to call a sum method on the
calculator from web, our web project needs to know how to call the sum method or what even that is.
Right now.
You can see that we have inside of the Web project weather forecast here and the weather forecast controller
inside of the controllers folder.
So this is called an API controller.
Let's open that up and you can see it's indicated here by two comments, which is API controller and
the actual route.
So if I go ahead and start the application, I will be able to access code from inside here methods
and all of that by going to localhost colon and then enter a port like one, two, three, four and
then slash weather forecast and then for example, slash weather forecast.
And that will result in that method here getting called.
So I will just get some random weather information.
Okay.
We will not dive deeper into that.
Let's just adjust it so that it's matching our scenario.
So right click on the weather forecast controller hit rename and write down calculate controller.
Let me hit apply.
You can see calculate controller and it automatically also renamed the file.
So it's now called calculate controller dot CSS.
That's awesome.
Let's save it like this.
Now delete the weather forecast.
We also don't need that one.
And now switch back to the calculator controller and we can delete the complete code from that get method
here and we will switch it over from returning an enumerable.
We changed that and this method or action will return an integer.
Right?
Call it get just like that.
And if someone is actually calling that from the web, he wants to provide two numbers, right?
So please sum up five and ten for example.
So again, we will build a structure similar to our actual functional code.
Let's just set the path here in a different way.
As I said, please don't care too much about what we are doing right now.
I really want to give you, well, a real world scenario on how an application would be set up, but
it's right now not related to any testing, but you will see everything just in a second.
So if you follow along, just do it exactly like this.
Take your time right now and write it down like that.
This is just the route that we are defining.
And there I made a mistake.
Should look like this.
And now what we do and that's the interesting part of the important part.
We now add our domain here.
So we call the calculator dot sum.
So let's go and start using domain because we added the project reference.
So if you haven't done that, you will not be able to use domain.
Now let's create a new calculator.
So var calculator equals to new calculator and we simply return calculator dot sum and for sure we will
provide left and right which we are receiving from the action here.
So this is a method, but it's called action because it's an API controller.
So let me just get that clear.
If we host this application, this web project, for example, anyone could call this method here.
So he will provide left and right by writing down like, uh, any URL in the browser slash add slash
five slash ten five will then be here left and ten will be right then.
And then we call our calculator and sum it up and return it as a response for the user.
So in the best scenario, you have some prior knowledge about web development and a lot of people have
it.
So I'm pretty sure that you understand what I'm talking about.
And really, if you have no idea of web development in general, you really have to take care about
that because most of the applications out there are built for any web scenario.
So don't worry about that too much.
Go ahead and watch this course about TDD.
That's all good.
But afterwards you should go ahead and learn web development for C-sharp ASP.
And we really got a lot of ASP.Net content, so we got you covered.
Perfect.
Let's save it like this and just see that we can go to the calculator, dot CSS and inside here we got
our functional code right And we can now simply change that if we think we our logic from that.
Some method should be different.
Obviously right now it's correct.
Right.
But just let's just assume, but let's just assume you need to change it.
You can simply change it here and it gets referenced everywhere in the testing project and also in the
web project.
So you're changing it once at one position and all references are updated for sure.
As I said, not all function bodies are as simple as the sum function right here.
Since we are calling the plus here in the sum function, we don't seem to break something by mistake.
Right.
And that's because I wanted the first example to be very simple to understand.
Now let's replace the plus.
Sign here with the minus sign as we have done it before, and let's simply run the test.
So right click and again run test.
And we have done that before.
So hit, run and you can see that the test failed.
So now what if we write down an application which has a functional method just like this one, but it's
not that easy to write it down so that you end up by resulting in a fail test.
And this is why there is approach which is called test first, and we will take care about that right
now.
So just to make that clear, we will for sure replace it with a plus sign here again so that everything
is working.
But now we focus on test first approach.
So let's move on and talk about that.