Пример #1
0
 public IHttpActionResult GetFlightsByOriginCountry(int countryCode)
 {
     if (anonymousUser.GetFlightsByOriginCountry(countryCode) == null)
     {
         return(NotFound());
     }
     return(Ok((anonymousUser.GetFlightsByOriginCountry(countryCode))));
 }
Пример #2
0
        public void AnonymousFacade_GetFlighstByOriginCountry_FlightsReceived()
        {
            Flight newFlight = null;

            InitDBUnitTest.InitDB();
            Flight flight = AirlineCompanyFacadeFacade_CreateNewFlight1();
            AnonymousUserFacade anonymousFacade = GetAnonymousFacade();

            newFlight    = CreateNewFlight1();
            newFlight.ID = flight.ID;
            newFlight.AIRLINECOMPANY_ID        = flight.AIRLINECOMPANY_ID;
            newFlight.ORIGIN_COUNTRY_CODE      = flight.ORIGIN_COUNTRY_CODE;
            newFlight.DESTINATION_COUNTRY_CODE = flight.DESTINATION_COUNTRY_CODE;
            IList <Flight> flights1 = anonymousFacade.GetFlightsByOriginCountry(newFlight.ORIGIN_COUNTRY_CODE);
            IList <Flight> flights2 = new List <Flight>();

            flights2.Add(newFlight);
            List <Flight> f1 = (List <Flight>)flights1;
            List <Flight> f2 = (List <Flight>)flights2;

            Assert.AreNotEqual(flights1, null);
            Assert.AreNotEqual(flights2, null);
            CollectionAssert.AreEqual(f1, f2);
            Assert.AreEqual(flights1[0].ID, flights2[0].ID);
            Assert.AreEqual(flights1[0].AIRLINECOMPANY_ID, flights2[0].AIRLINECOMPANY_ID);
            Assert.AreEqual(flights1[0].ORIGIN_COUNTRY_CODE, flights2[0].ORIGIN_COUNTRY_CODE);
            Assert.AreEqual(flights1[0].DESTINATION_COUNTRY_CODE, flights2[0].DESTINATION_COUNTRY_CODE);
            Assert.AreEqual(flights1[0].DEPARTURE_TIME, flights2[0].DEPARTURE_TIME);
            Assert.AreEqual(flights1[0].LANDING_TIME, flights2[0].LANDING_TIME);
            Assert.AreEqual(flights1[0].REMANING_TICKETS, flights2[0].REMANING_TICKETS);
            Assert.AreEqual(flights1[0].TOTAL_TICKETS, flights2[0].TOTAL_TICKETS);
        }
Пример #3
0
        public void GetAllFlightsByOriginCountry()
        {
            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);
            Flight flight = new Flight(DateTime.Now, DateTime.Now, 50, airlineCompany.ID, country.ID, country.ID);

            FlyingCenterSystem.GetInstance().TryLogin(airlineTestUr.UserName, airlineTestUr.Password, out ILogin tokenAir,
                                                      out FacadeBase facadeAir);
            LoginToken <AirlineCompany> myTokenair  = tokenAir as LoginToken <AirlineCompany>;
            LoggedInAirlineFacade       myFacadeAir = facadeAir as LoggedInAirlineFacade;

            myFacadeAir.CreateFlight(myTokenair, flight);
            AnonymousUserFacade anonymousUserFacade = new AnonymousUserFacade();
            List <Flight>       flights             = (List <Flight>)anonymousUserFacade.GetFlightsByOriginCountry(country.ID);

            Assert.IsNotNull(flights);
        }
Пример #4
0
        public void GetFlightsByOriginCountry_Test()
        {
            AnonymousUserFacade anonymous = new AnonymousUserFacade();
            var list = anonymous.GetFlightsByOriginCountry(2);

            Assert.AreEqual(list.Count, 2);
        }
        public void GetFlightsByOriginCountry_CountryHasNoFlights_ReturnsNullList()
        {
            AnonymousUserFacade userFacade = (AnonymousUserFacade)FlyingCenterSystem.FacadeList[0];

            List <Flight> flights = (List <Flight>)userFacade.GetFlightsByOriginCountry(3);

            Assert.AreEqual(0, flights.Count);
        }
