Generating test stubs with GitHub Copilot Chat
For our final technical section of this chapter, let’s look at a method that finds the largest number in a sequence of numbers, provided that the number doesn’t have a “7” in it somewhere, such as a 71 or 17. This method is located inside of TestMe.cs:
public static class TestMe {
public static int CalculateLargestNumberWithoutASeven(
INumberProvider provider) {
IEnumerable<int> numbers = provider.GenerateNumbers();
return numbers.Where(x => !x.ToString().Contains("7"))
.Max();
}
}
This CalculateLargestNumberWithoutASeven method takes in an INumberProvider that allows us to call GenerateNumbers and get a sequence of integers.
Next, the method looks at the resulting sequence, finds...