public void GetBookingsUsingSearchWithNoResults()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "GetBookingsUsingSearchWithNoResults")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                flightContext.AddRange(
                    new Booking {
                    Id = 1, PassengerName = "Joe Bloggs", Date = new DateTime(2018, 5, 10)
                },
                    new Booking {
                    Id = 2, PassengerName = "Joe Bloggs", Date = new DateTime(2018, 4, 10)
                });
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var bookingController = new BookingController(flightContext);
                var result            = bookingController.Get("John", DateTime.MinValue, null, string.Empty, string.Empty);
                Assert.IsTrue(result is NotFoundResult);
            }
        }
        public void GetBookingsUsingSearch()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "GetBookingsUsingSearch")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                flightContext.AddRange(
                    new Booking {
                    Id = 1, PassengerName = "Joe Bloggs", Date = new DateTime(2018, 5, 10)
                },
                    new Booking {
                    Id = 2, PassengerName = "Joe Bloggs", Date = new DateTime(2018, 4, 10)
                });
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var bookingController = new BookingController(flightContext);
                var result            = bookingController.Get("Bloggs", DateTime.MinValue, null, string.Empty, string.Empty);
                Assert.IsTrue(result is ObjectResult);
                var objectResult = result as ObjectResult;
                Assert.IsTrue(objectResult.Value is IList <Booking>);
                var bookings = (objectResult.Value as IList <Booking>).ToList();
                Assert.AreEqual(2, bookings.Count);
                Assert.AreEqual(1, bookings[0].Id);
                Assert.AreEqual("Joe Bloggs", bookings[0].PassengerName);
                Assert.AreEqual(new DateTime(2018, 5, 10), bookings[0].Date);
                Assert.AreEqual(2, bookings[1].Id);
                Assert.AreEqual("Joe Bloggs", bookings[1].PassengerName);
                Assert.AreEqual(new DateTime(2018, 4, 10), bookings[1].Date);
            }
        }
        public void GetBooking()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "GetBooking")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                flightContext.AddRange(
                    new Booking {
                    Id = 1, PassengerName = "Joe Bloggs", Date = new DateTime(2018, 5, 10)
                });
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var bookingController = new BookingController(flightContext);
                var result            = bookingController.Get(1);
                Assert.IsTrue(result is ObjectResult);
                var objectResult = result as ObjectResult;
                Assert.IsTrue(objectResult.Value is Booking);
                var booking = objectResult.Value as Booking;
                Assert.AreEqual(1, booking.Id);
                Assert.AreEqual("Joe Bloggs", booking.PassengerName);
                Assert.AreEqual(new DateTime(2018, 5, 10), booking.Date);
            }
        }
        public void GetBookingInvalidId()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "GetBookingInvalidId")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                flightContext.AddRange(
                    new Booking {
                    Id = 1, PassengerName = "Joe Bloggs", Date = new DateTime(2018, 5, 10)
                });
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var bookingController = new BookingController(flightContext);
                var result            = bookingController.Get(2);
                Assert.IsTrue(result is NotFoundResult);
            }
        }