Пример #6
0
        public void CRUDAirlineCompanyAndAnonymousFacadeTests()
        {
            ResetWhatIsNeeded();
            LoginService ls = new LoginService();
            LoginToken <AirlineCompany> loginToken = new LoginToken <AirlineCompany>();

            ls.TryAirlineLogin("company", "company", out loginToken);
            LoggedInAirlineFacade loggedInAirlineFacade = new LoggedInAirlineFacade();
            AnonymousUserFacade   anonymousUserFacade   = new AnonymousUserFacade();

            //create flight test
            DateTime departureTime = DateTime.Now.AddDays(1);
            DateTime landingTime   = departureTime.AddDays(1).AddHours(1);
            Flight   f             = new Flight(-1, loginToken.User.ID, 1, 3, departureTime, landingTime, 10, 10);

            loggedInAirlineFacade.CreateFlight(loginToken, f);

            IList <Flight> flights = anonymousUserFacade.GetAllFlights();

            //anonymous - get all flights test
            Assert.IsTrue(flights.Count == 1);
            f = flights[0];

            //anonymous - get flights vacancies
            Dictionary <Flight, int> dict = anonymousUserFacade.GetAllFlightsVacancy();
            int remainingTickets;

            Assert.IsTrue(dict.TryGetValue(f, out remainingTickets));
            Assert.AreEqual(10, remainingTickets);

            //anonymous - get flight by ID
            Assert.AreEqual(f, anonymousUserFacade.GetFlightById(f.ID));

            //anonymous - get flight by departure date
            Assert.IsTrue(checkForFlightInList(f, anonymousUserFacade.GetFlightsByDepatrureDate(f.DepartureTime)));

            //anonymous - get flight by landing date
            Assert.IsTrue(checkForFlightInList(f, anonymousUserFacade.GetFlightsByLandingDate(f.LandingTime)));

            //anonymous - get flight by destination country
            Assert.IsTrue(checkForFlightInList(f, anonymousUserFacade.GetFlightsByDestinationCountry(f.DestinationCountryID)));

            //anonymous - get flight by origin country
            Assert.IsTrue(checkForFlightInList(f, anonymousUserFacade.GetFlightsByOriginCountry(f.OriginCountryID)));

            //update flight
            Flight newFlight = new Flight(f.ID, f.AirlineCompanyID, f.OriginCountryID, f.DestinationCountryID, f.DepartureTime.AddMinutes(30), f.LandingTime.AddMinutes(30), f.RemainingTickets, f.MaxTickets);

            loggedInAirlineFacade.UpdateFlight(loginToken, newFlight);
            f = anonymousUserFacade.GetFlightById(newFlight.ID);
            Assert.IsTrue(f.DepartureTime.Equals(newFlight.DepartureTime) & f.DepartureTime.Equals(newFlight.DepartureTime));

            //cancel flight - test only the cancelling part, not the removing ticket part as there are
            //no tickets at this point
            loggedInAirlineFacade.CancelFlight(loginToken, newFlight);
            Assert.IsTrue(anonymousUserFacade.GetFlightById(newFlight.ID) == null);
        }
Пример #7
0
        public IHttpActionResult GetFlightsByOriginCountry(int countryCode)
        {
            List <Flight> flightsByOriginCountry = _anonymous.GetFlightsByOriginCountry(countryCode).ToList();

            if (flightsByOriginCountry.Count == 0)
            {
                return(NotFound());
            }
            return(Ok(flightsByOriginCountry));
        }
        public IHttpActionResult GetFlightsByOriginCountry(int countryCode)
        {
            IList <Flight> flights = facade.GetFlightsByOriginCountry(countryCode);

            if (flights.Count > 0)
            {
                return(Ok(flights));
            }
            return(NotFound());
        }
Пример #9
0
        public IHttpActionResult GetFlightsByOriginCountry([FromUri] long countryCode)
        {
            IList <Flight> flights = anonymousUserFacade.GetFlightsByOriginCountry(countryCode);

            if (flights.Count == 0)
            {
                return(NotFound());
            }
            return(Ok(flights));
        }
