...
Create a new Test Project in the FindHighestNumber Solution
Install the packages you want (MSTest already installed, or NUnit - we are going to be using NUnit)
Create a new setup the new test class as shown here (remember you will have errors)
Code Block language c# namespace TopicManagerTests { public class TopicManagerTests { [Test] public void find_heighest_score_in_empty_array_return_empty_array() { // Arrange int[] array = {}; TopicManager cut = new TopicManager(); int[] expectedResult = {}; // Act Topic[] result = cut.findTopicHighScores(array); // Assert Assert.That(result, Is.EqualTo(result)); } } }
Create a new class called TopicManager in the FindHighestNumberService project
Clean the code up so that the class is in a namespace called TopicManagerService
Lines 9, 11, and 14 give us enough information to allow us to start thinking about what we are trying to design here. based on the requirements, we want to pass into the method
findTopicHighScores
an array of Topics and their accompanying scores. It should return the topic score of each Topic, we will call this TopicTopScore. Each item in the array being passed into thefindTopicHighScores
will be calledTopicScores
(plural I know, but it matches the context, you may want to lose the ‘s' at the end of the class name). Let’s refactor the code to reflect what we have outlined here.Code Block language c# public class TopicManagerTests { [Test] public void find_heighest_score_in_empty_array_return_empty_array() { // Arrange TopicScores[] array = Array.Empty<TopicScores>(); TopicManager cut = new TopicManager(); TopicTopScore[] expectedResult = Array.Empty<TopicTopScore>(); // Act TopicTopScore[] result = cut.findTopicHighScores(array); // Assert Assert.That(result, Is.EqualTo(result)); } }
We are now in a good position to get VS to generate the
findTopicHighScores
with the correct signatureCode Block language c# namespace TopicManagerService { public class TopicManager // TopicManager.cs { public TopicTopScore[] findTopicHighScores(TopicScores[] array) { // This block oc code assumes that the input is an empty array, there is no need for an if statement return Array.Empty<TopicTopScore>(); } } }
Now we need to complete the first piece of implementation code to pass the test
So you should have will also need the following pieces of code
Code Block namespace TopicManagerService { public class TopicTopScore // TopicTopSscore.cs { } }
Code Block namespace TopicManagerService { public class TopicScores // TopicScores.cs { } }
...