Okay, so let's skip the what if analysis and checking for the completeness of the booking service dot
book method.
And let's add a test for cancelling bookings first.
So inside of our flight application specifications here, let's create a new test method so this books
flights method here.
We have already tested that.
Let's create a new one now for canceling.
So write down fact Public void Cancels booking.
And for sure we again have a given when and a then step.
And you can use this as a pattern.
So if you create a new test method, you can use given when and then as comments here and just fill
them out.
So right now we are not sure about given but for sure we are know that we can call booking service right
and then a new method which we can call for example cancel booking.
So cancel booking and now we are at a red state.
So in given we can say var entities equals to new entities object.
And again we can create a new database.
But we already have done that so we can copy it over from here.
So var entities equals two new entities.
Use in-memory database.
Configure a database called flights and then submit the options.
Now we can create the booking service.
So var booking service equals to new booking service
and we for sure have to submit entities.
So let's send over the entities.
This is why we had to create this new database here.
So we creating a new booking service and then we want to cancel a booking.
So simply hold the cursor above.
Cancel booking show potential fix generate method, cancel booking.
You can see like a preview right here.
This is exactly what we want to have.
Right?
Public void cancel booking thrown you not implemented exception.
So let's simply click on generate method cancel booking.
Awesome.
If we take a look at the booking service, we now have that method inside here.
Now for sure we need to well submit the information about which booking we want to cancel.
Right.
So let's cancel.
Let me just put that inside of the parentheses here.
A new cancel booking DTO which we will have to create.
Right.
Flight id set to good dot new good right now.
Awesome.
Next up, we got the passenger email set to for example, I'm at m.com and for sure we got the number
of seats set to two.
That's all we got to do right now.
So we want to cancel the booking so we create a new DTO to submit the information about which booking
we want to cancel.
And instead of that DTO, we got a flight ID, the information about like which flight we want to cancel,
right?
The passenger email and the number of seats which are related to that cancel request.
So let's add our public class.
Cancel booking DTO scroll a little bit down.
Public class cancel booking DTO
and inside there we got a constructor for sure.
So ctor and you can see that we here submitting flight ID passenger email a number of seats.
So let's simply do it exactly that way.
A new good for flight ID, string passenger email and int number of seats.
Awesome.
Now we are at a green state again, but now let's directly move that class over.
So in application project, create a new C-sharp class and call it cancel booking DTO There we go.
And we will just switch back right now to the flight specifications and take that class here, cut it
out and bring it into that new C-sharp file here.
Great.
So perfect.
Now we got that here.
So we save some time later because we don't need to refactor anymore.
Okay, Let's switch back to flight specifications.
You can see we are at a red state because in cancel booking, if we go into that, keep in mind that
we are submitting something, right?
So we call that method and we submit submitting a new cancel booking DTO.
So let's go into cancel booking and create a parameter here which takes cancel booking, DTO cancel
booking, DTO awesome.
Now switch back again and we are again at Green State.
So here at given right after creating the entities, we want to for sure have a flight inside there
so that we don't have an empty database.
Right.
We want to have a flight with at least a seat capacity of three.
So let's add it here.
Entities, dot flights, dot add flight.
Great.
So now we have at least one flight inside there.
And if we want to cancel something, we have to book something first, right?
So after creating the booking service, let's use that booking service to book a flight.
So booking service, dot book.
And now we can submit a new DTO new book, DTO.
So what do we want to book?
Flight ID?
Well, we want to book a flight of the flight we have just created here.
Submit the passenger email for example, m@m.com number of seats set to two.
Great.
Okay, so now we book that flight and here in cancel booking, we want to cancel the booking for that
flight id not for new good flight.id.
Okay.
That's what we have to implement.
So we create database and we add a flight.
Then we book something for that flight and then we send a request for canceling that booking that we
have just created.
Finally, let's come to the then step booking service dot.
Get remaining number of seats for flight ID dot should dot be too.
Okay.
So get remaining number of seats for sure is something we need to create.
We want to submit the flight ID there.
So we want to know how many seats are remaining for that specific flight.
And the value should be three, not two.
There we go.
Because we create a flight with three seats.
Then we book two.
So one is remaining, then we cancel it again for two, and then we should have three again.
So let's move on and add the get remaining number of seats.
Hold the cursor here above that show potential fixes.
Let's generate method, get remaining number of seats.
Perfect.
It's inside of the booking service.
So let's save that here.
Inside of booking service, you can now see get remaining number of seats.
And now before we come to the next part and continue this, let's really quick improve our flight specification
because you may think about like, okay, here we have entities, new entities generate something,
right?
And we also have that here, right?
It's exactly the same code.
So what we can do instead for sure is to create like, let me just copy that over here.
Let me just copy that over.
Read only entities.
Let me paste that here.
Let's remove the var.
So read only entities, entities, new entities, object, use flights and all of that.
So we can now go ahead and get rid of the entities creation here.
That's the first part at both methods.
Also here entities.
Great.
So a little bit of refactoring.
We can also get rid of the booking service because we are again like repeating that.
So copy it over and create read only booking service.
Let's just paste that again.
Booking service equals to new booking service, but we need to set the value instead of a constructor.
So let's just call it read only booking service, booking service, just like that.
And then we create a constructor.
So sitter and inside of that constructor we're going to say booking service is equals to new booking
service.
And then we submit entities.
Entities, which is for sure this object here or this read only field.
Perfect.
Now go ahead and remove the booking service.
New booking service because we don't need that anymore at both methods again.
So now we really improved our code and for any future methods, you could go ahead and use entities
and the booking service which we have directly set up right here.