Okay, so let's move on.
Book flights.
Let's add a new variable here called entities.
Equals to new entities.
And for sure, we are at a red state now because he does not know entities.
So let's move on and create an entities class.
Let's do that inside of our data project.
So here go into data project and then class one, right?
So and we directly refactor that.
So just rename it and name it entities.
There we go.
Hit, apply.
That's all we have to do.
Perfect.
You could have also created that entities class in the flight specifications.
Right?
And then move it later on.
But since we have a project only for the data layer, we can directly insert it there also.
So both ways are definitely valid.
Now let's add a reference to the data project in the application test project so that we can use the
namespace there.
Let's go in the flight applications here and right click in the Applications Test project and add a
new project reference.
And as I said, we want to add the data project.
So hit.
Okay, now let's scroll up and add a new using directive using data.
There we go.
Now let's scroll down here.
We got our entities and entities in that case are like our bookings.
So for the booking service, he should know which bookings are existing in our database.
Let's provide entities and submit entities.
Now we are again at a red state.
So let's create a constructor in our booking service, Ctor Tab Tab.
And that booking service is taking entities entities.
There we go.
Now we are at a green state again.
For our entities.
As I said, this is like our data source.
So which flights and bookings and all of that we have let's enter some flights.
So entities, dot flights, dot add.
Never forget that we are using the TDD approach.
So we are really thinking about what we want to have and writing it down and then fixing compilation
errors.
So let's add a flight with three actual seats available.
Awesome so entities flights dot add now again we are at red state so go to our entities right here and
that entities is an actual DB context and the DB context is really an actual database provider.
So we can use entity framework right here.
So show potential fixes and you can see install package, Microsoft Entity framework Core, and we want
to do that, find and install the latest version.
Now the error is gone and if I hover above it, you can see here a DB context instance represents the
session with the database.
So this is like a real world scenario where you could connect your application to a real database.
Now we want to don't dive too deep into that topic, right?
Because that's like entity framework core and that could be a whole topic by itself.
But how it works is mainly you have if you think of an SQL database, if you have no no clue about databases,
just just don't pay too much attention to just follow along, write down the code that I'm writing down.
But if you know about SQL databases, you know that there are tables for specific data, right?
And what we do now is we create the DB set, which is like a table, and we attach our flight type and
we have flight already defined inside of the reference domain.
So let's add it.
And we have the project reference and using domain here, right?
So this is our flight model and let's set it to flights and it goes to a new set of type flight.
So in the end, what will happen here is we will have a database.
Just think about that, right?
So the DB context is just like the structure of the database.
But in the end it would be like we have a database which contains a table which has all of the single
columns of the flight.
So we would have a SQL table which has booking list and like number of remaining seats and all of that.
Okay.
As I said, we don't want to dive too deep into that topic.
Okay.
So that said, let's switch back to our flight specifications here again or flight application specifications
and entities.
Flights, dot add new flight.
Let's add a project reference here too, so that we can really use it.
So show potential fixes and start using domain.
And when we book a flight, we get that here booking service, right book and we want to go ahead and
use the flight ID and not a new good.
So flight.id, let's set it like this flight.id.
There we go.
He's trying to use that class for sure.
Flight ID, Awesome.
Let's save it like this.
Sure.
We are at a red state right now, so switch over to our flight.
To our actual flight class.
Right.
So select it and press F12, for example.
And let's add a new good here.
So add a property or we can we can also write it down manually.
Good.
Because this time we only have a getter here, so we don't set it.
Now we need to use that ID in the flight application specifications.
Right?
So here where we call booking service Dot find bookings, we want to find bookings for a specific ID,
So let's just call flight ID, There we go.
And then the find bookings method that we have.
Right.
Uh, let me just go to it.
F12 here.
We for sure want to pass that Good, good flight ID so that we can use it.
Okay, so that's it for now.
Now let's take a look on the flight right here.
So in order to fix that red states, let's create a new flight.
Var flight equals to a new flight with a capacity of three.
There we go.
And we want to add that to the entities.
So flight.
Okay, now let me just sum this up.
What we have done so far, because I know that might be a point where you a little bit confused entities,
as I said, is like our database right?
Just think about it that way.
And we create a new flight and we add that flight to our database because we call entities flights and
add that flight that we have just created.
Then we create the booking service and that service can book flights for us and it can find flights.
So we test this book.
So we create a new booking of a flight.
For that, we create a new data transfer object to transfer data because that's what you do really professionally.
So you create a DTO and inside that DTO you set all the values flight ID, passenger email, right?
So we actually book that and we use our new flight that we have right here.
And then we take the booking service and try to get that flight again or check if it's inside of our
well entities object, which is our database.
So we book it and afterwards we check if it's in it.
And for that we now need to really use the database.
And that's why we now make use of the so-called in-memory data.
The base.
So as you can see, we're really taking that TD stuff here.
Serious.
So next up, we will create an in-memory database so we don't have an SQL database or something like
that, only a database which is available during runtime of the application.