예제 #1
0
        public void DeleteBooking_WhenNoBooking_ReturnNotFound(int expectedStatusCode)
        {
            _mockService.Setup(s => s.GetBookingById(1)).Returns(Task.FromResult((Booking)null));

            var response = _controller.DeleteBooking(1).GetAwaiter().GetResult();

            // Assert
            var result = response as NotFoundResult;

            Assert.That(result.StatusCode == expectedStatusCode);
        }
예제 #2
0
        public async void Remove_ValidIdPassed_ReturnsOk()
        {
            // Arrange
            var existingId = 1;

            // Act
            var actionResult = await _controller.DeleteBooking(existingId);

            // Assert
            Assert.IsType <OkObjectResult>(actionResult.Result);
        }
예제 #3
0
        public void TestDeleteBooking()
        {
            Booking a = new Booking()
            {
                BookingId  = 1,
                User       = "******",
                Service    = "Service1",
                BookedFrom = DateTime.Now,
                BookedTo   = DateTime.Now.AddDays(1),
                Deleted    = false
            };

            var mockBookingValidator = new Mock <IBookingValidator>();

            mockBookingValidator.Setup(x => x.DeleteBooking("1")).Verifiable();
            mockBookingValidator.Setup(x => x.secure(null)).Verifiable();
            mockBookingValidator.Setup(x => x.AtmSecure(null)).Verifiable();

            var controller        = new BookingsController(mockBookingValidator.Object);
            var controllerContext = new HttpControllerContext();
            var request           = new HttpRequestMessage();

            request.Headers.Add("TODO_PAGOS_TOKEN", "1");
            controllerContext.Request    = request;
            controller.ControllerContext = controllerContext;

            IHttpActionResult actionResult = controller.DeleteBooking("1");
            var contentResult = actionResult as OkNegotiatedContentResult <IEnumerable <Booking> >;

            Assert.IsNotNull(actionResult);
        }
예제 #4
0
        public void ShouldNot_DeleteBooking_NotFound()
        {
            Booking testBooking = new Booking {
                Id = 10
            };

            Mock <IUnitOfWork> mock = new Mock <IUnitOfWork>();

            mock.Setup(f => f.Bookings.GetById(10)).Returns((Booking)null);

            BookingsController controller = new BookingsController(mock.Object, null, null);
            var result = controller.DeleteBooking(10);

            Assert.IsType <NotFoundResult>(result);
        }
예제 #5
0
        public void Should_DeleteBooking()
        {
            Booking testBooking = new Booking {
                Id = 1
            };

            Mock <IUnitOfWork> mock = new Mock <IUnitOfWork>();

            mock.Setup(f => f.Bookings.GetById(1)).Returns(testBooking);
            mock.Setup(f => f.Bookings.Delete(testBooking)).Returns(true);

            BookingsController controller = new BookingsController(mock.Object, null, null);
            var result = controller.DeleteBooking(1);

            Assert.IsType <OkObjectResult>(result);
        }
예제 #6
0
        public void ShouldNot_DeleteBooking_ModelStateError()
        {
            Booking testBooking = new Booking {
                Id = 1
            };

            Mock <IUnitOfWork> mock = new Mock <IUnitOfWork>();

            mock.Setup(f => f.Bookings.Delete(testBooking)).Returns(true);

            BookingsController controller = new BookingsController(mock.Object, null, null);

            controller.ModelState.AddModelError("TestError", "Error");
            var result = controller.DeleteBooking(1);

            Assert.IsType <BadRequestObjectResult>(result);
        }