Пример #1
0
 public IHttpActionResult GetAllAirlineCompanies()
 {
     if (anonymousUser.GetAllAirlineCompanies() == null)
     {
         return(NotFound());
     }
     return(Ok(anonymousUser.GetAllAirlineCompanies()));
 }
        public void GenerateFlights(int flightsPerCompany)
        {
            Random   rng = new Random();
            DateTime now = DateTime.Now; //what's better? more fields but less text or less fields but more text?
            IList <AirlineCompany> airlines  = anonymousFacade.GetAllAirlineCompanies();
            IList <Country>        countries = dbGeneratorFacade.GetAllCountries();

            foreach (var airline in airlines)
            {
                for (int i = 0; i < flightsPerCompany; i++)
                {
                    try
                    {
                        //choosing random countries
                        int originCountryCodeIndex      = rng.Next(0, countries.Count - 1);
                        int destinationCountryCodeIndex = rng.Next(0, countries.Count - 1);

                        Country originCountry      = countries[originCountryCodeIndex];
                        Country destinationCountry = countries[destinationCountryCodeIndex];

                        //choosing random dates
                        int num1 = 0;
                        int num2 = 0;

                        while (num1 == num2)
                        {
                            num1 = rng.Next(-604800, 604801);
                            num2 = rng.Next(-604800, 604801);
                        }

                        DateTime departureDate;
                        DateTime landingDate;

                        if (num1 < num2)
                        {
                            departureDate = now.AddSeconds(num1);
                            landingDate   = now.AddSeconds(num2);
                        }
                        else
                        {
                            departureDate = now.AddSeconds(num2);
                            landingDate   = now.AddSeconds(num1);
                        }

                        Flight flight = new Flight(0, airline.ID, originCountry.ID, destinationCountry.ID, departureDate, landingDate, 200);
                        dbGeneratorFacade.CreateFlight(flight);
                    }
                    catch (Exception ex)
                    {
                        i--;
                    }
                }
            }
        }
Пример #3
0
        public void GetAllAirlineCompanies_Test()
        {
            AnonymousUserFacade anonymous = new AnonymousUserFacade();
            var list = anonymous.GetAllAirlineCompanies();

            Assert.IsTrue(list.Count > 0);
        }
Пример #4
0
        public void AnonymouseFacade_GetAllAirlineCompanies_AirlineCompaniesReceived()
        {
            InitDBUnitTest.InitDB();
            AirlineCompany         airlineCompany1   = AdministratorFacade_CreateNewAirline1();
            AirlineCompany         airlineCompany2   = AdministratorFacade_CreateNewAirline2();
            AnonymousUserFacade    anonymousFacade   = GetAnonymousFacade();
            IList <AirlineCompany> airlineCompanies1 = anonymousFacade.GetAllAirlineCompanies();
            IList <AirlineCompany> airlineCompanies2 = new List <AirlineCompany>();

            airlineCompanies2.Add(airlineCompany1);
            airlineCompanies2.Add(airlineCompany2);
            List <AirlineCompany> a1 = (List <AirlineCompany>)airlineCompanies1;
            List <AirlineCompany> a2 = (List <AirlineCompany>)airlineCompanies2;

            CollectionAssert.AreEqual(a1, a2);
            Assert.AreEqual(airlineCompanies1[0].ID, airlineCompanies2[0].ID);
            Assert.AreEqual(airlineCompanies1[0].AIRLINE_NAME, airlineCompanies2[0].AIRLINE_NAME);
            Assert.AreEqual(airlineCompanies1[0].USER_NAME, airlineCompanies2[0].USER_NAME);
            Assert.AreEqual(airlineCompanies1[0].PASSWORD, airlineCompanies2[0].PASSWORD);
            Assert.AreEqual(airlineCompanies1[0].COUNTRY_CODE, airlineCompanies2[0].COUNTRY_CODE);
            Assert.AreEqual(airlineCompanies1[1].ID, airlineCompanies2[1].ID);
            Assert.AreEqual(airlineCompanies1[1].AIRLINE_NAME, airlineCompanies2[1].AIRLINE_NAME);
            Assert.AreEqual(airlineCompanies1[1].USER_NAME, airlineCompanies2[1].USER_NAME);
            Assert.AreEqual(airlineCompanies1[1].PASSWORD, airlineCompanies2[1].PASSWORD);
            Assert.AreEqual(airlineCompanies1[1].COUNTRY_CODE, airlineCompanies2[1].COUNTRY_CODE);
        }
