So when we now run our tests, you will see that they for sure fail.
And the information that we get from that books, books, flights method is that no database provider
has been configured for this DB context.
And this is exactly what we do now.
So go to Tools NuGet Package Manager and then manage the packages for the solution and click on Browse
because right now we will install a new package which is called Entity Framework Core Dot In-memory.
And here we have an in-memory database provider and we will install it.
So select the applications dot test project and hit install.
Now, once that's done, go to the flight application specifications.
That way we got our books flights method and here you can see var entities.
There we go, right var entities.
Now inside that new entities here since entities, let me just go to that using F12, you can see it's
inherited by Dbcontext, right?
So we can here inside of the constructor create a new Dbcontext options builder or use it.
So let's first of all start using Microsoft Dot Entity Framework Core.
And now inside that new entities object.
Here we're going to create a new Dbcontext options builder.
So pay attention so that you use the builder, not dbcontext options, but Dbcontext options builder.
And we will create a new one for the entities.
So and and on that object we can go ahead and call use in-memory database and let's create a database
and call it flights.
And on that database we can call options.
Awesome.
So what we do is we create a new instance of entities inside here.
We create a new Dbcontext options builder, configure a database and submit the options inside of that
well instantiation.
Now for sure, we are at a red state, so go to the entities object.
As I said, hover above it, press F12, for example.
Let's create a constructor.
So right down Ctrl, tap tap and that one should now take DB context options, not a builder this time
options.
And in order to make it run we need to use the base constructor to and provide options.
So that's also part of the official documentation, right?
So if we don't include the base constructor, we will get an error which tells us we need to implement
the base constructor.
So there's not a lot more to say about this.
Awesome.
Okay, so let's save this and for entity framework to make the flight run so that we can use it, we
need to go to flight.
And here you can see we have a constructor which takes a parameter and we need one parameter which is
completely empty.
So just create a flight constructor without any content.
And we can add an attribute here which is called obsolete.
You may have already seen that a couple of times, let's say needed by F for entity framework.
Awesome.
Okay, so don't think about all of that too much.
As I said, it's really more about the test driven approach, but we really want to use a real database
and an in-memory database here in that scenario is a real database, or at least it is configured like
a real database.
Okay, now let's switch over to entities.
And let's add a new method here which is protected override, void on model creating.
And let's add a model builder here.
Let's call it model builder.
And inside there we can or we have to write some code.
But let me explain you what exactly that is.
So this on model creating exists because we are inheriting from Dbcontext.
You need to think about it that way.
We are now creating a database based on our C-sharp classes, and that's exactly what's happening here.
Inside of that method, we can define how our C-sharp classes should be mapped to a database, And the
only thing that we really have to do right now is to call the model builder and to say, well, type
of flight.
So our flights should be mapped inside the database and we want to give them a key.
And the key is the flight dot ID.
So as I've already said, if you are familiar with SQL databases, you might know that each entry inside
of a database.
So let's say you have 100 cars inside of a database.
Each car entry needs a unique ID so that you can really identify each single value of the database.
And that's what we do in here.
And we say, Hey, for our flights, the key, the primary key is the ID, which is like for sure part
of our flight object.
And then just to really complete that, we call on model creating on the base so that we don't skip
that.
Okay.
And here again, I really need to mention it has really nothing to do with TDD in that scenario, right?
But it's entity framework and if you are familiar with C-sharp, there will be a point where you will
need to learn about entity framework core.
So in that scenario, even if you just copy it over from what you have seen right now, you will get
some experience in using entity framework and just listen to my simple explanations about the database
and all of that.
But you really don't have now to go online and really learn everything about entity framework core,
right?
So because this is TDD and everything that's not related to TDD, you can watch a course for this later
on.
Right now, just copy over if you don't understand something because the only thing that you should
really care about if you don't understand anything about TDD right.
So if you don't understand something on TDD, that's what you should have to care about.
But if you don't understand something now on entity framework, that's totally fine because this course
is not about entity framework and entity framework itself is a very, very huge topic.
So we would not be able to really cover entity framework in a TDD course.
Okay.
Now let's think about one more thing.
Our flight has a booking list, right?
So one flight can have many bookings.
This is what we have.
If we take a look at our flights, you can see booking list.
So one flight can have many bookings.
And exactly what we did here with the key, we need to do the same thing.
What I've just said, like one flight can have multiple bookings.
We need to define that inside of the database.
So model builder dot entity of type flight dot owns many F goes to F book booking list.
There we go.
So we say that one flight owns many bookings.
Great.
So let's save that switch back to our flight application specifications and let's open up the Test Explorer
and run the books.
Flight failing test again.
So you can now see that it has passed because we now provided a database.
However, this test should not pass right now, so let's just parameterize the test to make it way more
trustworthy.
Because you can see right now we are adding a ABC.com number of seats two and here in our flight booking
we return that.
So once we parameter wise our books flights test and at different values, we will see again that the
test is failing because our flight booking implementation here will not be enough.
All right, so let's do that.