public void DeleteNotFoundTest() { Exception internalEx = new SportNotFoundException(); sportsService.Setup(r => r.DeleteSport("Golf")).Throws(new ServiceException(internalEx.Message, ErrorType.ENTITY_NOT_FOUND)); IActionResult result = controllerToTest.Delete("Golf"); NotFoundObjectResult notFound = result as NotFoundObjectResult; sportsService.Verify(r => r.DeleteSport("Golf"), Times.Once); Assert.IsNotNull(notFound); Assert.IsNotNull(notFound.Value); }
public void GetNotExistentTest() { //Arrange. Exception internalEx = new SportNotFoundException(); Exception toThrow = new ServiceException(internalEx.Message, ErrorType.ENTITY_NOT_FOUND); sportsService.Setup(s => s.GetSport(It.IsAny <string>())).Throws(toThrow); //Act. IActionResult result = controllerToTest.Get("Golf"); NotFoundObjectResult notFound = result as NotFoundObjectResult; ErrorModelOut error = notFound.Value as ErrorModelOut; //Assert. sportsService.Verify(r => r.GetSport("Golf"), Times.Once); Assert.IsNotNull(notFound); Assert.AreEqual(notFound.StatusCode, 404); Assert.AreEqual(toThrow.Message, error.ErrorMessage); }
public void CalculateTableNotExistingSportTest() { //Arrange. Exception internalEx = new SportNotFoundException(); Exception toThrow = new ServiceException(internalEx.Message, ErrorType.ENTITY_NOT_FOUND); tableGenerator.Setup(tg => tg.GetScoreTable(It.IsAny <string>())).Throws(toThrow); //Act. IActionResult result = controllerToTest.CalculateSportTable("Golf"); NotFoundObjectResult notFound = result as NotFoundObjectResult; ErrorModelOut error = notFound.Value as ErrorModelOut; //Assert. tableGenerator.VerifyAll(); Assert.IsNotNull(result); Assert.IsNotNull(notFound); Assert.IsNotNull(error); Assert.AreEqual(toThrow.Message, error.ErrorMessage); }
public void GetSportMatchesNotFoundTest() { //Arrange. Exception internalEx = new SportNotFoundException(); Exception toThrow = new ServiceException(internalEx.Message, ErrorType.ENTITY_NOT_FOUND); matchService.Setup(ms => ms.GetAllEncounterDtos(It.IsAny <string>())).Throws(toThrow); //Act. IActionResult result = controller.GetBySport("Soccer"); NotFoundObjectResult notFound = result as NotFoundObjectResult; ErrorModelOut error = notFound.Value as ErrorModelOut; //Assert. matchService.Verify(ms => ms.GetAllEncounterDtos(It.IsAny <string>()), Times.Once); Assert.IsNotNull(result); Assert.IsNotNull(notFound); Assert.AreEqual(404, notFound.StatusCode); Assert.IsNotNull(error); Assert.AreEqual(toThrow.Message, error.ErrorMessage); }
public void GetSportTeamsNotFoundTest() { //Arrange. Exception internalEx = new SportNotFoundException(); Exception toThrow = new ServiceException(internalEx.Message, ErrorType.ENTITY_NOT_FOUND); teamsRepo.Setup(r => r.GetSportTeams(It.IsAny <string>())).Throws(toThrow); //Act. IActionResult result = controllerToTest.GetTeams("Dummy"); NotFoundObjectResult notFound = result as NotFoundObjectResult; ErrorModelOut error = notFound.Value as ErrorModelOut; //Assert. teamsRepo.Verify(r => r.GetSportTeams(It.IsAny <string>()), Times.Once); Assert.IsNotNull(result); Assert.IsNotNull(notFound); Assert.AreEqual(404, notFound.StatusCode); Assert.IsNotNull(error); Assert.AreEqual(toThrow.Message, error.ErrorMessage); }