Esempio n. 1
0
        public void AvailableFlightsWithToManyPassengersDueToBookings()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "AvailableFlightsWithToManyPassengersDueToBookings")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                var flight = new Flight {
                    Number = 1, Capacity = 1
                };
                flightContext.Add(flight);
                flightContext.Add(new Booking {
                    Date = new DateTime(2018, 5, 11), FlightNumber = 1, Flight = flight
                });
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var search  = new Search(flightContext);
                var results = search.GetAvailableFlights(new DateTime(2018, 5, 10), new DateTime(2018, 5, 12), 1);
                Assert.AreEqual(2, results.Count);
                Assert.AreEqual(new DateTime(2018, 5, 10), results[0].Date);
                Assert.AreEqual(1, results[0].Flight.Number);
                Assert.AreEqual(1, results[0].RemainingCapacity);
                Assert.AreEqual(new DateTime(2018, 5, 12), results[1].Date);
                Assert.AreEqual(1, results[1].Flight.Number);
                Assert.AreEqual(1, results[1].RemainingCapacity);
            }
        }
        public void GetAvailableFlightWithStartAndEndDate()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "GetAvailableFlightWithEndDate")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                flightContext.Add(new Flight {
                    Number = 1, Capacity = 1
                });
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var flightController = new FlightController(flightContext);
                var result           = flightController.Get(new DateTime(2018, 5, 10), new DateTime(2018, 5, 10), null);
                Assert.IsTrue(result is ObjectResult);
                var objectResult = result as ObjectResult;
                Assert.IsTrue(objectResult.Value is IList <AvailableFlight>);
                var flights = (objectResult.Value as IList <AvailableFlight>).ToList();
                Assert.AreEqual(1, flights.Count);
                Assert.AreEqual(new DateTime(2018, 5, 10), flights[0].Date);
                Assert.AreEqual(1, flights[0].RemainingCapacity);
                Assert.AreEqual(1, flights[0].Flight.Number);
            }
        }
        public void CreateBookingWithInvalidFlight()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "CreateBookingWithInvalidFlight")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                flightContext.Add(new Flight {
                    Number = 1, Capacity = 1
                });
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var bookingController = new BookingController(flightContext);
                var result            = bookingController.Create(new Booking
                {
                    PassengerName = "Joe Bloggs",
                    Date          = new DateTime(2018, 5, 10),
                    FlightNumber  = 2
                });
                Assert.IsTrue(result is BadRequestResult);
            }
        }
Esempio n. 4
0
        public void AvailableFlightsWithStartAndEndDate()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "AvailableFlightsWithStartAndEndDate")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                flightContext.Add(new Flight {
                    Number = 1, Capacity = 1
                });
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var search  = new Search(flightContext);
                var results = search.GetAvailableFlights(new DateTime(2018, 5, 10), new DateTime(2018, 5, 12), null);
                Assert.AreEqual(3, results.Count);
                Assert.AreEqual(new DateTime(2018, 5, 10), results[0].Date);
                Assert.AreEqual(1, results[0].Flight.Number);
                Assert.AreEqual(1, results[0].RemainingCapacity);
                Assert.AreEqual(new DateTime(2018, 5, 11), results[1].Date);
                Assert.AreEqual(1, results[1].Flight.Number);
                Assert.AreEqual(1, results[1].RemainingCapacity);
                Assert.AreEqual(new DateTime(2018, 5, 12), results[2].Date);
                Assert.AreEqual(1, results[2].Flight.Number);
                Assert.AreEqual(1, results[2].RemainingCapacity);
            }
        }
        public void GetFlight()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "GetFlight")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                flightContext.Add(new Flight {
                    Number = 1, Capacity = 1
                });
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var flightController = new FlightController(flightContext);
                var result           = flightController.Get(1);
                Assert.IsTrue(result is ObjectResult);
                var objectResult = result as ObjectResult;
                Assert.IsTrue(objectResult.Value is Flight);
                var flight = objectResult.Value as Flight;
                Assert.AreEqual(1, flight.Number);
                Assert.AreEqual(1, flight.Capacity);
            }
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Surname,Lastname,IdentifiactionalNumber,PhoneNumber,Email")] Reservations reservations)
        {
            if (ModelState.IsValid)
            {
                _context.Add(reservations);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(reservations));
        }
        public async Task <IActionResult> Create([Bind("PlaneId,LocationFrom,LocationTo,DepartTime,ArrivalTime,PlaneType,PilotName,PlaneCapacityNormal,PlaneCapacityBusiness,AlreadyReserved")] Flights flights)
        {
            if (ModelState.IsValid)
            {
                _context.Add(flights);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(flights));
        }
Esempio n. 8
0
        public async Task <IActionResult> Create([Bind("RouteId,DepartureLocation,DestinationLocation")] Route route)
        {
            if (ModelState.IsValid)
            {
                route.RouteId = Guid.NewGuid();
                _context.Add(route);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(route));
        }
