Now let's play the devil's advocate game and let's return three from the get remaining number of seats
method.
But let me just close some of our files that we got open right now.
So let's just close all of that.
And let's scroll a little bit down.
And here we got get remaining number of seats.
So F12 to get inside there and let's simply return three.
Right.
And you should know now why we are returning three And in addition to return three, let's simply remove
cancel booking, throw new, not implemented exception.
Right.
Because as I said, we are the devil.
Switch over Now go to test test Explorer and let's start test.
So right click cancel booking, let's hit run.
You can see that the test is now passing.
Now to increase the trustworthy.
You should now know that we need to parameterize the test.
So let's go to cancel booking instead of using effect, we use theory attribute and add some inline
data.
Inline data.
And we use three for example, cancel booking would be int initial capacity.
Let's use initial capacity here at the given step.
So create a new flight with initial capacity and here add the then step at the bottom.
Also use it initial capacity.
Right?
Because if we create if we have like ten initial capacity and we book two seats and then remove two,
we should have again ten Awesome.
So let's save it like that.
And when we now run the test again, you will be able to see that it's again for sure still working
because we only have inline data set to three.
So let's copy that inline data over and set it to ten so that we have initial capacity set to ten.
And now for sure, if we start right click and run the test again, it will fail at least for the inland
data set to ten.
Awesome.
Okay.
You can see that failing now.
Perfect.
Okay, now let's implement the cancel booking functionality.
Let's simply go into cancel booking method right here.
You can see we use cancel booking DTO and what we want to do here is we want a Var flight entities dot
flights dot find.
We want to find a flight based on the cancel booking DTO we want to take that flight and cancel booking.
We submit DTO passenger email.
And cancel booking number of seats.
Great.
So we are at a red state now, so we need to first of all, fix that for sure.
Let's go ahead into cancel booking DTO and let's add properties for flight ID, passenger email number
of seats, right?
Prop good flight ID.
Prop string passenger email prop int number of seats.
Let's assign the properties values for the properties in the constructor.
Flight ID and capital letter property.
Right.
Flight id equals to flight id passenger email equals to passenger email and number of seats equals to
number of seats.
Now let's switch back again to the booking service.
And once we modify it, the flight, like we cancel something here, we need to for sure save the changes
in the database.
So what we do is entities dot save changes.
Awesome.
Because like we modified the flight, right.
And that needs to get saved now instead of returning three and get remaining number of seats, we for
sure want to use some logic instead.
So what we do here is return entities, dot flights, dot find.
We want to find a specific flight.
That one here or ID is like not the best name.
Let's rename it to flight ID.
So entities find a flight given is the flight ID and return the remaining number of seats of that flight.
Great.
So let's save it like this.
And here line 34.
As you saw that we are trying to find the flight based on the cancel booking DTO, but for sure we need
to use the flight ID from that because we are always trying to find the flight based on a key.
And that key is like the flight ID in that scenario.
Great.
So now go to test and run all tests and now they should all pass again implemented the logic and now
can also cancel a booking.
Great.
So now you can book everything gets remembered and you can also cancel the booking without expecting
any issues to take place because we have used the TDD approach and created a complete flight booking
system using a real database.