Esempio n. 1
0
 public IHttpActionResult GetAllFlightsVacancy()
 {
     if (anonymousUser.GetAllFlightsVacancy() == null)
     {
         return(NotFound());
     }
     return(Ok(anonymousUser.GetAllFlightsVacancy()));
 }
Esempio n. 2
0
        public void GetAllFlightsThatIsentFullyBooked()
        {
            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();
            Dictionary <Flight, int> flights             = (Dictionary <Flight, int>)anonymousUserFacade.GetAllFlightsVacancy();

            Assert.IsNotNull(flights);
        }
        public void GetAllFlightsVacancy_Test()
        {
            AnonymousUserFacade anonymous = new AnonymousUserFacade();
            var list = anonymous.GetAllFlightsVacancy();

            Assert.IsTrue(list.Count > 0);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        public IHttpActionResult GetAllFlightsVacancy()
        {
            Dictionary <Flight, int> vacancy = anonymous.GetAllFlightsVacancy();

            if (vacancy.Count == 0)
            {
                return(NotFound());
            }
            return(Ok(vacancy));
        }
        public IHttpActionResult GetAllFlightsVacancy()
        {
            FlightsVacanc = F.GetAllFlightsVacancy();

            if (FlightsVacanc.Count == 0)
            {
                return(NotFound());
            }
            return(Ok(FlightsVacanc));
        }
        public IHttpActionResult GetAllFlightsVacancy()
        {
            Dictionary <Flight, int> flights = facade.GetAllFlightsVacancy();

            if (flights.Count > 0)
            {
                return(Ok(flights));
            }
            return(NotFound());
        }
        public void GetAllFlightsVacancy()
        {
            Flight expectedFlight = new Flight(1, 1, 1, new DateTime(2000, 01, 01), new DateTime(2000, 01, 01), 1);

            expectedFlight.Id = 1;
            Dictionary <Flight, int> flights_vacancy          = anonymousUserFacade.GetAllFlightsVacancy();
            Dictionary <Flight, int> expected_flights_vacancy = new Dictionary <Flight, int>();

            expected_flights_vacancy.Add(expectedFlight, 1);
            CollectionAssert.AreEqual(flights_vacancy, expected_flights_vacancy);
        }
        public IHttpActionResult GetAllFlightsVacancy()
        {
            AnonymousUserFacade anonymousFacade = (AnonymousUserFacade)f.GetFacade(null);

            Dictionary <Flight, int> vacancy = anonymousFacade.GetAllFlightsVacancy();

            if (vacancy == null || vacancy.Count == 0)
            {
                return(NotFound());
            }
            return(Ok(vacancy));
        }
Esempio n. 10
0
        public void GetAllFlightsVacancy()
        {
            Flights expectedF  = new Flights(1, 1, 3, 6, new DateTime(2021, 03, 26), new DateTime(2021, 04, 26), 10);
            Flights expectedF3 = new Flights(2, 2, 5, 2, new DateTime(2021, 01, 17), new DateTime(2021, 04, 17), 23);
            Dictionary <Flights, int> flight_vacancy = new Dictionary <Flights, int>();

            flight_vacancy = anonymousUser.GetAllFlightsVacancy();
            Dictionary <Flights, int> flight_vacancy_expected = new Dictionary <Flights, int>();

            flight_vacancy_expected.Add(expectedF, 10);
            flight_vacancy_expected.Add(expectedF3, 23);
            CollectionAssert.AreEqual(flight_vacancy_expected, flight_vacancy);
        }
Esempio n. 11
0
        public void GetAllFlightsVacancyTest()
        {
            AnonymousUserFacade facade = FlightsCenterSystem.GetInstance().GetFacade <Anonymous>(null) as AnonymousUserFacade;

            TestData.DeleteAllData();

            flightDAOPGSQL.Add(CreateFlightForTest());

            var f_list = facade.GetAllFlightsVacancy();

            Assert.AreNotEqual(f_list, null);
            Assert.AreEqual(f_list.Count, 1);
        }
        public IHttpActionResult GetAllFlightsVacancy()
        {
            Dictionary <Flight, int> AllFlightsVacancy = AnonymousFacade.GetAllFlightsVacancy();

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

            else
            {
                return(Ok(AllFlightsVacancy.ToList()));
            }
        }
        public IHttpActionResult GetAllFlightsVacancy()
        {
            IHttpActionResult result = controllersCenter.ExecuteSafe(() =>
            {
                Dictionary <Flight, int> vacancyFlights = facade.GetAllFlightsVacancy();
                if (vacancyFlights.Count < 1)
                {
                    return(Content(HttpStatusCode.NoContent, "Sorry, But Currently, Has No Flights With Tickets To Buy... Please Try Later."));
                }
                return(Content(HttpStatusCode.OK, vacancyFlights));
            });

            return(result); // for debug - break point here
        }
Esempio n. 14
0
        public void Get_All_Flights_Vacancy()
        {
            Execute_Test(() =>
            {
                Dictionary <Flight, int> flight_vacancy = anonymous_facade.GetAllFlightsVacancy();
                Assert.AreEqual(flight_vacancy.Count, 6);

                for (int i = 0; i < flight_vacancy.Count; i++)
                {
                    Flight flight = TestData.Get_Flights_Data_For_Anonymous_Tests()[i];
                    flight.Id     = i + 1;

                    Assert.AreEqual(flight.RemainingTickets, flight_vacancy[flight]);
                }
            });
        }
        public IHttpActionResult GetAllFlightsVacancies()
        {
            AnonymousUserFacade      facade    = new AnonymousUserFacade();
            Dictionary <Flight, int> vacancies = facade.GetAllFlightsVacancy();

            if (vacancies.Count == 0)
            {
                return(StatusCode(HttpStatusCode.NoContent));
            }
            else
            {
                //converting from Flight,int dictionary to int,int dictionary
                Dictionary <int, int> toReturn = new Dictionary <int, int>();
                foreach (KeyValuePair <Flight, int> pair in vacancies)
                {
                    toReturn.Add(pair.Key.ID, pair.Value);
                }
                return(Ok(toReturn));
            }
        }
        public void AnonymouseFacade_GetAllFlightsVacancy_FlightsVacancyFound()
        {
            AnonymousUserFacade facade = FlyingCenterSystem.GetInstance().GetAnonymousFacade();

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

            Assert.AreNotEqual(flightsVacancy, null);

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

            int i = 0;

            foreach (Flight flight in flights)
            {
                flightsVacancy.TryGetValue(flight, out int vacancy);

                Assert.AreEqual(TestResource.Vacancies[i], vacancy);

                i = i + 1;
            }
        }
Esempio n. 17
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
        }
Esempio n. 18
0
        public IHttpActionResult GetAllFlightsVacancy()
        {
            IDictionary <Flight, int> flightsVacancy = facade.GetAllFlightsVacancy();

            return(Ok(flightsVacancy));
        }
Esempio n. 19
0
 public IHttpActionResult GetAllFlightsVacancy()
 {
     return(Json(_facade.GetAllFlightsVacancy()));
 }