FizzBuzz
Moving on to the FizzBuzz example from Chapter 2, Setting Up the .NET Test Environment, extend the classic behavior of this code kata and introduce some new behavior.
A new feature
A new requirement has been added to the classic FizzBuzz kata. The new requirement states that when a number is not divisible by 3 or 5, and is greater than 1, then the message Number not found
should be returned. This should be easy enough. Start, once again, with the tests, and make the necessary modifications.
Number not found
To get started, a new test method is needed to verify that the Number not found
message is returned:
[Fact] public void GivenNonDivisibleGreaterThan1ThenNumberNotFound() { // Arrange // Act var result = FizzBuzz(2); // Assert Assert.Equal("Number not found", result); }
Now, make the test pass by modifying the existing code:
private object FizzBuzz(int value) { if (value % 15 == 0) return "FizzBuzz"; if (value % 5 == 0) return "Buzz"; if (value % 3 == 0) return...