public void Flight_AddNew()
        {
            FlightRepository repository = new FlightRepository(dbConnectionString);
            var flightList = repository.GetAll();
            var prevCount  = flightList.ToList().Count;

            var rndNo = new Random().Next(10, 999);

            Flight flight = new Flight
            {
                Number            = "FL" + rndNo.ToString(),
                Name              = "Test Flight Name",
                DepartureCity     = "Craigieburn",
                DepartureTime     = DateTime.Now,
                ArrivalCity       = "Melbourne",
                ArrivalTime       = DateTime.Now.AddHours(4),
                PassengerCapacity = 20
            };

            var result = repository.Add(flight);

            flightList = repository.GetAll();
            var afterCount = flightList.ToList().Count;

            Assert.AreEqual(1, result);
            Assert.IsTrue(prevCount > 0);
            Assert.IsTrue(afterCount > 0);
            Assert.IsTrue(afterCount > prevCount);
        }
        public void DepartureBiggerThanArrivalPutTest()
        {
            Flight testflight = new Flight();

            Location loc_departure = new Location();
            Location loc_arrival   = new Location();
            Airplane airplane      = new Airplane();

            loc_departure.Id = 1;
            loc_arrival.Id   = 2;
            airplane.Id      = 1;

            testflight.plane         = airplane;
            testflight.price         = 100;
            testflight.departure     = "12-11-2020 01:00:00";
            testflight.arrival       = "12-11-2020 02:00:00";
            testflight.loc_departure = loc_departure;
            testflight.loc_arrival   = loc_arrival;

            int id = FlightRepository.Add(testflight);

            testflight.departure = "12-13-2020 01:00:00";
            testflight.arrival   = "12-12-2020 02:00:00";
            testflight.Id        = id;

            var result = controller.Put(testflight);

            Assert.IsInstanceOf <BadRequestObjectResult>(result.Result);
        }
        public void DeleteTest()
        {
            Flight testflight = new Flight();

            Location loc_departure = new Location();
            Location loc_arrival   = new Location();
            Airplane airplane      = new Airplane();

            loc_departure.Id = 1;
            loc_arrival.Id   = 2;
            airplane.Id      = 1;

            testflight.plane         = airplane;
            testflight.price         = 100;
            testflight.departure     = "12-11-2020";
            testflight.arrival       = "12-21-2020";
            testflight.loc_departure = loc_departure;
            testflight.loc_arrival   = loc_arrival;

            int id = FlightRepository.Add(testflight);

            var result = controller.Delete(id);

            Assert.IsInstanceOf <OkObjectResult>(result.Result);
        }
        public void Should_save_flight()
        {
            var flight     = new FlightTestBuilder().Build();
            var repository = new FlightRepository(this.DbContext);

            repository.Add(flight);
            ClearChangeTracker();

            var actualFlight = repository.GetById(flight.Id);

            actualFlight.Should().BeEquivalentTo(flight);
        }
Exemple #5
0
        public void InsertFlight()
        {
            FlightRepository   flightRepository;
            LocationRepository locationRepository;
            Location           from, to;

            string   flightNumber = "BY999";
            DateTime takeOff      = new DateTime(2014, 2, 1, 8, 30, 0); // Feb. 1st 2014, 8:30am

            using (locationRepository = new LocationRepository())
            {
                from = locationRepository.FindBy(l => l.City == "Paris").Single();
                to   = locationRepository.FindBy(l => l.City == "New-York").Single();
            }

            using (flightRepository = new FlightRepository())
            {
                Flight newFlight = new Flight();
                newFlight.FlightNumber = flightNumber;
                newFlight.Destination  = to;
                newFlight.Source       = from;
                newFlight.Schedules    = new List <FlightSchedule> {
                    new FlightSchedule
                    {
                        Departure = takeOff,
                        Duration  = new TimeSpan(2, 30, 0)
                    }
                };

                flightRepository.Add(newFlight);
                flightRepository.Save();
            }

            using (flightRepository = new FlightRepository())
            {
                Flight newFlight = flightRepository.GetFlight(flightNumber);
                Assert.AreEqual(newFlight.FlightNumber, flightNumber);
                Assert.AreEqual(newFlight.Destination.City, "New-York");
                Assert.AreEqual(newFlight.Source.City, "Paris");
                Assert.AreEqual(newFlight.Schedules.First().Departure, takeOff);
                Assert.AreEqual(newFlight.Schedules.First().Duration.TotalMinutes, 150);
            }
        }
        public ActionResult Save(FlightFormViewModel flightFormViewModel)
        {
            if (!ModelState.IsValid)
            {
                var lightFlightPaths = InitializeFlightPaths();
                var lightStarships   = InitializeStarships();

                var viewModel = new ContainerFlightFormViewModel(flightFormViewModel, lightFlightPaths, lightStarships);
                return(View("FlightForm", viewModel));
            }

            Flight flightToDB;

            if (flightFormViewModel.FlightId == 0)
            {
                var starship = starshipRepository.GetSingleStarship(flightFormViewModel.StarshipId);
                flightToDB = new Flight(flightFormViewModel.GetDateTime(), flightFormViewModel.BasePrice, flightFormViewModel.FlightPathId, starship, flightFormViewModel.IsVIP);

                flightRepository.Add(flightToDB);
            }
            else
            {
                flightToDB = flightRepository.GetSingleFlight(flightFormViewModel.FlightId);

                if (flightToDB == null)
                {
                    return(HttpNotFound());
                }

                var starship = starshipRepository.GetSingleStarship(flightFormViewModel.StarshipId);
                flightToDB.Update(flightFormViewModel.GetDateTime(), flightFormViewModel.BasePrice, null, starship, null);
            }

            unitOfWork.Complete();

            InformViewsForCreateOrEdit(flightToDB, flightFormViewModel.FlightId);

            return(RedirectToAction("Index", "Flight"));
        }
        public IActionResult Add(FlightViewModel model, string returnUrtl = null)
        {
            var flight = new FlightModel {
                Id                   = model.Id,
                AirplaneId           = model.AirplaneId,
                AviaCompanyId        = model.AviaCompanyId,
                HomeAirportId        = model.HomeAirportId,
                DestinationAirportId = model.DestinationAirportId,
                Departure            = model.Departure,
                Arrival              = model.Arrival
            };
            var curFlights = _flights.GetAll().ToList().OrderByDescending(item => item.Id);

            if (curFlights.Count() == 0)
            {
                flight.Id = 1;
            }
            else
            {
                flight.Id = curFlights.First().Id + 1;
            }
            _flights.Add(flight);
            return(RedirectToAction("Index"));
        }
Exemple #8
0
 public void AddFlightTest()
 {
     id = FlightRepository.Add(testflight);
     Assert.True(id > 0);
 }
Exemple #9
0
 // Flight Methods
 /// <summary>
 /// Will add a flight
 /// </summary>
 /// <param name="flight"></param>
 public static void AddFlight(Flight flight)
 {
     _flightRepository.Add(flight);
 }
Exemple #10
0
 public ActionResult Create(Flight flight)
 {
     Repository.Add(flight);
     return(RedirectToAction("Index", "Flight"));
 }