public void InsertTag_ValidTag_ReturnSuccess() { TagsController controller = new TagsController(mockTagService.Object); this.SetupControllerTests(controller, "http://localhost/STCRMService/api/tags", HttpMethod.Post); var mockResponse = mockRepository.Create <SaveTagResponse>(); TagViewModel newTag = new TagViewModel() { TagID = SAMPLE_TAG_ID }; mockResponse.Setup(c => c.TagViewModel).Returns(newTag); mockTagService.Setup(c => c.SaveTag(It.IsAny <SaveTagRequest>())).Returns(mockResponse.Object); var httpResponseMessage = controller.PostTag(It.IsAny <TagViewModel>()); var postResponse = httpResponseMessage.Content.ReadAsAsync <SaveTagResponse>().ContinueWith( t => { return(t.Result); }).Result; var tagResponse = postResponse.TagViewModel; mockRepository.VerifyAll(); Assert.IsTrue(postResponse.TagViewModel.TagID > 0, "Id is not greater than zero after insert."); Assert.AreEqual(httpResponseMessage.StatusCode, HttpStatusCode.OK); Assert.AreEqual(postResponse.Exception, null); }
public void PostTag_RuntimeError_500InternalServerError() { TagsController controller = new TagsController(mockTagService.Object); this.SetupControllerTests(controller, "http://localhost/STCRMService/api/tags", HttpMethod.Post); var mockResponse = mockRepository.Create <SaveTagResponse>(); mockTagService.Setup(c => c.SaveTag(It.IsAny <SaveTagRequest>())). Returns(mockResponse.Object); mockResponse.Setup(r => r.Exception).Returns(new InvalidOperationException()); var httpResponseMessage = controller.PostTag(It.IsAny <TagViewModel>()); var postResponse = httpResponseMessage.Content.ReadAsAsync <SaveTagResponse>().ContinueWith( t => { return(t.Result); }).Result; mockRepository.VerifyAll(); Assert.AreEqual(httpResponseMessage.StatusCode, HttpStatusCode.InternalServerError); Assert.AreNotEqual(postResponse.Exception, null); }