We started with the test scenario and made the test pass and improved its trustworthiness.
So the next step is checking to see if the cancel booking method is entirely complete.
Let's look at the production code to check for its completeness.
When we switch to the flight class, you can see the cancel booking right here.
But is that everything?
What the cancel booking should do?
What if the passenger who's canceling the book has never actually booked this flight?
However, we shouldn't start implementing such production code because we should think about the scenario
and write the test first.
So let's add a new test.
Let's call it doesn't cancel bookings for passengers who have not booked.
Let's go to flight specifications and create.
We can start with the fact here.
Let's create effect.
Public void doesn't cancel bookings for passengers who have not booked.
All right.
That's an awesome test method name.
Right.
But it's describing the scenario.
Very nice.
So don't or we should not cancel any bookings for passengers who really have not booked any flight.
Let's add a given.
And when step so var flight equals to new flight, this is the given step, right?
So we are given a flight with three available seats.
Now let's create a cancel booking flights, cancel booking, and for passenger email we again take like
abc.com.
That's totally fine.
And for number of seats we take two.
So I want to cancel for a abc.com number of seats two.
Right.
And you can see that I added an error here because I want cancel booking to return an error, but this
time not an overbooking error.
Right.
We will create its own error class for it.
And yeah.
So if we are trying to cancel a booking for abc.com but a ABC's never has booked a flight, we want
to return an error here.
Now keep in mind the second law of TDD so we do not proceed any further because we have an error here.
So let's go ahead and fix this right now.
So switch over to the cancel booking method and set the return type to nullable object and let's return
Null right now to fix the compilation at its first step, we don't need to add any logic right now.
Oh, there we go.
Sorry.
Not return.
It's return null now.
Okay.
Flight specification.
You can see the compilation error is gone, which is nice.
So we can now continue.
So the then step should be error dot should be of type booking not found error.
There we go.
We can call it like this booking not found error.
Let's add that booking class.
So go to domain.
That way we have the overbooking error too.
Let's simply add a new class and we can call it booking.
Not found error, just exactly the name that we have just written down.
So booking not found error for abc.com.
Then for example, don't make it internal, make it public public class booking not found error in domain
namespace.
That's fine.
So now in flight specifications we can see that the compilation error is gone too.
Perfect.
So next up, we need to write the minimum amount of code to actually pass the test.
So again, switch to the devil's advocate side and you can see here in the then step errors should be
of type booking, not found error.
So let's go ahead and simply return new booking, not found error.
There we go.
Let's switch back.
That was devil's advocate, right?
So we make that test pass anyway.
Anyway, so let's run the test.
You can see that it actually well works fine, doesn't cancel booking.
Right.
It succeeded.
So it passed and we don't want that.
So how can we defeat the devil?
Exactly.
We need to add new tests.
So first of all, let's switch to our slide here.
And instead of returning new booking NotFound, let's implement a real logic.
Because right now we are always returning a booking, not found error, which is obviously not correct.
Okay.
So based on laws, we are now not able to work on the production code because we need to add a test
first.
So we know that there is an issue here and that we need to adjust that, but we need to write the test
first.
So let's switch back to flight specifications and let's add a new test.
And that one is fact.
Again, public void, let's call it returns null when successfully cancels a booking.
There we go.
And I mean, I don't need to describe it any further, right?
So if we cancel a booking successfully, we want to return null.
And that's what's not happening right now.
So let's create a new flight.
So var new flight, you can see this is some sort of repeating, right?
And let's book a flight.
So flight dot book, let's book it for again, passenger email.
Let me write that down a@b.com for number of seats one and let's grab the error flight dot cancel booking
or the potential error cancel booking for passenger email a@b.com again.
And for sure we also want to set the number of seats to three one now error should be null.
There we go.
So in that scenario we cancel a booking which is existing and we expect the error which or the error
object which should or should not get returned from cancel booking to be actual null.
Awesome.
So if we run the test now we should see at least one failing and that's great because then we can write
our production code.
Awesome.
So you can see we defeated the devil.
Here we got return nulls.
And here you can see returns null.
Expected error to be null but found booking not found error.
So we now have the test proof of something being wrong inside of our cancel booking.
Awesome.
So now let's move on.
Right to production code right here.
Let's check that in an if statement.
So if a booking list contains any, but we want to check for the opposite.
So if it doesn't, if booking list does not contain any booking where the booking is like booking dot
email equals to passenger email.
So if we don't have a booking with that passenger email inside of our booking list, then we want to
return a new booking.
Not found error.
I hope that makes sense.
Right.
So it makes sense for you.
So here we have our booking list and if it does not contain any booking where this booking has an email
of passenger email, which actually means like check if we have a booking with the passenger email inside
of our booking list and if we do not have it, then return a booking not found.
If you don't know what this is, you should definitely learn about expressions and Linq in C sharp.
Awesome.
So in that scenario we return booking not found and in every other case we had a booking with that passenger
email.
So we simply return null.
And now we should be trustworthy enough.
So let's go ahead and rerun all of our tests and they should all pass now.
Awesome.
So all tests have passed and we again increased the trustworthiness of our testing suit.