From the course: ASP.NET Core: Test-Driven Development

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Refactor existing code

Refactor existing code - ASP.NET Core Tutorial

From the course: ASP.NET Core: Test-Driven Development

Start my 1-month free trial

Refactor existing code

- [Instructor] Let's perform some refactoring in our booking service method. As I've said before, our unit test should give us the confidence in any changes we might make. So this gives us the freedom to play around, and maybe even experiment a little bit. Let's go to our booking service class. ReSharper is suggesting that we invert this if statement, so let's use the ReSharper Command and select invert if. Now, I also don't like it when strings took against null because often, from user input, they can be empty. So let's switch this out for an is null or empty, but I think it'd be a good idea to write a test for this. Let's go to our Booking Service Tests and we'll duplicate this test and we'll give it a modifier of WithEmptyCouponCode. We'll pass in an empty string CouponCode and run the test. Now let's go back to our code and make the change. String.IsNullOrEmpty, now we're in the test again. Everything looks good. Now, as I mentioned before, it's important to run your app to make…

Contents