Example #1
0
        // Create a random amount of airlines
        public void CreateRandomAirlineCompanies(int numberOfAirlines)
        {
            Country               randomCountry = new Country();
            IList <Country>       dbCountries   = adminF.GetAllCountries(adminT);
            List <AirLineCompany> airlines      = new List <AirLineCompany>();
            Random random = new Random();

            for (int i = 0; i < numberOfAirlines; i++)
            {
                randomCountry = dbCountries[random.Next(0, dbCountries.Count)];
                AirLineCompany c = new AirLineCompany
                {
                    AirLineName = RandomString(true),
                    UserName    = RandomString(true),
                    Password    = RandomPassword(),
                    CountryCode = randomCountry.ID,
                };
                foreach (AirLineCompany airLine in airlines)
                {
                    if (airLine.UserName == c.UserName || airLine.Password == c.Password || adminF.GetAirlineUserName(adminT, c.UserName) == c.UserName)
                    {
                        i--;
                    }
                }
                airlines.Add(c);
                adminF.CreateNewAirline(adminT, c);
            }
        }
        public void Create_And_Get_List_Of_New_Countries()
        {
            Execute_Test(() =>
            {
                Country[] data           = TestData.Get_Countries_Data();
                Country[] demi_countries = { data[0], data[1], data[2], data[3], data[4] };
                for (int i = 0; i < demi_countries.Length; i++)
                {
                    int country_id = administrator_facade.CreateNewCountry(administrator_token, demi_countries[i]);
                    Assert.AreEqual(country_id, i + 1);
                    demi_countries[i].Id = country_id;
                }

                IList <Country> countries_from_db = administrator_facade.GetAllCountries();
                Assert.AreEqual(demi_countries.Length, countries_from_db.Count);
                for (int i = 0; i < countries_from_db.Count; i++)
                {
                    TestData.CompareProps(countries_from_db[i], demi_countries[i]);
                }
            });
        }
        private void GenerateAirlineCompanies(LoggedInAdministratorFacade facade, LoginToken <Administrator> loginToken)
        {
            List <AirlineCompany> airlineCompanies = new List <AirlineCompany>();
            List <Country>        countries        = (List <Country>)facade.GetAllCountries(loginToken);

            Converters.ConvertToAirlineCompany(RandomUsers, airlineCompanies, countries, AirlineCompaniesAmount);
            for (int i = 0; i < airlineCompanies.Count; i++)
            {
                try
                {
                    facade.CreateNewAirline(loginToken, airlineCompanies[i]);
                }
                catch (Exception e)
                {
                    MessageBox.Show($"Username {airlineCompanies[i].Username} already exists", "Generator Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
        private void GenerateFlights(LoggedInAdministratorFacade facade, LoginToken <Administrator> loginToken,
                                     FlyingCenterSystem flyingCenterSystem)
        {
            Random r = new Random();
            List <AirlineCompany> airlineCompanies = (List <AirlineCompany>)facade.GetAllAirlineCompanies();
            List <Country>        countries        = (List <Country>)facade.GetAllCountries(loginToken);

            foreach (AirlineCompany airlineCompany in airlineCompanies)
            {
                //login as the airline to get access to the CreateFlight method
                LoginToken <AirlineCompany> AirlineCompanyLoginToken = flyingCenterSystem.AttemptLoginAirlineCompany(airlineCompany.Username, airlineCompany.Password);
                LoggedInAirlineFacade       airlineFacade            = (LoggedInAirlineFacade)FlyingCenterSystem.GetFlyingCenterSystem().GetFacade(AirlineCompanyLoginToken);

                for (int i = 0; i < TicketsPerCustomerAmount; i++)
                {
                    //create departue date
                    DateTime newFlightDeparture = DateTime.Now;
                    newFlightDeparture = newFlightDeparture.AddDays(r.Next(0, 8));
                    newFlightDeparture = newFlightDeparture.AddHours(r.Next(0, 25));
                    newFlightDeparture = newFlightDeparture.AddMinutes(r.Next(0, 61));
                    newFlightDeparture = newFlightDeparture.AddSeconds(r.Next(0, 61));

                    //create landing date
                    DateTime newFlightLanding = newFlightDeparture;
                    newFlightLanding = newFlightLanding.AddHours(r.Next(0, 25));
                    newFlightLanding = newFlightLanding.AddMinutes(r.Next(0, 61));
                    newFlightLanding = newFlightLanding.AddSeconds(r.Next(0, 61));

                    //choose countries for the flight
                    Country country1 = countries[r.Next(0, countries.Count)];
                    Country country2 = null;
                    do
                    {
                        country2 = countries[r.Next(0, countries.Count)];
                    }while (ReferenceEquals(country2, null) || country1.Equals(country2));

                    //create the flight and add it to the DB
                    int    availableTickets = r.Next(30, 61);
                    Flight toAdd            = new Flight(-1, airlineCompany.ID, country1.ID, country2.ID, newFlightDeparture, newFlightLanding, availableTickets, availableTickets);
                    airlineFacade.CreateFlight(AirlineCompanyLoginToken, toAdd);
                }
            }
        }
Example #5
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!");
        }