public void PutTag_UnknownIdPassed_ReturnsNotFound() { _mockRepository.Setup(r => r.GetTagById(It.IsAny <long>())).Returns((Tag)null); TagUpdateDto tagUpdateDto = new TagUpdateDto() { Name = "estudos" }; var notFoundResult = _controller.PutTag(5, tagUpdateDto); Assert.IsType <NotFoundResult>(notFoundResult); }
public void UpdateTag_UpdateTag_RuntimeError_500InternalServerError() { TagsController controller = new TagsController(mockTagService.Object); this.SetupControllerTests(controller, "http://localhost/STCRMService/api/tags/1", HttpMethod.Get); var mockResponse = mockRepository.Create <UpdateTagResponse>(); mockTagService.Setup(c => c.UpdateTag(It.IsAny <UpdateTagRequest>())). Returns(mockResponse.Object); mockResponse.Setup(r => r.Exception).Returns(new InvalidOperationException()); var httpResponseMessage = controller.PutTag(It.IsAny <TagViewModel>()); var postResponse = httpResponseMessage.Content.ReadAsAsync <UpdateTagResponse>().ContinueWith( t => { return(t.Result); }).Result; mockRepository.VerifyAll(); Assert.AreEqual(httpResponseMessage.StatusCode, HttpStatusCode.InternalServerError); Assert.AreNotEqual(postResponse.Exception, null); }