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); }
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."); }
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); }
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); }
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); }
public void Post() { var controller = new BookingsController(_bookingService); controller.Post("Test"); }