Ejemplo n.º 1
0
 public IHttpActionResult GetFlightsByLandingDate(DateTime landingDate)
 {
     if (anonymousUser.GetFlightsByLandingDate(landingDate) == null)
     {
         return(NotFound());
     }
     return(Ok((anonymousUser.GetFlightsByLandingDate(landingDate))));
 }
Ejemplo n.º 2
0
        public void AnonymousFacade_GetFlighstByLandingDate_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.GetFlightsByLandingDate(newFlight.LANDING_TIME);
            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);
        }
        public void AnonymouseFacade_GetFlightsByLandingDate_FlightsFound()
        {
            AnonymousUserFacade facade = FlyingCenterSystem.GetInstance().GetAnonymousFacade();

            IList <Flight> flights = facade.GetFlightsByLandingDate(TestResource.LANDING_TIME);

            Assert.AreNotEqual(null, flights);

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

                Assert.AreEqual(TestResource.DepartureTimes[i], flights[i].DepartureTime);

                Assert.AreEqual(TestResource.LandingTimes[i], flights[i].LandingTime);

                Assert.AreEqual(TestResource.AirlineCompaniesId[i], flights[i].AirlineCompanyId);

                Assert.AreEqual(TestResource.OriginCountryCodes[i], flights[i].OriginCountryCode);

                Assert.AreEqual(TestResource.DestinationCountryCodes[i], flights[i].DestinationCountryCode);

                Assert.AreEqual(TestResource.Vacancies[i], flights[i].RemainingTickets);
            }
        }
Ejemplo n.º 4
0
        public void GetAllFlightsByLandingTime()
        {
            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.GetFlightsByLandingDate(DateTime.Now);

            Assert.IsNotNull(flights);
        }
Ejemplo n.º 5
0
        public void GetFlightsByLandingDate_Test()
        {
            AnonymousUserFacade anonymous = new AnonymousUserFacade();
            var list = anonymous.GetFlightsByLandingDate(new System.DateTime(2021, 01, 24));

            Assert.AreEqual(list.Count, 1);
        }
Ejemplo n.º 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);
        }
        public void GetFlightsByLandingDate_NoFlightOnDate_ReturnsNullList()
        {
            AnonymousUserFacade userFacade = (AnonymousUserFacade)FlyingCenterSystem.FacadeList[0];
            DateTime            dateTime   = new DateTime(2019, 10, 11);

            List <Flight> flights = (List <Flight>)userFacade.GetFlightsByLandingDate(dateTime);

            Assert.AreEqual(0, flights.Count);
        }
Ejemplo n.º 8
0
        public IHttpActionResult GetFlightsByLandingDate([FromUri] DateTime landingDate)
        {
            IList <Flight> flights = anonymousUserFacade.GetFlightsByLandingDate(landingDate);

            if (flights.Count == 0)
            {
                return(NotFound());
            }
            return(Ok(flights));
        }
        public IHttpActionResult GetFlightsByLandingDate(DateTime landingDate)
        {
            IList <Flight> flights = facade.GetFlightsByLandingDate(landingDate);

            if (flights.Count > 0)
            {
                return(Ok(flights));
            }
            return(NotFound());
        }
Ejemplo n.º 10
0
        public void GetFlightsByLandingDate()
        {
            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.GetFlightsByLandingDate(new DateTime(2021, 04, 26));

            CollectionAssert.AreEqual(expectedlis, f);
        }
Ejemplo n.º 11
0
        public IHttpActionResult GetFlightsByLandingDate(int year = 0, int month = 0, int day = 0)
        {
            DateTime      landingDate          = new DateTime(year, month, day);
            List <Flight> flightsByLandingDate = _anonymous.GetFlightsByLandingDate(landingDate).ToList();

            if (flightsByLandingDate.Count == 0)
            {
                return(NotFound());
            }
            return(Ok(flightsByLandingDate));
        }
        public IHttpActionResult GetFlightsByLandingDate([FromUri] DateTime landingDate)
        {
            AnonymousUserFacade anonymousFacade = (AnonymousUserFacade)f.GetFacade(null);

            IList <Flight> flights = anonymousFacade.GetFlightsByLandingDate(landingDate);

            if (flights == null || flights.Count == 0 || landingDate <= DateTime.Now)
            {
                return(NotFound());
            }
            return(Ok(flights));
        }
Ejemplo n.º 13
0
        public void GetFlightsByLandingDateTest()
        {
            AnonymousUserFacade facade = FlightsCenterSystem.GetInstance().GetFacade <Anonymous>(null) as AnonymousUserFacade;

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

            var f_list = facade.GetFlightsByLandingDate(TestData.CreateFlight_LandingTime);

            Assert.AreNotEqual(f_list, null);
            Assert.AreEqual(f_list.Count, 1);
        }
        public void GetFlightsByLandingDate_OneFlightOnDate_ReturnsOneFlight()
        {
            AnonymousUserFacade userFacade = (AnonymousUserFacade)FlyingCenterSystem.FacadeList[0];
            DateTime            dateTime   = new DateTime(2020, 10, 11);

            List <Flight> flights = (List <Flight>)userFacade.GetFlightsByLandingDate(dateTime);

            Assert.AreEqual(1, flights.Count);
            foreach (Flight flight in flights)
            {
                Assert.IsNotNull(flight);
            }
        }
        public IHttpActionResult GetFlightsByLandingDate(DateTime landingDate)
        {
            List <Flight> flightsByLandingDate = AnonymousFacade.GetFlightsByLandingDate(landingDate).ToList();

            if (flightsByLandingDate.Count == 0)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(flightsByLandingDate));
            }
        }
        public IHttpActionResult GetFlightsByLandingDate(DateTime landingDate)
        {
            if (landingDate <= DateTime.Now)
            {
                return(BadRequest());
            }
            AnonymousUserFacade facade  = new AnonymousUserFacade();
            IList <Flight>      flights = facade.GetFlightsByLandingDate(landingDate);

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

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

            IList <Flight> result = null;

            try
            {
                result = await Task.Run(() => facade.GetFlightsByLandingDate(dateTime));
            }
            catch (Exception ex)
            {
                return(StatusCode(400, $"{{ error: can't get flights by landing date \"{ex.Message}\" }}"));
            }
            if (result == null)
            {
                return(StatusCode(204, "{There are no flights by this departure date }"));
            }
            return(Ok(result));
        }
Ejemplo n.º 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
        }
Ejemplo n.º 20
0
        public IHttpActionResult GetFlightsByLadnigDate([FromUri] DateTime date)
        {
            IList <Flight> flights = facade.GetFlightsByLandingDate(date);

            return(Ok(flights));
        }
Ejemplo n.º 21
0
 public IHttpActionResult GetFlightsByLandingDate(DateTime landingDate)
 {
     return(Json(_facade.GetFlightsByLandingDate(landingDate)));
 }