The student will refactor the code to adhere to one of the SOLID principles and understand why. Once a round of updates are made, the student will re-run the unit tests to confirm nothing was broken. A new C# 6.0 feature will also be incorporated into the refactoring effort, specifically: string interpolation. Students will confirm all tests pass after making string interpolation changes.
- [Voiceover] Ok, so, we are in the refactor phase.…So, let's go ahead and take a look at our code…and see what we can change to make it adhere…to some standards.…Now, the first thing that jumps out to me is…I know that I'm using C Sharp six point zero,…so one of the new features that came out with it…was string interpolation.…So, let's go ahead and use it by getting rid of…the string format feature.…To do that, we need to just add a dollar sign…in front of a string,…and then we can go ahead and replace the variables…with the placeholders, such as weekly hours,…we can add that to zero here,…wage, we'll replace that where one is,…salary, we'll replace the number two.…
And in the beginning of each string,…don't forget to add the dollar sign so that the compiler…recognizes the placeholders.…Ok, looks good, get rid of that closing parenthesis…and that looks good for now.…Let's go ahead and do the same for our next method,…weekly hours will replace the two zero placeholders…and let's get rid of string format, add the dollar sign…
In this course, Reynald Adolphe explains the principles of test-driven development and shows how to apply them to two different C# workflows. First, he creates a new test-driven project. He writes the test cases before the code to drive the design of the program. In the second scenario, he writes test cases for an existing C# project, to find bugs before it goes live. Along the way, Reynald uses Microsoft's MSTest, but he also introduces other testing tools (such as the unit testing framework xUnit and the mocking framework Moq) and theories (such as the red-green-refactor mantra and SOLID principles) that make test-driven development so efficient.
- Different approaches to testing
- Using testing tools and mocking frameworks
- Creating a simple C# test-driven project
- Adding a failing test
- Updating tests to pass
- Refactoring code
- Using Moq to test data