Пример #5
0
        public void TestGetAllAirlineCompanies()
        {
            ResetWhatIsNeeded();
            AnonymousUserFacade    anonymousUserFacade = new AnonymousUserFacade();
            IList <AirlineCompany> airlineCompanies    = anonymousUserFacade.GetAllAirlineCompanies();

            Assert.AreEqual(3, airlineCompanies.Count);
        }
        public IHttpActionResult GetAllAirlineCompanies()
        {
            IList <AirlineCompany> airlines = facade.GetAllAirlineCompanies();

            if (airlines.Count > 0)
            {
                return(Ok(airlines));
            }
            return(NotFound());
        }
Пример #7
0
        public IHttpActionResult GetAllAirlineCompanies()
        {
            IList <AirlineCompany> airlineCompanies = anonymousUserFacade.GetAllAirlineCompanies();

            if (airlineCompanies.Count == 0)
            {
                return(NotFound());
            }
            return(Ok(airlineCompanies));
        }
        public IHttpActionResult GetAllAirlineCompanies()
        {
            AllCompanies = F.GetAllAirlineCompanies().ToList();

            if (AllCompanies.Count == 0)
            {
                return(NotFound());
            }
            return(Ok(AllCompanies));
        }
Пример #9
0
        public IHttpActionResult GetAllAirlineComapanies()
        {
            List <AirlineCompany> airlineCompanies = _anonymous.GetAllAirlineCompanies().ToList();

            if (airlineCompanies.Count == 0)
            {
                return(NotFound());
            }
            return(Ok(airlineCompanies));
        }
        public void GetAllAirlineCompanies()
        {
            AirlineCompany expected_airline_company = new AirlineCompany("airline_name", 3, 2);

            expected_airline_company.Id = 1;
            List <AirlineCompany> list_of_airline_companies = (List <AirlineCompany>)anonymousUserFacade.GetAllAirlineCompanies();
            List <AirlineCompany> expected_list_of_airlines = new List <AirlineCompany>();

            expected_list_of_airlines.Add(expected_airline_company);
            CollectionAssert.AreEqual(list_of_airline_companies, expected_list_of_airlines);
        }
        public IHttpActionResult GetAllAirlineCompanies()
        {
            AnonymousUserFacade anonymousFacade = (AnonymousUserFacade)f.GetFacade(null);

            IList <AirlineCompany> airlineCompanies = anonymousFacade.GetAllAirlineCompanies();

            if (airlineCompanies == null || airlineCompanies.Count == 0)
            {
                return(NotFound());
            }
            return(Ok(airlineCompanies));
        }
Пример #12
0
        public void GetAllAirelineCompanies()
        {
            AirlineCompanies        expected     = new AirlineCompanies(1, "airone", 3, 3);
            AirlineCompanies        expected2    = new AirlineCompanies(2, "airtwo", 5, 4);
            List <AirlineCompanies> Expectedlist = new List <AirlineCompanies>();

            Expectedlist.Add(expected);
            Expectedlist.Add(expected2);
            List <AirlineCompanies> airlineCompanies = (List <AirlineCompanies>)anonymousUser.GetAllAirlineCompanies();

            CollectionAssert.AreEqual(Expectedlist, airlineCompanies);
        }
