Exemplo n.º 1
0
 public IHttpActionResult GetAllFlights()
 {
     try
     {
         if (airlineCompanyFacade.GetAllFlights() == null)
         {
             return(NotFound());
         }
         return(Ok(airlineCompanyFacade.GetAllFlights()));
     }
     catch (Exception)
     {
         return(BadRequest());
     }
 }
Exemplo n.º 2
0
        public IHttpActionResult GetAllFlights()
        {
            LoginToken <AirlineCompany> token  = (LoginToken <AirlineCompany>)Request.Properties["User"];
            LoggedInAirlineFacade       facade = (LoggedInAirlineFacade)(FlyingCenterSystem.GetFlyingCenterSystem().GetFacade(token));

            return(Ok(facade.GetAllFlights(token)));
        }
Exemplo n.º 3
0
 public void NullUserTriesToGetFlightsException()
 {
     FlightCenterSystem.Instance.Login(out FacadeBase facadebase, out ILoginToken token, "adi213", "54321");
     LoginToken <AirlineCompany> loginToken = (LoginToken <AirlineCompany>)token;
     LoggedInAirlineFacade       facade     = (LoggedInAirlineFacade)facadebase;
     IList <Flight> list = facade.GetAllFlights(null);
 }
        public IHttpActionResult GetAllFlights()
        {
            GetLoginToken();

            try
            {
                IList <Flight> flights = airlineFacade.GetAllFlights(loginToken);
                if (flights.Count == 0)
                {
                    return(NotFound());
                }
                return(Ok(flights));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
Exemplo n.º 5
0
        public async Task <ActionResult <List <Flight> > > GetAllFlights()
        {
            FlightsCenterSystem.GetInstance().login(GetLoginToken().Name, GetLoginToken().Password,
                                                    out LoginToken <Object> l, out FacadeBase f);
            facade = f as LoggedInAirlineFacade;
            var result = await Task.Run(() => facade.GetAllFlights());

            return(StatusCode(200, result));
        }
Exemplo n.º 6
0
        public void GetAllFlights_Test()
        {
            FlightCenterSystem.Instance.Login(out FacadeBase facadebase, out ILoginToken token, "adi213", "54321");
            LoginToken <AirlineCompany> loginToken = (LoginToken <AirlineCompany>)token;
            LoggedInAirlineFacade       facade     = (LoggedInAirlineFacade)facadebase;
            IList <Flight> list = facade.GetAllFlights(loginToken);

            Assert.AreEqual(list.Count, 3);
        }
Exemplo n.º 7
0
        public IHttpActionResult GetAllFlights()
        {
            var loginToken = GetLoginToken();

            if (loginToken == null)
            {
                return(Unauthorized());
            }
            return(Json(_facade.GetAllFlights(loginToken)));
        }
        public IHttpActionResult GetAllFlights()
        {
            List <Flight> flights = _loggedInAirlineFacade.GetAllFlights();

            if (flights.Count == 0)
            {
                return(NotFound());
            }

            return(Ok(flights));
        }
Exemplo n.º 9
0
        public IHttpActionResult GetAllFlights()
        {
            GetLoginToken();
            if (AirLineToken != null)
            {
                List <Flight> flights = F.GetAllFlights(AirLineToken).ToList();
                return(Ok(flights));
            }

            return(NotFound());
        }
        public void GetAllFlights()
        {
            Flight expectedFlight = new Flight(1, 1, 1, new DateTime(2000, 01, 01), new DateTime(2000, 01, 01), 1);

            expectedFlight.Id = 1;
            List <Flight> list_of_flights          = (List <Flight>)airlineFacade.GetAllFlights();
            List <Flight> expected_list_of_flights = new List <Flight>();

            expected_list_of_flights.Add(expectedFlight);
            CollectionAssert.AreEqual(list_of_flights, expected_list_of_flights);
        }
Exemplo n.º 11
0
        public IHttpActionResult GetAllFlights()
        {
            LoginToken <AirlineCompany> airlineToken  = (LoginToken <AirlineCompany>)Request.Properties["airlineToken"];
            LoggedInAirlineFacade       airlineFacade = (LoggedInAirlineFacade)Request.Properties["airlineFacade"];

            IList <Flight> flights = airlineFacade.GetAllFlights(airlineToken);

            if (flights == null || flights.Count == 0)
            {
                return(NotFound());
            }
            return(Ok(flights));
        }
Exemplo n.º 12
0
        public void Create_And_Get_List_Of_New_Flight()
        {
            Execute_Test(() =>
            {
                Flight[] data         = TestData.Get_Flights_Data();
                Flight[] demi_flights = { data[0], data[1], data[2] };

                for (int i = 0; i < demi_flights.Length; i++)
                {
                    long flight_id = airline_facade.CreateFlight(airline_token, demi_flights[i]);
                    Assert.AreEqual(flight_id, i + 3);
                    demi_flights[i].Id = flight_id;
                }

                IList <Flight> flights_from_db = airline_facade.GetAllFlights();
                Assert.AreEqual(demi_flights.Length + 2, flights_from_db.Count);

                for (int i = 2; i < flights_from_db.Count; i++)
                {
                    TestData.CompareProps(flights_from_db[i], demi_flights[i - 2], true);
                }
            });
        }
Exemplo n.º 13
0
        public void TestGetAllTicketsOfAirlineAndCancelFlight()
        {
            ResetWhatIsNeeded();
            FlyingCenterSystem flyingCenterSystem = FlyingCenterSystem.GetFlyingCenterSystem();

            //sign in as a airline company
            LoginToken <AirlineCompany> companyLoginToken     = flyingCenterSystem.AttemptLoginAirlineCompany("company", "company");
            LoggedInAirlineFacade       loggedInAirlineFacade = (LoggedInAirlineFacade)flyingCenterSystem.GetFacade(companyLoginToken);

            //sign in as admin and add 2 customers
            LoginToken <Administrator>  administratorLoginToken     = flyingCenterSystem.AttemptLoginAdministrator("admin", "admin");
            LoggedInAdministratorFacade loggedInAdministratorFacade = (LoggedInAdministratorFacade)flyingCenterSystem.GetFacade(administratorLoginToken);

            loggedInAdministratorFacade.CreateNewCustomer(administratorLoginToken,
                                                          new Customer(-1, "john", "bravo", "john", "john", "places", "number", "anotherNumber"));
            loggedInAdministratorFacade.CreateNewCustomer(administratorLoginToken,
                                                          new Customer(-1, "david", "david", "david", "david", "somewhere", "longnumber", "longnumber"));

            //create 4 flights
            DateTime now = DateTime.Now;

            loggedInAirlineFacade.CreateFlight(companyLoginToken,
                                               new Flight(-1, companyLoginToken.User.ID, 1, 2,
                                                          now.AddHours(1), now.AddHours(2), 10, 10));
            loggedInAirlineFacade.CreateFlight(companyLoginToken,
                                               new Flight(-1, companyLoginToken.User.ID, 1, 2,
                                                          now.AddHours(2), now.AddHours(3), 10, 10));
            loggedInAirlineFacade.CreateFlight(companyLoginToken,
                                               new Flight(-1, companyLoginToken.User.ID, 1, 2,
                                                          now.AddHours(3), now.AddHours(4), 10, 10));
            loggedInAirlineFacade.CreateFlight(companyLoginToken,
                                               new Flight(-1, companyLoginToken.User.ID, 1, 2,
                                                          now.AddHours(4), now.AddHours(5), 10, 10));

            IList <Flight> flights = loggedInAirlineFacade.GetFlightsByDestinationCountry(2);

            //login as 2 customers
            LoginToken <Customer> customer1 = flyingCenterSystem.AttemptLoginCustomer("john", "john");
            LoginToken <Customer> customer2 = flyingCenterSystem.AttemptLoginCustomer("david", "david");

            LoggedInCustomerFacade loggedInCustomerFacade = (LoggedInCustomerFacade)flyingCenterSystem.GetFacade(customer1);

            //purchase tickets
            loggedInCustomerFacade.PurchaseTicket(customer1, flights[0]);
            loggedInCustomerFacade.PurchaseTicket(customer1, flights[1]);
            loggedInCustomerFacade.PurchaseTicket(customer1, flights[2]);
            loggedInCustomerFacade.PurchaseTicket(customer1, flights[3]);
            loggedInCustomerFacade.PurchaseTicket(customer2, flights[0]);
            loggedInCustomerFacade.PurchaseTicket(customer2, flights[1]);

            //check to see if the flights data has been updated
            Flight flight0 = loggedInCustomerFacade.GetFlightById(flights[0].ID);
            Flight flight1 = loggedInCustomerFacade.GetFlightById(flights[1].ID);
            Flight flight2 = loggedInCustomerFacade.GetFlightById(flights[2].ID);
            Flight flight3 = loggedInCustomerFacade.GetFlightById(flights[3].ID);

            Assert.AreEqual(8, flight0.RemainingTickets);
            Assert.AreEqual(8, flight1.RemainingTickets);
            Assert.AreEqual(9, flight2.RemainingTickets);
            Assert.AreEqual(9, flight3.RemainingTickets);

            //check to see if tickets table has been updated
            IList <Ticket> tickets = loggedInAirlineFacade.GetAllTickets(companyLoginToken);

            Assert.IsTrue(LookForTicket(tickets, customer1.User.ID, flight0.ID));
            Assert.IsTrue(LookForTicket(tickets, customer1.User.ID, flight1.ID));
            Assert.IsTrue(LookForTicket(tickets, customer1.User.ID, flight2.ID));
            Assert.IsTrue(LookForTicket(tickets, customer1.User.ID, flight3.ID));
            Assert.IsTrue(LookForTicket(tickets, customer2.User.ID, flight0.ID));
            Assert.IsTrue(LookForTicket(tickets, customer2.User.ID, flight1.ID));

            //remove the flights
            loggedInAirlineFacade.CancelFlight(companyLoginToken, flight0);
            loggedInAirlineFacade.CancelFlight(companyLoginToken, flight1);
            loggedInAirlineFacade.CancelFlight(companyLoginToken, flight2);
            loggedInAirlineFacade.CancelFlight(companyLoginToken, flight3);

            tickets = loggedInAirlineFacade.GetAllTickets(companyLoginToken);
            Assert.IsTrue(tickets.Count == 0);

            flights = loggedInAirlineFacade.GetAllFlights(companyLoginToken);
            Assert.IsTrue(flights.Count == 0);
        }
Exemplo n.º 14
0
 public void GetAllFlights()
 {
     facade.GetAllFlights(AirLineLogin);
 }
Exemplo n.º 15
0
        public void AirlineFacadeTest()
        {
            new TestFacade().DeleteAllTables();

            AirlineCompany testAirline = new AirlineCompany("Air One", "airone", "*****@*****.**", "555", 1);

            LoginToken <Administrator> token = new LoginToken <Administrator>()
            {
                User = new Administrator()
            };

            new LoggedInAdministratorFacade().CreateNewAirline(token, testAirline);

            testAirline.Id = new AnonymousUserFacade().GetAllAirlineCompanies()[0].Id;

            FlightCenterSystem fcs = FlightCenterSystem.GetInstance();

            LoginToken <AirlineCompany> loginToken = new LoginToken <AirlineCompany>()
            {
                User = testAirline
            };

            LoggedInAirlineFacade facade = fcs.GetFacade <AirlineCompany>(loginToken) as LoggedInAirlineFacade;

            #region Create flight

            IList <AirlineCompany> airlines = new AnonymousUserFacade().GetAllAirlineCompanies();

            Assert.ThrowsException <InvalidTokenException>(() =>
            {
                facade.CreateFlight(null, new Flight(airlines[0].Id, 1, 2, DateTime.Now, DateTime.Now.AddHours(3), 5, 99));
                // Null token, should cause an exception to be thrown
            });

            // Airline company constraints:

            Assert.ThrowsException <InvalidFlightException>(() =>
            {
                facade.CreateFlight(loginToken, new Flight(0, 1, 2, new DateTime(2011, 11, 11), new DateTime(2011, 11, 11), 5, 99));
                // Airline company Id is 0, should cause an exception to be thrown
            });

            Assert.ThrowsException <AirlineCompanyNotFoundException>(() =>
            {
                facade.CreateFlight(loginToken, new Flight(9999, 1, 2, new DateTime(2011, 11, 11), new DateTime(2011, 11, 11), 5, 99));
                // Airline company Id doesn't exist, should cause an exception to be thrown from the sql
            });

            // Origin country constraints:

            Assert.ThrowsException <InvalidFlightException>(() =>
            {
                facade.CreateFlight(loginToken, new Flight(airlines[0].Id, 0, 2, new DateTime(2011, 11, 11), new DateTime(2011, 11, 11), 5, 99));
                // Origin country Id is 0, should cause an exception to be thrown
            });

            Assert.ThrowsException <CountryNotFoundException>(() =>
            {
                facade.CreateFlight(loginToken, new Flight(airlines[0].Id, 9999, 2, new DateTime(2011, 11, 11), new DateTime(2011, 11, 11), 5, 99));
                // Origin country Id doesn't exist, should cause an exception to be thrown from the sql
            });

            // Destination country constraints:

            Assert.ThrowsException <InvalidFlightException>(() =>
            {
                facade.CreateFlight(loginToken, new Flight(airlines[0].Id, 1, 0, new DateTime(2011, 11, 11), new DateTime(2011, 11, 11), 5, 99));
                // Destination country Id is 0, should cause an exception to be thrown
            });

            Assert.ThrowsException <CountryNotFoundException>(() =>
            {
                facade.CreateFlight(loginToken, new Flight(airlines[0].Id, 1, 9999, new DateTime(2011, 11, 11), new DateTime(2011, 11, 11), 5, 99));
                // Destination country Id doesn't exist, should cause an exception to be thrown from the sql
            });

            // Flight time constraints:

            Assert.ThrowsException <InvalidFlightException>(() =>
            {
                facade.CreateFlight(loginToken, new Flight(airlines[0].Id, 1, 2, new DateTime(), new DateTime(2011, 11, 11), 5, 99));
                // No departure time, should cause an exception to be thrown
            });

            Assert.ThrowsException <InvalidFlightException>(() =>
            {
                facade.CreateFlight(loginToken, new Flight(airlines[0].Id, 1, 2, new DateTime(2011, 11, 11), new DateTime(), 5, 99));
                // No landing time, should cause an exception to be thrown
            });

            int yearNow  = DateTime.Now.Year;
            int monthNow = DateTime.Now.Month;
            int dayNow   = DateTime.Now.Day;

            facade.CreateFlight(loginToken, new Flight(airlines[0].Id, 1, 2, new DateTime(2012, 12, 12), new DateTime(2012, 12, 12), 5, 120));
            IList <Flight> flights = facade.GetAllFlights();

            Assert.AreEqual(flights[0].AirlineCompanyId, airlines[0].Id);
            Assert.AreEqual(flights[0].OriginCountryCode, 1);
            Assert.AreEqual(flights[0].DestinationCountryCode, 2);
            Assert.AreEqual(flights[0].DepartureTime, new DateTime(2012, 12, 12));
            Assert.AreEqual(flights[0].LandingTime, new DateTime(2012, 12, 12));
            Assert.AreEqual(flights[0].RemainingTickets, 5);
            Assert.AreEqual(flights[0].TicketPrice, 120);

            #endregion

            #region Update flight

            Assert.ThrowsException <InvalidTokenException>(() =>
            {
                facade.UpdateFlight(null, new Flight(airlines[0].Id, 3, 4, new DateTime(yearNow, monthNow, dayNow), new DateTime(yearNow, monthNow, dayNow), 10, 99));
                // Null token, should cause an exception to be thrown
            });

            flights = facade.GetAllFlights();
            facade.UpdateFlight(loginToken, new Flight(airlines[0].Id, 2, 3, new DateTime(yearNow, monthNow, dayNow), new DateTime(yearNow, monthNow, dayNow), 10, 99)
            {
                Id = flights[0].Id
            });

            flights = facade.GetAllFlights();

            Assert.AreEqual(flights[0].AirlineCompanyId, airlines[0].Id);
            Assert.AreEqual(flights[0].OriginCountryCode, 2);
            Assert.AreEqual(flights[0].DestinationCountryCode, 3);
            Assert.AreEqual(flights[0].DepartureTime, new DateTime(yearNow, monthNow, dayNow));
            Assert.AreEqual(flights[0].LandingTime, new DateTime(yearNow, monthNow, dayNow));
            Assert.AreEqual(flights[0].RemainingTickets, 10);
            Assert.AreEqual(flights[0].TicketPrice, 99);

            #endregion

            #region Change my password

            Assert.ThrowsException <InvalidTokenException>(() =>
            {
                facade.ChangeMyPassword(null, "555", "666");
                // Null token, should cause an exception to be thrown
            });

            Assert.ThrowsException <WrongPasswordException>(() =>
            {
                facade.ChangeMyPassword(loginToken, "444", "666");
                // wrong password, should cause an exception to be thrown
            });

            facade.ChangeMyPassword(loginToken, "555", "666");

            airlines = facade.GetAllAirlineCompanies();

            Assert.AreEqual(airlines[0].Password, "666");

            #endregion

            #region Modify airline details

            Assert.ThrowsException <InvalidTokenException>(() =>
            {
                facade.ModifyAirlineDetails(null, testAirline);
                // Null token, should cause an exception to be thrown
            });

            testAirline.Name = "Best Pilots";

            facade.ModifyAirlineDetails(loginToken, testAirline);
            airlines = facade.GetAllAirlineCompanies();

            Assert.AreEqual(airlines[0].Name, "Best Pilots");

            #endregion

            #region Get all my flights

            Assert.ThrowsException <InvalidTokenException>(() =>
            {
                facade.CreateFlight(null, new Flight(airlines[0].Id, 3, 4, new DateTime(2009, 9, 9), new DateTime(2009, 9, 9), 10, 99));
                // Null token, should cause an exception to be thrown
            });

            facade.CreateFlight(loginToken, new Flight(airlines[0].Id, 3, 4, new DateTime(yearNow, monthNow, dayNow), new DateTime(yearNow, monthNow, dayNow), 10, 99));

            flights = facade.GetAllMyFlights(loginToken);

            Assert.AreEqual(flights[0].AirlineCompanyId, airlines[0].Id);
            Assert.AreEqual(flights[0].OriginCountryCode, 2);
            Assert.AreEqual(flights[0].DestinationCountryCode, 3);
            Assert.AreEqual(flights[0].DepartureTime, new DateTime(yearNow, monthNow, dayNow));
            Assert.AreEqual(flights[0].LandingTime, new DateTime(yearNow, monthNow, dayNow));
            Assert.AreEqual(flights[0].RemainingTickets, 10);
            Assert.AreEqual(flights[0].TicketPrice, 99);

            Assert.AreEqual(flights[1].AirlineCompanyId, airlines[0].Id);
            Assert.AreEqual(flights[1].OriginCountryCode, 3);
            Assert.AreEqual(flights[1].DestinationCountryCode, 4);
            Assert.AreEqual(flights[1].DepartureTime, new DateTime(yearNow, monthNow, dayNow));
            Assert.AreEqual(flights[1].LandingTime, new DateTime(yearNow, monthNow, dayNow));
            Assert.AreEqual(flights[1].RemainingTickets, 10);
            Assert.AreEqual(flights[1].TicketPrice, 99);

            #endregion
        }