QLC-2.4) Stubs to Mocks test
Selvyn Wright
[Test]
public void find_heighest_score_with_array_of_many_return_array_of_many_using_stub()
{
//[{“Physics”, { 56, 67, 45, 89} }, {“Art”, { 87, 66, 78} }, {“Comp Sci”, { 45, 88, 97, 56} }]
// Arrange
int[] physics_scores = { 56, 67, 45, 89 };
string physics = "Physics";
int[] art_scores = { 87, 66, 78 };
string art = "Art";
int[] compSci_scores = { 45, 88, 97, 56 };
string compSci = "Comp Sci";
TopicScores[] topicScores = { new TopicScores(physics, physics_scores),
new TopicScores(art, art_scores),
new TopicScores(compSci, compSci_scores)};
// Setup your expectations
IHighestNumberFinder hnf = Substitute.For<IHighestNumberFinder>();
hnf.findHighestNumber(physics_scores).Returns(89);
hnf.findHighestNumber(art_scores).Returns(87);
hnf.findHighestNumber(compSci_scores).Returns(97);
TopicManager cut = new TopicManager(hnf);
TopicTopScore[] expectedResult = { new TopicTopScore("Physics", 89),
new TopicTopScore("Art", 87),
new TopicTopScore("Comp Sci", 97) };
// Act
TopicTopScore[] result = cut.findTopicHighScores(topicScores);
// Assert
Assert.AreEqual(result[0].TopicName, expectedResult[0].TopicName);
Assert.AreEqual(result[0].TopScore, expectedResult[0].TopScore);
Assert.AreEqual(result[1].TopicName, expectedResult[1].TopicName);
Assert.AreEqual(result[1].TopScore, expectedResult[1].TopScore);
Assert.AreEqual(result[2].TopicName, expectedResult[2].TopicName);
Assert.AreEqual(result[2].TopScore, expectedResult[2].TopScore);
}
{"serverDuration": 38, "requestCorrelationId": "24d574cf9bc44f648b73abb337e1baaa"}