Пример #13
0
        public void GetAllAirlineCompaniesTest()
        {
            AnonymousUserFacade facade = FlightsCenterSystem.GetInstance().GetFacade <Anonymous>(null) as AnonymousUserFacade;

            TestData.DeleteAllData();

            airlineCompanyDAOPGSQL.Add(CreateAirlineCompanyForTest());

            var ac_list = facade.GetAllAirlineCompanies();

            Assert.AreNotEqual(ac_list, null);
            Assert.AreEqual(ac_list.Count, 1);
        }
        public IHttpActionResult GetAllAirlineCompanies()
        {
            AnonymousUserFacade    facade           = new AnonymousUserFacade();
            IList <AirlineCompany> airlineCompanies = facade.GetAllAirlineCompanies();

            if (airlineCompanies.Count == 0)
            {
                return(StatusCode(HttpStatusCode.NoContent));
            }
            else
            {
                return(Ok(airlineCompanies));
            }
        }
        public IHttpActionResult GetAllAirlineCompanies()
        {
            List <AirlineCompany> AllAirlineCompanies = AnonymousFacade.GetAllAirlineCompanies().ToList();

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

            else
            {
                return(Ok(AllAirlineCompanies));
            }
        }
        public IHttpActionResult GetAllCompanies()
        {
            IHttpActionResult result = controllersCenter.ExecuteSafe(() =>
            {
                IList <AirlineCompany> companies = facade.GetAllAirlineCompanies();
                if (companies.Count < 1)
                {
                    return(Content(HttpStatusCode.NoContent, "Company List Is Empty."));
                }
                return(Content(HttpStatusCode.OK, companies));
            });

            return(result); // for debug - break point here
        }
Пример #17
0
        public void RemoveAirlineTest()
        {
            TestData.DeleteAllData();
            getTokenAndGetFacade(out LoginToken <Admin> token, out LoggedInAdministratorFacade facadeAdmin);
            AnonymousUserFacade facade = FlightsCenterSystem.GetInstance().GetFacade <Anonymous>(null) as AnonymousUserFacade;

            airlineCompanyDAOPGSQL.Add(CreateAirlineCompanyForTest());
            var list = airlineCompanyDAOPGSQL.GetAll();

            facadeAdmin.RemoveAirline(token, list[0]);
            list = facade.GetAllAirlineCompanies();

            Assert.AreNotEqual(1, list.Count);
            Assert.AreEqual(0, list.Count);
        }
        public void AnonymouseFacade_GetAllAirlineCompanies_CompaniesFound()
        {
            AnonymousUserFacade facade = FlyingCenterSystem.GetInstance().GetAnonymousFacade();

            IList <AirlineCompany> companies = facade.GetAllAirlineCompanies();

            Assert.AreNotEqual(null, companies);

            for (int i = 0; i < companies.Count; i++)
            {
                Assert.AreEqual(TestResource.airlinesId[i], companies[i].Id);

                Assert.AreEqual(TestResource.airlineNames[i], companies[i].AirlineName);

                Assert.AreEqual(TestResource.airlineCountryCodes[i], companies[i].CountryCode);
            }
        }
        public async Task <ActionResult <AirlineCompanies> > GetAllAirlineCompanies()
        {
            IList <AirlineCompanies> result = null;

            try
            {
                result = await Task.Run(() => facade.GetAllAirlineCompanies());
            }
            catch (Exception ex)
            {
                return(StatusCode(400, $"{{ error: \"{ex.Message}\" }}"));
            }
            if (result == null)
            {
                return(StatusCode(204, "{ }"));
            }
            return(Ok(result));
        }
        public async Task <ActionResult <AirlineCompany> > GetAllAirlineCompanies()
        {
            AnonymousUserFacade facade = new AnonymousUserFacade(false);

            IList <AirlineCompany> result = null;

            try
            {
                result = await Task.Run(() => facade.GetAllAirlineCompanies());
            }
            catch (Exception ex)
            {
                return(StatusCode(400, $"{{ error: can't get all airline comapnies \"{ex.Message}\" }}"));
            }
            if (result == null)
            {
                return(StatusCode(204, "{The list is empty. No result to return }"));
            }
            return(Ok(result));
        }