Пример #10
0
        public void GetFlightsByOriginCountry()
        {
            Flights        expectedF   = new Flights(1, 1, 3, 6, new DateTime(2021, 03, 26), new DateTime(2021, 04, 26), 10);
            List <Flights> expectedlis = new List <Flights>();

            expectedlis.Add(expectedF);
            List <Flights> f = (List <Flights>)anonymousUser.GetFlightsByOriginCountry(3);

            CollectionAssert.AreEqual(expectedlis, f);
        }
        public void AnonymouseFacade_GetFlightsByOriginCountry_FlightsFound()
        {
            AnonymousUserFacade facade = FlyingCenterSystem.GetInstance().GetAnonymousFacade();

            IList <Flight> flights = facade.GetFlightsByOriginCountry(TestResource.ORIGIN_COUNTRY_CODE);

            for (int i = 0; i < flights.Count; i++)
            {
                Assert.AreEqual(TestResource.ORIGIN_COUNTRY_CODE, flights[i].OriginCountryCode);
            }
        }
        public IHttpActionResult GetFlightsByOriginCountry([FromUri] int countryCode)
        {
            AnonymousUserFacade anonymousFacade = (AnonymousUserFacade)f.GetFacade(null);

            IList <Flight> flights = anonymousFacade.GetFlightsByOriginCountry(countryCode);

            if (flights == null || flights.Count == 0 || countryCode <= 0)
            {
                return(NotFound());
            }
            return(Ok(flights));
        }
        public void GetFlightsByOriginCountry_CountryHas1Flight_ReturnsListOfFlights()
        {
            AnonymousUserFacade userFacade = (AnonymousUserFacade)FlyingCenterSystem.FacadeList[0];

            List <Flight> flights = (List <Flight>)userFacade.GetFlightsByOriginCountry(5);

            Assert.AreEqual(1, flights.Count);
            foreach (Flight flight in flights)
            {
                Assert.IsNotNull(flight);
                Assert.AreEqual(5, flight.OriginCountryId);
            }
        }
        public IHttpActionResult GetFlightsByOriginCountry([FromUri] int countryCode)
        {
            List <Flight> flightsByOriginCountry = AnonymousFacade.GetFlightsByOriginCountry(countryCode).ToList();

            if (flightsByOriginCountry.Count == 0)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(flightsByOriginCountry));
            }
        }
Пример #15
0
        public void GetFlightsByOriginCountryTest()
        {
            AnonymousUserFacade facade = FlightsCenterSystem.GetInstance().GetFacade <Anonymous>(null) as AnonymousUserFacade;

            TestData.DeleteAllData();
            flightDAOPGSQL.Add(CreateFlightForTest());

            var flights_list = flightDAOPGSQL.GetAll();
            var f_list       = facade.GetFlightsByOriginCountry(flights_list[0].Origin_Country_Id);

            Assert.AreNotEqual(f_list, null);
            Assert.AreEqual(f_list.Count, 1);
        }
        public IHttpActionResult GetFlightsByOriginCountry([FromUri] int originCountryID)
        {
            if (originCountryID <= 0)
            {
                return(BadRequest());
            }
            AnonymousUserFacade facade  = new AnonymousUserFacade();
            IList <Flight>      flights = facade.GetFlightsByOriginCountry(originCountryID);

            if (flights.Count == 0)
            {
                return(StatusCode(HttpStatusCode.NoContent));
            }
            return(Ok(flights));
        }
        public async Task <ActionResult <Flights> > GetFlightsByOriginCountry(int countrycode)
        {
            IList <Flights> result = null;

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

            IList <Flight> result = null;

            try
            {
                result = await Task.Run(() => facade.GetFlightsByOriginCountry(countrycode));
            }
            catch (Exception ex)
            {
                return(StatusCode(400, $"{{ error: can't get flights by origin country \"{ex.Message}\" }}"));
            }
            if (result == null)
            {
                return(StatusCode(204, "{There are no flights by this origin country }"));
            }
            return(Ok(result));
        }
Пример #19
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
        }
Пример #20
0
        public IHttpActionResult GetFlightsByOriginCountry(int id = 0)
        {
            IList <Flight> flights = facade.GetFlightsByOriginCountry(id);

            return(Ok(flights));
        }
Пример #21
0
 public IHttpActionResult GetFlightsByOriginCountry(int countryCode)
 {
     return(Json(_facade.GetFlightsByOriginCountry(countryCode)));
 }