public void PostTour_validTour_Succeed() { ToursController controller = new ToursController(mockTourService.Object); this.SetupControllerTests(controller, "http://localhost/STCRMService/api/tour", HttpMethod.Get); var mockResponse = mockRepository.Create <InsertTourResponse>(); TourViewModel newContactTour = new TourViewModel() { TourID = SAMPLE_TOUR_ID }; mockResponse.Setup(c => c.TourViewModel).Returns(newContactTour); mockTourService.Setup(c => c.InsertTour(It.IsAny <InsertTourRequest>())).Returns(mockResponse.Object); var httpResponseMessage = controller.PostTour(It.IsAny <TourViewModel>()); var postResponse = httpResponseMessage.Content.ReadAsAsync <InsertTourResponse>().ContinueWith( t => { return(t.Result); }).Result; var contactResponse = postResponse.TourViewModel; mockRepository.VerifyAll(); Assert.IsTrue(postResponse.TourViewModel.TourID > 0, "Id is not greater than zero after insert."); Assert.AreEqual(httpResponseMessage.StatusCode, HttpStatusCode.OK); Assert.AreEqual(postResponse.Exception, null); }
public void PostTour_RuntimeError_500InternalServerError() { ToursController controller = new ToursController(mockTourService.Object); this.SetupControllerTests(controller, "http://localhost/STCRMService/api/tour", HttpMethod.Get); var mockResponse = mockRepository.Create <InsertTourResponse>(); mockTourService.Setup(c => c.InsertTour(It.IsAny <InsertTourRequest>())).Returns(mockResponse.Object); mockResponse.Setup(r => r.Exception).Returns(new InvalidOperationException()); var httpResponseMessage = controller.PostTour(It.IsAny <TourViewModel>()); var postResponse = httpResponseMessage.Content.ReadAsAsync <InsertTourResponse>().ContinueWith( t => { return(t.Result); }).Result; mockRepository.VerifyAll(); Assert.AreEqual(httpResponseMessage.StatusCode, HttpStatusCode.InternalServerError); Assert.AreNotEqual(postResponse.Exception, null); }