Пример #21
0
        public void GetAllAirlineCompanies()
        {
            UserRepository testUr    = new UserRepository("dad", "aes", RolesEnum.admin);
            Admin          testAdmin = new Admin("dav,", "id", 3);

            FlyingCenterSystem.GetInstance().TryLogin(ur.UserName, ur.Password, out ILogin token,
                                                      out FacadeBase facade);
            LoginToken <Admin>          myToken  = token as LoginToken <Admin>;
            LoggedInAdministratorFacade myFacade = facade as LoggedInAdministratorFacade;

            myFacade.CreateNewAdmin(myToken, testUr, testAdmin);
            Country country = new Country("Israel");

            myFacade.CreateNewCountry(myToken, country);
            AirlineCompany airlineCompany = new AirlineCompany("ElALL", 1, country.ID);
            UserRepository airlineTestUr  = new UserRepository("rad", "ass", RolesEnum.airline);

            myFacade.CreateNewAirline(myToken, airlineTestUr, airlineCompany, country);
            AnonymousUserFacade   anonymousUserFacade = new AnonymousUserFacade();
            List <AirlineCompany> airlineCompanies    = (List <AirlineCompany>)anonymousUserFacade.GetAllAirlineCompanies();

            Assert.IsNotNull(airlineCompanies);
        }
