public void CreateCommentInNoExistingMatch() { //Arrange. ControllerContext fakeContext = GetFakeControllerContext(); controller.ControllerContext = fakeContext; CommentModelIn input = new CommentModelIn() { Text = "this is a comment" }; Exception internalEx = new EncounterNotFoundException(); Exception toThrow = new ServiceException(internalEx.Message, ErrorType.ENTITY_NOT_FOUND); matchService.Setup(ms => ms.CommentOnEncounter(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>())).Throws(toThrow); //Act. IActionResult result = controller.CommentOnMatch(3, input); NotFoundObjectResult badRequest = result as NotFoundObjectResult; ErrorModelOut error = badRequest.Value as ErrorModelOut; //Assert. matchService.Verify(ms => ms.CommentOnEncounter(3, "username", input.Text), Times.Once); Assert.IsNotNull(result); Assert.IsNotNull(badRequest); Assert.AreEqual(404, badRequest.StatusCode); Assert.IsNotNull(error); Assert.AreEqual(error.ErrorMessage, toThrow.Message); }
public void PutAdd() { //Arrange. Exception internalEx = new EncounterNotFoundException(); Exception toThrow = new ServiceException(internalEx.Message, ErrorType.ENTITY_NOT_FOUND); matchService.Setup(ms => ms.ModifyEncounter(It.IsAny <int>(), It.IsAny <ICollection <int> >(), It.IsAny <DateTime>(), It.IsAny <string>())).Throws(toThrow); matchService.Setup(ms => ms.AddEncounter(It.IsAny <int>(), It.IsAny <ICollection <int> >(), It.IsAny <string>(), It.IsAny <DateTime>())).Returns(testEncounter); MatchModelIn input = BuildMatchModelIn(testEncounter); //Act. IActionResult result = controller.Put(1, input); CreatedAtRouteResult createdResult = result as CreatedAtRouteResult; EncounterModelOut modified = createdResult.Value as EncounterModelOut; //Assert. matchService.Verify(ms => ms.ModifyEncounter(It.IsAny <int>(), It.IsAny <ICollection <int> >(), It.IsAny <DateTime>(), It.IsAny <string>()), Times.Once); matchService.Verify(ms => ms.AddEncounter(It.IsAny <int>(), It.IsAny <ICollection <int> >(), It.IsAny <string>(), It.IsAny <DateTime>()), Times.Once); Assert.IsNotNull(result); Assert.IsNotNull(createdResult); Assert.AreEqual(201, createdResult.StatusCode); Assert.AreEqual("GetMatchById", createdResult.RouteName); Assert.IsNotNull(modified); Assert.AreEqual(modified.Id, testEncounter.id); }
public void DeleteNotExistentTest() { //Arrange. Exception internalEx = new EncounterNotFoundException(); Exception toThrow = new ServiceException(internalEx.Message, ErrorType.ENTITY_NOT_FOUND); matchService.Setup(ms => ms.DeleteEncounter(3)).Throws(toThrow); //Act. IActionResult result = controller.Delete(3); NotFoundObjectResult badRequest = result as NotFoundObjectResult; ErrorModelOut error = badRequest.Value as ErrorModelOut; //Assert. Assert.IsNotNull(result); Assert.IsNotNull(badRequest); Assert.IsNotNull(error); Assert.AreEqual(404, badRequest.StatusCode); Assert.AreEqual(error.ErrorMessage, toThrow.Message); }
public void GetNotExistingMatchTest() { //Arrange. Exception internalEx = new EncounterNotFoundException(); Exception toThrow = new ServiceException(internalEx.Message, ErrorType.ENTITY_NOT_FOUND); matchService.Setup(ms => ms.GetEncounter(It.IsAny <int>())).Throws(toThrow); //Act. IActionResult result = controller.Get(1); NotFoundObjectResult notFoundresult = result as NotFoundObjectResult; ErrorModelOut error = notFoundresult.Value as ErrorModelOut; //Assert. Assert.IsNotNull(result); Assert.IsNotNull(notFoundresult); Assert.AreEqual(404, notFoundresult.StatusCode); Assert.IsNotNull(error); Assert.AreEqual(error.ErrorMessage, toThrow.Message); }