Example #1
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 LoggedInAdministratorFacade;
            var result = await Task.Run(() => facade.GetAllFlights());

            return(StatusCode(200, result));
        }
        private void GenerateTickets(LoggedInAdministratorFacade facade, LoginToken <Administrator> loginToken,
                                     FlyingCenterSystem flyingCenterSystem)
        {
            Random          r         = new Random();
            List <Customer> customers = (List <Customer>)facade._customerDAO.GetAll();
            List <Flight>   Flights   = (List <Flight>)facade.GetAllFlights();

            foreach (Customer customer in customers)
            {
                //login as the customer to get access to the PurchaseTicket method
                LoginToken <Customer>  customerLoginToken = flyingCenterSystem.AttemptLoginCustomer(customer.Username, customer.Password);
                LoggedInCustomerFacade customerFacade     = (LoggedInCustomerFacade)FlyingCenterSystem.GetFlyingCenterSystem().GetFacade(customerLoginToken);

                for (int i = 0; i < TicketsPerCustomerAmount; i++)
                {
                    /*in large amounts random might choose many flights that the customer already bought ticket to
                     * therefore i am limiting the amount of times a random chooses this kind of flight to 3 and from there on
                     * im moving to a for loop on all flights*/
                    int isNullCounter = 0;
                    while (isNullCounter < 3)
                    {
                        if (customerFacade.PurchaseTicket(customerLoginToken, Flights[r.Next(0, Flights.Count)]) == null)
                        {
                            isNullCounter++;
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (isNullCounter == 3)
                    {
                        for (int j = 0; j < Flights.Count; i++)
                        {
                            if (customerFacade.PurchaseTicket(customerLoginToken, Flights[r.Next(0, Flights.Count)]) != null)
                            {
                                break;
                            }
                        }
                    }
                }
            }
        }
        public void Remove_Airline_Company_With_Flight_And_Ticket()
        {
            Execute_Test(() =>
            {
                int country_id  = administrator_facade.CreateNewCountry(administrator_token, TestData.Get_Countries_Data()[0]);
                int country_id2 = administrator_facade.CreateNewCountry(administrator_token, TestData.Get_Countries_Data()[1]);
                int country_id3 = administrator_facade.CreateNewCountry(administrator_token, TestData.Get_Countries_Data()[2]);

                AirlineCompany demi_airline_company = TestData.Get_AirlineCompanies_Data()[0];
                demi_airline_company.CountryId      = country_id;
                long airline_company_id             = administrator_facade.CreateNewAirlineCompany(administrator_token, demi_airline_company);
                demi_airline_company.Id             = airline_company_id;

                system.TryLogin(demi_airline_company.User.UserName, demi_airline_company.User.Password, out ILoginToken token, out FacadeBase facade);
                LoggedInAirlineFacade airlineFacade      = facade as LoggedInAirlineFacade;
                LoginToken <AirlineCompany> airlineToken = token as LoginToken <AirlineCompany>;

                Flight demi_flight = TestData.Get_Flights_Data()[0];
                long flight_id     = airlineFacade.CreateFlight(airlineToken, demi_flight);
                demi_flight.Id     = flight_id;

                Customer demi_customer = TestData.Get_Customers_Data()[0];
                demi_customer.Id       = administrator_facade.CreateNewCustomer(administrator_token, demi_customer);

                system.TryLogin(demi_customer.User.UserName, demi_customer.User.Password, out ILoginToken token2, out FacadeBase facade2);
                LoggedInCustomerFacade customerFacade = facade2 as LoggedInCustomerFacade;
                LoginToken <Customer> customerToken   = token2 as LoginToken <Customer>;

                Ticket ticket = customerFacade.PurchaseTicket(customerToken, demi_flight);

                administrator_facade.RemoveAirline(administrator_token, demi_airline_company);

                Assert.AreEqual(administrator_facade.GetAllAirlineCompanies().Count, 0);
                Assert.AreEqual(administrator_facade.GetAllFlights().Count, 0);
                Assert.AreEqual(airlineFacade.GetAllTickets(airlineToken).Count, 0);
                Assert.AreEqual(airlineFacade.GetFlightHistoryByOriginalId(airlineToken, demi_flight.Id).Id, 1);
                Assert.AreEqual(customerFacade.GetTicketHistoryByOriginalId(customerToken, ticket.Id).Id, 1);
            });
        }
Example #4
0
        public void GenerateData()
        {
            log.Info("Creating admin user");
            MainWindowViewModel.ListForLog.Add("Creating admin user");
            //Creating admin user:
            IloginAdministrator     = FlyingCenterSystem.GetFlyingCenterSystemInstance().Login("admin", "9999");
            loginTokenAdministrator = IloginAdministrator as LoginToken <Administrator>;
            administratorFacade     = (LoggedInAdministratorFacade)FlyingCenterSystem.GetFlyingCenterSystemInstance().GetFacade(IloginAdministrator);

            //Adds the countries first (foreign key constrain considaration):
            log.Info("Adds the countries first");
            MainWindowViewModel.ListForLog.Add("Adds the countries first");
            for (int i = 0; i < _CountriesNoToAdd; i++)
            {
                administratorFacade.CreateNewCountry(loginTokenAdministrator,
                                                     new Country()
                {
                    CountryName = listOfThings.CountriesArray[rnd.Next(listOfThings.CountriesArray.Length)]
                });
                if (i >= listOfThings.CountriesArray.Length)
                {
                    administratorFacade.CreateNewCountry(loginTokenAdministrator,
                                                         new Country()
                    {
                        CountryName = RandomString(5)
                    });
                }
            }

            //Get All Countries and add country codes for filling the airline companies:
            log.Info("Adds the Airline Companies");
            MainWindowViewModel.ListForLog.Add("Adds the Airline Companies");
            IList <Country> countries = new List <Country>();

            countries = administratorFacade.GetAllCountries(loginTokenAdministrator);

            //Adds the Airline Companies:
            for (int i = 0; i < _AirlineCompaniesNo; i++)
            {
                administratorFacade.CreateNewAirline(loginTokenAdministrator, new AirlineCompany()
                {
                    AirLineName = RandomString(5),
                    CountryCode = countries[rnd.Next(0, countries.Count)].CountyID,
                    Password    = RandomString(6),
                    UserName    = RandomString(4)
                });
            }

            //Adds the Customers:
            log.Info("Adds the Customers");
            MainWindowViewModel.ListForLog.Add("Adds the Customers");
            //FillCustomerTableFromUserApi(CustomersNo); - will not use, site is down (although it's working)
            FillCustomerTableRandomly(rnd, _CustomersNo);

            //Get All AirlineCompanies for the id:
            IList <AirlineCompany> airlineCompanies = administratorFacade.GetAllAirLineCompanies();

            //Adds the Flights Per Company:
            log.Info("Adds the Flights Per Company");
            MainWindowViewModel.ListForLog.Add("Adds the Flights Per Company");
            for (int i = 0; i < _FlightsPerCompany; i++)
            {
                administratorFacade.CreateFlight(loginTokenAdministrator, new Flight()
                {
                    AirLineCompany_ID        = airlineCompanies[rnd.Next(0, airlineCompanies.Count)].Airline_ID,
                    Origin_Country_Code      = countries[rnd.Next(0, countries.Count)].CountyID,
                    Destination_Country_Code = countries[rnd.Next(0, countries.Count)].CountyID,
                    DepartureTime            = createRandomDate(),
                    LandingTime       = createRandomDate(),
                    Remaining_Tickets = rnd.Next(5, 51)
                });
            }

            log.Info("Adds the Tickets per Customer");
            MainWindowViewModel.ListForLog.Add("Adds the Tickets per Customer");
            //Get All customers:
            IList <Customer> customers = new List <Customer>();

            customers = administratorFacade.GetAllCustomers(loginTokenAdministrator);

            //Get All flights :
            IList <Flight> flights = new List <Flight>();

            flights = administratorFacade.GetAllFlights();

            //Adds the Tickets per Customer:
            for (int i = 0; i < _TicketsPerCustomer; i++)
            {
                administratorFacade.AddTicketsToCustomer(loginTokenAdministrator,
                                                         customers[rnd.Next(0, customers.Count)].Customer_ID,
                                                         flights[rnd.Next(0, flights.Count)].FlightID);
            }

            log.Info("Finished puting data in DB!");
            MainWindowViewModel.ListForLog.Add("Finished puting data in DB!");
        }