コード例 #1
0
        public void CreateInValidBookingAlreadyBooked()
        {
            // Arrange
            IAcmeRepository repo       = new AcmeRepository();
            var             mockLogger = new Mock <ILogger>();

            BookingsController controller = new BookingsController(repo, mockLogger.Object);

            controller.Request       = new HttpRequestMessage();
            controller.Configuration = new HttpConfiguration();

            BookingModel bm = new BookingModel
            {
                PassengerName = "Karen Lom",
                Date          = new DateTime(2018, 3, 5),
                FlightNo      = 2
            };

            // Act
            var result = controller.Post(bm);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.StatusCode == System.Net.HttpStatusCode.BadRequest);
            HttpError err;

            Assert.IsTrue(result.TryGetContentValue <HttpError>(out err));
            Assert.IsTrue(err.Message.IndexOf("Booking already exists for this passenger for flight 2 on date") != -1);
        }
コード例 #2
0
        public void CreateInValidBookingFlightNo()
        {
            // Arrange
            IAcmeRepository repo       = new AcmeRepository();
            var             mockLogger = new Mock <ILogger>();

            BookingsController controller = new BookingsController(repo, mockLogger.Object);

            controller.Request       = new HttpRequestMessage();
            controller.Configuration = new HttpConfiguration();

            BookingModel bm = new BookingModel
            {
                PassengerName = "John SMith",
                Date          = new DateTime(2018, 3, 7),
                FlightNo      = 53
            };

            // Act
            var result = controller.Post(bm);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.StatusCode == System.Net.HttpStatusCode.BadRequest);
            HttpError err;

            Assert.IsTrue(result.TryGetContentValue <HttpError>(out err));
            Assert.IsTrue(err.Message == "Invalid flight number in booking.");
        }
コード例 #3
0
        public void CreateValidBooking()
        {
            // Arrange
            IAcmeRepository repo       = new AcmeRepository();
            var             mockLogger = new Mock <ILogger>();

            BookingsController controller = new BookingsController(repo, mockLogger.Object);

            controller.Request       = new HttpRequestMessage();
            controller.Configuration = new HttpConfiguration();

            BookingModel bm = new BookingModel
            {
                PassengerName = "James B",
                Date          = new DateTime(2018, 3, 7),
                FlightNo      = 5
            };

            // Act
            var result = controller.Post(bm);

            // Assert
            Assert.IsNotNull(result);
            BookingModel newBookingModel;

            Assert.IsTrue(result.StatusCode == System.Net.HttpStatusCode.Created);
            Assert.IsTrue(result.TryGetContentValue <BookingModel>(out newBookingModel));
            Assert.AreEqual("James B", newBookingModel.PassengerName);
            Assert.AreEqual(5, newBookingModel.FlightNo);
            Assert.AreEqual(10, newBookingModel.BookingNo);
        }
コード例 #4
0
        public void CreateNewBooking()
        {
            //Arrange
            var newBooking = new NewBookingViewModel()
            {
                FlightNumber = "BB124",
                Person       = new PersonViewModel()
                {
                    Address   = "123 street",
                    DateBirth = new DateTime(1985, 5, 5),
                    Email     = "testyahoo.com",
                    Gender    = GenderType.Male,
                    Name      = "Adam lalana"
                }
            };

            bookingServiceMock.Setup(a => a.Create(It.IsAny <string>(), It.IsAny <Person>())).Returns(new Booking()
            {
                DateBooking = DateTime.Now,
                Id          = 5200,
                Number      = "BB124"
            });
            // Act
            IHttpActionResult actionResult = objController.Post(newBooking);
            var contentResult = actionResult as OkNegotiatedContentResult <BookingViewModel>;

            // Assert
            Assert.IsNotNull(contentResult);
            Assert.IsNotNull(contentResult.Content);
            bookingServiceMock.Verify(a => a.Create(It.IsAny <string>(), It.IsAny <Person>()), Times.Once);
        }
コード例 #5
0
        public void CreateBooking_StartAndEndAreBeforeBookedPeriod_ReturnOk()
        {
            var booking = new Booking()
            {
                StartDate = DateTime.Today.AddDays(1),
                EndDate   = DateTime.Today.AddDays(3)
            };
            var result = bController.Post(booking);

            mockBookingRepository.Verify(x => x.Add(booking), Times.Once);
        }
コード例 #6
0
        public void Post()
        {
            var controller = new BookingsController(_bookingService);

            controller.Post("Test");
        }