Example #1
0
        public async Task <ActionResult <List <Flight> > > GetFlightsByDestinationCountry(int country_id)
        {
            FlightsCenterSystem.GetInstance().login(GetLoginToken().Name, GetLoginToken().Password,
                                                    out LoginToken <Object> l, out FacadeBase f);
            facade = f as LoggedInAirlineFacade;
            var result = await Task.Run(() => facade.GetFlightsByDestinationCountry(country_id));

            return(StatusCode(200, result));
        }
Example #2
0
        public void TestCustomerFacade()
        {
            ResetWhatIsNeeded();
            FlyingCenterSystem flyingCenterSystem = FlyingCenterSystem.GetFlyingCenterSystem();

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

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

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

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

            //login as the customer
            LoginToken <Customer>  customer = flyingCenterSystem.AttemptLoginCustomer("customer", "customer");
            LoggedInCustomerFacade loggedInCustomerFacade = (LoggedInCustomerFacade)flyingCenterSystem.GetFacade(customer);

            //buy a ticket for 4 flights
            loggedInCustomerFacade.PurchaseTicket(customer, flights[0]);
            loggedInCustomerFacade.PurchaseTicket(customer, flights[1]);
            loggedInCustomerFacade.PurchaseTicket(customer, flights[2]);
            loggedInCustomerFacade.PurchaseTicket(customer, flights[3]);

            TicketDAOMSSQL _ticketDAO = new TicketDAOMSSQL();
            IList <Ticket> tickets    = _ticketDAO.GetAll();

            Assert.IsTrue(LookForTicket(tickets, customer.User.ID, flights[0].ID));
            Assert.IsTrue(LookForTicket(tickets, customer.User.ID, flights[1].ID));
            Assert.IsTrue(LookForTicket(tickets, customer.User.ID, flights[2].ID));
            Assert.IsTrue(LookForTicket(tickets, customer.User.ID, flights[3].ID));

            Assert.AreEqual(4, loggedInCustomerFacade.GetAllMyFlights(customer).Count);

            loggedInCustomerFacade.CancelTicket(customer, tickets[0]);
            loggedInCustomerFacade.CancelTicket(customer, tickets[1]);
            loggedInCustomerFacade.CancelTicket(customer, tickets[2]);
            loggedInCustomerFacade.CancelTicket(customer, tickets[3]);

            tickets = _ticketDAO.GetAll();
            Assert.IsTrue(tickets.Count == 0);

            flights = loggedInAirlineFacade.GetFlightsByDestinationCountry(3);

            Assert.IsTrue(flights[0].RemainingTickets == 10);
            Assert.IsTrue(flights[1].RemainingTickets == 10);
            Assert.IsTrue(flights[2].RemainingTickets == 10);
            Assert.IsTrue(flights[3].RemainingTickets == 10);
        }
Example #3
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);
        }