Esempio n. 9
0
        public async Task <IActionResult> Create([Bind("StopId,StopLocation")] Stop stop)
        {
            if (ModelState.IsValid)
            {
                stop.StopId = Guid.NewGuid();
                _context.Add(stop);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(stop));
        }
        public async Task <IActionResult> Create([Bind("LineId,Name")] Line line)
        {
            if (ModelState.IsValid)
            {
                line.LineId = Guid.NewGuid();
                _context.Add(line);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(line));
        }
Esempio n. 11
0
        public async Task <IActionResult> Create([Bind("CardId,ClientId,ExpirationDate,Number,CVC")] Card card)
        {
            if (ModelState.IsValid)
            {
                card.CardId = Guid.NewGuid();
                _context.Add(card);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ClientId"] = new SelectList(_context.Clients, "Id", "Id", card.ClientId);
            return(View(card));
        }
Esempio n. 12
0
        public async Task <IActionResult> Create([Bind("PlaneId,Model,Manufacturer,LineId")] Plane plane)
        {
            if (ModelState.IsValid)
            {
                plane.PlaneId = Guid.NewGuid();
                _context.Add(plane);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["LineId"] = new SelectList(_context.Lines, "LineId", "LineId", plane.LineId);
            return(View(plane));
        }
        public async Task <IActionResult> Create([Bind("FlightId,PlaneId,RouteId,DepartureDate,DepartureHour,DestinationHour")] Flight flight)
        {
            if (ModelState.IsValid)
            {
                flight.FlightId = Guid.NewGuid();
                _context.Add(flight);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PlaneId"] = new SelectList(_context.Planes, "PlaneId", "PlaneId", flight.PlaneId);
            ViewData["RouteId"] = new SelectList(_context.Routes, "RouteId", "RouteId", flight.RouteId);
            return(View(flight));
        }
Esempio n. 14
0
        public async Task <IActionResult> Create([Bind("BookingId,ClientId,RouteId,PaymentDate,PaymentMethod,FlightClass,BookingDate")] Booking booking)
        {
            if (ModelState.IsValid)
            {
                booking.BookingId = Guid.NewGuid();
                _context.Add(booking);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ClientId"] = new SelectList(_context.Clients, "Id", "Id", booking.ClientId);
            ViewData["RouteId"]  = new SelectList(_context.Routes, "RouteId", "RouteId", booking.RouteId);
            return(View(booking));
        }
Esempio n. 15
0
        public async Task <IActionResult> Create([Bind("Route_StopId,StopId,RouteId,StopTime")] Route_Stop route_Stop)
        {
            if (ModelState.IsValid)
            {
                route_Stop.Route_StopId = Guid.NewGuid();
                _context.Add(route_Stop);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["RouteId"] = new SelectList(_context.Routes, "RouteId", "RouteId", route_Stop.RouteId);
            ViewData["StopId"]  = new SelectList(_context.Stops, "StopId", "StopId", route_Stop.StopId);
            return(View(route_Stop));
        }
Esempio n. 16
0
        public void AvailableFlightsWithToManyPassengers()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "AvailableFlightsWithToManyPassengers")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                flightContext.Add(new Flight {
                    Number = 1, Capacity = 1
                });
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var search  = new Search(flightContext);
                var results = search.GetAvailableFlights(new DateTime(2018, 5, 10), new DateTime(2018, 5, 12), 2);
                Assert.AreEqual(0, results.Count);
            }
        }
Esempio n. 17
0
        public void GetInvalidFlight()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "GetInvalidFlight")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                flightContext.Add(new Flight {
                    Number = 1, Capacity = 1
                });
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var flightController = new FlightController(flightContext);
                var result           = flightController.Get(2);
                Assert.IsTrue(result is NotFoundResult);
            }
        }
        public void CreateBooking()
        {
            var options = new DbContextOptionsBuilder <FlightsContext>()
                          .UseInMemoryDatabase(databaseName: "CreateBooking")
                          .Options;

            using (var flightContext = new FlightsContext(options))
            {
                var flight = new Flight {
                    Number = 1, Capacity = 1
                };
                flightContext.Add(flight);
                flightContext.SaveChanges();
            }

            using (var flightContext = new FlightsContext(options))
            {
                var bookingController = new BookingController(flightContext);
                var result            = bookingController.Create(new Booking
                {
                    PassengerName = "Joe Bloggs",
                    Date          = new DateTime(2018, 5, 10),
                    FlightNumber  = 1
                });
                Assert.IsTrue(result is CreatedAtRouteResult);
                var objectResult = result as CreatedAtRouteResult;
                Assert.IsTrue(objectResult.Value is Booking);
                var bookings = objectResult.Value as Booking;
                Assert.AreEqual(1, bookings.Id);
                Assert.AreEqual("Joe Bloggs", bookings.PassengerName);
                Assert.AreEqual(new DateTime(2018, 5, 10), bookings.Date);
                Assert.AreEqual(1, flightContext.Bookings.Count());
                Assert.AreEqual(1, flightContext.Bookings.First().Id);
                Assert.AreEqual("Joe Bloggs", flightContext.Bookings.First().PassengerName);
                Assert.AreEqual(new DateTime(2018, 5, 10), flightContext.Bookings.First().Date);
            }
        }