예제 #1
0
        public void PutTour_UpdateTour_RuntimeError_500InternalServerError()
        {
            ToursController controller = new ToursController(mockTourService.Object);

            this.SetupControllerTests(controller, "http://localhost/STCRMService/api/tour/1", HttpMethod.Get);
            var mockResponse = mockRepository.Create <UpdateTourResponse>();

            mockTourService.Setup(c => c.UpdateTour(It.IsAny <UpdateTourRequest>())).
            Returns(mockResponse.Object);
            mockResponse.Setup(r => r.Exception).Returns(new InvalidOperationException());
            var httpResponseMessage = controller.PutTour(It.IsAny <TourViewModel>());
            var postResponse        = httpResponseMessage.Content.ReadAsAsync <UpdateTourResponse>().ContinueWith(
                t => { return(t.Result); }).Result;

            mockRepository.VerifyAll();

            Assert.AreEqual(httpResponseMessage.StatusCode, HttpStatusCode.InternalServerError);
            Assert.AreNotEqual(postResponse.Exception, null);
        }
예제 #2
0
        public void PutTour_UpdateTour_Succeed()
        {
            ToursController controller = new ToursController(mockTourService.Object);

            this.SetupControllerTests(controller, "http://localhost/STCRMService/api/tour/1", HttpMethod.Get);
            var           mockResponse   = mockRepository.Create <UpdateTourResponse>();
            TourViewModel newContactTour = new TourViewModel()
            {
                TourID = SAMPLE_TOUR_ID
            };

            mockResponse.Setup(c => c.TourViewModel).Returns(newContactTour);
            mockTourService.Setup(c => c.UpdateTour(It.IsAny <UpdateTourRequest>())).Returns(mockResponse.Object);

            var httpResponseMessage = controller.PutTour(It.IsAny <TourViewModel>());
            var postResponse        = httpResponseMessage.Content.ReadAsAsync <UpdateTourResponse>().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);
        }