Пример #22
0
        public void I_AnonymousFacadeTest()
        {
            new TestFacade().DeleteAllTables();

            FlightCenterSystem fcs = FlightCenterSystem.GetInstance();

            AnonymousUserFacade facade = fcs.GetFacade <Anonymous>(null) as AnonymousUserFacade;

            #region Sign up

            facade.SignUp(new Customer("Joe", "Fin", "jf", "*****@*****.**", "111", "China", "100", "4580"));

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

            Customer testCustomer = new LoggedInAdministratorFacade().GetAllCustomers(token)[0];

            Assert.AreEqual(testCustomer.FirstName, "Joe");
            Assert.AreEqual(testCustomer.LastName, "Fin");
            Assert.AreEqual(testCustomer.UserName, "jf");
            Assert.AreEqual(testCustomer.Password, "111");
            Assert.AreEqual(testCustomer.Address, "China");
            Assert.AreEqual(testCustomer.PhoneNo, "100");
            Assert.AreEqual(testCustomer.CreditCardNo, "4580");

            #endregion

            #region Get all airlines

            new LoggedInAdministratorFacade().CreateNewAirline(token, new AirlineCompany("Air One", "airone", "*****@*****.**", "555", 1));
            new LoggedInAdministratorFacade().CreateNewAirline(token, new AirlineCompany("Travel Air", "travelair", "*****@*****.**", "222", 1));

            IList <AirlineCompany> airlines = facade.GetAllAirlineCompanies();

            Assert.AreEqual(airlines[0].Name, "Air One");
            Assert.AreEqual(airlines[0].UserName, "airone");
            Assert.AreEqual(airlines[0].Password, "555");
            Assert.AreEqual(airlines[0].CountryCode, 1);

            Assert.AreEqual(airlines[1].Name, "Travel Air");
            Assert.AreEqual(airlines[1].UserName, "travelair");
            Assert.AreEqual(airlines[1].Password, "222");
            Assert.AreEqual(airlines[1].CountryCode, 1);

            #endregion

            #region Get all flights

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

            new LoggedInAirlineFacade().CreateFlight(airlineToken, new Flight(airlines[0].Id, 1, 2, new DateTime(2010, 10, 10), new DateTime(2010, 10, 10), 5, 99));
            new LoggedInAirlineFacade().CreateFlight(airlineToken, new Flight(airlines[1].Id, 2, 3, new DateTime(2012, 12, 12), new DateTime(2012, 12, 12), 0, 99));

            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(2010, 10, 10));
            Assert.AreEqual(flights[0].LandingTime, new DateTime(2010, 10, 10));
            Assert.AreEqual(flights[0].RemainingTickets, 5);
            Assert.AreEqual(flights[0].TicketPrice, 99);

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

            #endregion

            #region Get all flights vacancy

            Dictionary <Flight, int> flightsVacancy = facade.GetAllFlightsVacancy();

            Flight[] flightsArray = new Flight[2];
            int[]    vacancyArray = new int[2];

            flightsVacancy.Keys.CopyTo(flightsArray, 0);
            flightsVacancy.Values.CopyTo(vacancyArray, 0);

            Assert.AreEqual(flightsArray[0].Id, flights[0].Id);
            Assert.AreEqual(vacancyArray[0], flights[0].RemainingTickets);

            Assert.AreEqual(flightsArray[1].Id, flights[1].Id);
            Assert.AreEqual(vacancyArray[1], flights[1].RemainingTickets);

            #endregion

            #region Get flight by id

            Flight flight = facade.GetFlightById(flights[0].Id);

            Assert.AreEqual(flight.AirlineCompanyId, airlines[0].Id);
            Assert.AreEqual(flight.OriginCountryCode, 1);
            Assert.AreEqual(flight.DestinationCountryCode, 2);
            Assert.AreEqual(flight.DepartureTime, new DateTime(2010, 10, 10));
            Assert.AreEqual(flight.LandingTime, new DateTime(2010, 10, 10));
            Assert.AreEqual(flight.RemainingTickets, 5);

            #endregion

            #region Get flights by departure date

            IList <Flight> selectedFlights = facade.GetFlightsByDepartureDate(new DateTime(2010, 10, 10));

            Assert.AreEqual(selectedFlights[0].AirlineCompanyId, airlines[0].Id);
            Assert.AreEqual(selectedFlights[0].OriginCountryCode, 1);
            Assert.AreEqual(selectedFlights[0].DestinationCountryCode, 2);
            Assert.AreEqual(selectedFlights[0].DepartureTime, new DateTime(2010, 10, 10));
            Assert.AreEqual(selectedFlights[0].LandingTime, new DateTime(2010, 10, 10));
            Assert.AreEqual(selectedFlights[0].RemainingTickets, 5);

            #endregion

            #region Get flights by landing date

            selectedFlights = facade.GetFlightsByLandingDate(new DateTime(2012, 12, 12));

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

            #endregion

            #region Get flights by origin country

            selectedFlights = facade.GetFlightsByOriginCountry(1);

            Assert.AreEqual(selectedFlights[0].AirlineCompanyId, airlines[0].Id);
            Assert.AreEqual(selectedFlights[0].OriginCountryCode, 1);
            Assert.AreEqual(selectedFlights[0].DestinationCountryCode, 2);
            Assert.AreEqual(selectedFlights[0].DepartureTime, new DateTime(2010, 10, 10));
            Assert.AreEqual(selectedFlights[0].LandingTime, new DateTime(2010, 10, 10));
            Assert.AreEqual(selectedFlights[0].RemainingTickets, 5);

            #endregion

            #region Get flights by destination country

            selectedFlights = facade.GetFlightsByDestinationCountry(3);

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

            #endregion
        }
        public async Task <ActionResult <List <Flight> > > GetAllAirlineCompanies()
        {
            var result = await Task.Run(() => facade.GetAllAirlineCompanies());

            return(StatusCode(200, result));
        }
Пример #24
0
        public AirlineCompany GetAirlineFotTest()
        {
            AirlineCompany a = AnonymousFacade.GetAllAirlineCompanies().ToList()[0];

            return(a);
        }
Пример #25
0
 public IHttpActionResult GetAllAirlineCompanies()
 {
     return(Json(_facade.GetAllAirlineCompanies()));
 }
Пример #26
0
        public IHttpActionResult GetAllAirlineCompanies()
        {
            IList <AirlineCompany> airlineCompanies = facade.GetAllAirlineCompanies();

            return(Ok(airlineCompanies));
        }