public void GetAverageScoreForInstructorByInstructorId_WhereInstructorExists_ReturnsAverageOfAllRatingsForInstructor([Values(1, 2, 3)] int instructorId) { //arrange var expectedScore = _ratingsList.Where(x => x.InstructorId == instructorId).Select(x => x.InstructorRating).Average(); var expectedResponse = new OverallInstructorRatingDTO() { InstructorId = instructorId, OverallInstructorRating = expectedScore }; IReportingService reportingService = Mock.Create <IReportingService>(); Mock.Arrange(() => reportingService.GetAverageRatingForInstructor(instructorId)).Returns(expectedResponse); var reportingController = new ReportingController(reportingService); //act var actual = reportingController.GetAverageRatingForInstructor(instructorId) as OkNegotiatedContentResult <OverallInstructorRatingDTO>; var actualContent = actual.Content; //assert Mock.Assert(reportingService); Assert.That(actual, Is.Not.Null); Assert.That(actual, Is.TypeOf(typeof(OkNegotiatedContentResult <OverallInstructorRatingDTO>))); Assert.That(actualContent, Is.EqualTo(expectedResponse)); }
public void GetAverageScoreForInstructorByInstructorId_WhereInstructorDoesntExist_ReturnsNotFoundResult([Values(100, 200, 300)] int instructorId) { //arrange OverallInstructorRatingDTO expected = null; IReportingService reportingService = Mock.Create <IReportingService>(); Mock.Arrange(() => reportingService.GetAverageRatingForInstructor(instructorId)).Returns(expected); var reportingController = new ReportingController(reportingService); //act var actual = reportingController.GetAverageRatingForInstructor(instructorId) as NotFoundResult; //assert Mock.Assert(reportingService); Assert.That(actual, Is.Not.Null); Assert.That(actual, Is.TypeOf(typeof(NotFoundResult))); }