//[ExpectedException()]
 public void CheckNullToken()
 {
     Assert.ThrowsException <Exception>(() =>
     {
         airlineFacade.CancelFlight(null, new Flight());
     });
     Assert.ThrowsException <Exception>(() =>
     {
         airlineFacade.GetAllTickets(null);
     });
     Assert.ThrowsException <Exception>(() =>
     {
         airlineFacade.CreateFlight(null, new Flight());
     });
     Assert.ThrowsException <Exception>(() =>
     {
         airlineFacade.UpdateFlight(null, new Flight());
     });
     Assert.ThrowsException <Exception>(() =>
     {
         airlineFacade.ChangeMyPassword(null, "old_password", "new_password");
     });
     Assert.ThrowsException <Exception>(() =>
     {
         airlineFacade.MofidyAirlineDetails(null, new AirlineCompany());
     });
 }
Пример #2
0
        public void InsertData()
        {
            LoginToken <Administrator> admin = new LoginToken <Administrator>()
            {
                User = new Administrator(0, "Admin", "Test", 3, 0, new Users(0, "admin", "Test", "@", 1))
            };

            LoggedInAdministrator.CreateNewUser(admin, new Users(1, "admin1", "pass", "*****@*****.**", 1));
            LoggedInAdministrator.CreateNewUser(admin, new Users(2, "admin2", "pass", "*****@*****.**", 1));
            LoggedInAdministrator.CreateNewUser(admin, new Users(3, "airline1", "pass", "*****@*****.**", 2));
            LoggedInAdministrator.CreateNewUser(admin, new Users(4, "airline2", "pass", "*****@*****.**", 2));
            LoggedInAdministrator.CreateNewUser(admin, new Users(5, "customer1", "pass", "*****@*****.**", 3));
            LoggedInAdministrator.CreateNewUser(admin, new Users(6, "customer2", "pass", "*****@*****.**", 3));

            LoggedInAdministrator.CreateAdmin(admin, new Administrator(1, "simi", "simi", 2, 1));
            LoggedInAdministrator.CreateAdmin(admin, new Administrator(2, "bibi", "simi", 3, 2));
            LoggedInAdministrator.CreateNewAirline(admin, new AirlineCompanies(1, "airone", 3, 3));
            LoggedInAdministrator.CreateNewAirline(admin, new AirlineCompanies(2, "airtwo", 5, 4));
            LoggedInAdministrator.CreateNewCustomer(admin, new Customers(1, "cus", "tomer", "ytl2", "03-23423400234", "2131313", 5));
            LoggedInAdministrator.CreateNewCustomer(admin, new Customers(2, "cusw", "tomerw", "ytle3", "03-234546234234", "231313113", 6));

            loggedInAirline.CreateFlight(new LoginToken <AirlineCompanies>(), new Flights(1, 1, 3, 6, new DateTime(2021, 03, 26), new DateTime(2021, 04, 26), 10));
            loggedInAirline.CreateFlight(new LoginToken <AirlineCompanies>(), new Flights(2, 2, 5, 2, new DateTime(2021, 01, 17), new DateTime(2021, 04, 17), 23));
            LoggedInAdministrator.CreateNewTicket(admin, new Tickets(1, 1));
            LoggedInAdministrator.CreateNewTicket(admin, new Tickets(2, 2));
        }
Пример #3
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 IHttpActionResult CreateFlight([FromBody] Flight flight)
        {
            bool   isAuthorized = false;
            bool   isCreated    = false;
            Action act          = () =>
            {
                isAuthorized = GetInternalLoginTokenInternal <AirlineCompany>(out LoginToken <AirlineCompany> loginTokenAirline);

                if (isAuthorized)
                {
                    isCreated = _loggedInAirlineFacade.CreateFlight(loginTokenAirline, flight);
                }
            };

            ProcessExceptions(act);
            if (!isAuthorized)
            {
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, $"Sorry, but you're not an Airline Company. Your accsess is denied.")));
            }

            if (!isCreated)
            {
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, $"Sorry, but the flight number \"{flight.ID}\" doesn't created.")));
            }

            return(ResponseMessage(Request.CreateResponse(HttpStatusCode.OK, $"The flight number \"{flight.ID}\" has been created")));
        }
Пример #5
0
        public void CancelFlight()
        {
            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);
            myFacadeAir.CancelFlight(myTokenair, flight);
            Flight flight1 = myFacadeAir.GetFlightById(flight.ID);

            Assert.IsNull(flight1);
        }
Пример #6
0
        public void CreateFlight()
        {
            IList <AirlineCompany> airlines = facade.GetAllAirlineCompanies();

            flight.AirlineCompanyId = airlines[0].Id;
            facade.CreateFlight(AirLineLogin, flight);
        }
        private void Init_Customer_Facade_Data()
        {
            _logger.Debug($"Start Init Customer Tests Data");

            string username = "******";
            string password = "******";

            system.TryLogin(username, password, out ILoginToken admin_token, out FacadeBase admin_facade);
            LoggedInAdministratorFacade loggedInAdministratorFacade = admin_facade as LoggedInAdministratorFacade;
            LoginToken <Administrator>  adminLoginToken             = admin_token as LoginToken <Administrator>;
            int country_id = loggedInAdministratorFacade.CreateNewCountry(adminLoginToken, TestData.Get_Countries_Data()[0]);

            loggedInAdministratorFacade.CreateNewCountry(adminLoginToken, TestData.Get_Countries_Data()[1]);
            loggedInAdministratorFacade.CreateNewCountry(adminLoginToken, TestData.Get_Countries_Data()[2]);
            loggedInAdministratorFacade.CreateNewCustomer(adminLoginToken, TestData.Get_Customers_Data()[0]);
            loggedInAdministratorFacade.CreateNewCustomer(adminLoginToken, TestData.Get_Customers_Data()[1]);

            AirlineCompany airlineCompany = TestData.Get_AirlineCompanies_Data()[0];

            airlineCompany.CountryId = country_id;
            loggedInAdministratorFacade.CreateNewAirlineCompany(adminLoginToken, airlineCompany);
            system.TryLogin(airlineCompany.User.UserName, airlineCompany.User.Password, out ILoginToken airline_token, out FacadeBase airline_facade);
            LoggedInAirlineFacade       loggedInAirlineFacade = airline_facade as LoggedInAirlineFacade;
            LoginToken <AirlineCompany> airlineLoginToken     = airline_token as LoginToken <AirlineCompany>;
            Flight flight  = TestData.Get_Flights_Data()[3];
            Flight flight2 = TestData.Get_Flights_Data()[4];
            Flight flight3 = TestData.Get_Flights_Data()[5];

            long flight_id  = loggedInAirlineFacade.CreateFlight(airlineLoginToken, flight);
            long flight_id2 = loggedInAirlineFacade.CreateFlight(airlineLoginToken, flight2);
            long flight_id3 = loggedInAirlineFacade.CreateFlight(airlineLoginToken, flight3);

            flight.Id  = flight_id;
            flight2.Id = flight_id2;
            flight3.Id = flight_id3;

            system.TryLogin(TestData.Get_Customers_Data()[1].User.UserName, TestData.Get_Customers_Data()[1].User.Password, out ILoginToken token, out FacadeBase facade);
            LoginToken <Customer>  cust_token  = token as LoginToken <Customer>;
            LoggedInCustomerFacade cust_facade = facade as LoggedInCustomerFacade;

            cust_facade.PurchaseTicket(cust_token, flight);

            Login(TestData.Get_Customers_Data()[0].User.UserName, TestData.Get_Customers_Data()[0].User.Password);

            _logger.Debug($"End Init Customer Tests Data");
        }
Пример #8
0
        public void NullUserTriesToCreateFlightException()
        {
            FlightCenterSystem.Instance.Login(out FacadeBase facadebase, out ILoginToken token, "dana432", "gdfds");
            LoginToken <AirlineCompany> loginToken = (LoginToken <AirlineCompany>)token;
            LoggedInAirlineFacade       facade     = (LoggedInAirlineFacade)facadebase;

            facade.CreateFlight(null, new Flight());
        }
Пример #9
0
        public void AirlineFacade_CreateFlight()
        {
            LoggedInAirlineFacade facade = FlyingCenterSystem.GetInstance().Login(TestResource.AIRLINE_USERNAME, TestResource.AIRLINE_PASSWORD, out LoginTokenBase login) as LoggedInAirlineFacade;

            Flight flight = new Flight(1, 3, 2, new DateTime(2019, 08, 11, 09, 00, 00), new DateTime(2019, 08, 11, 12, 00, 00), 40);

            facade.CreateFlight(login as LoginToken <AirlineCompany>, flight);
        }
Пример #10
0
        public IHttpActionResult CreateFlight([FromBody] Flight flight)
        {
            LoginToken <AirlineCompany> token = GetLoginToken();

            facade.CreateFlight(token, flight);

            return(Ok());
        }
Пример #11
0
        public void CreateFlight_FlightAlreadyExists_ThrowsException()
        {
            LoggedInAirlineFacade airlineFacade = GetAirlineFacade(LoggedInAirlineFacadeTest_Constants.CreateFlight_FlightAlreadyExists_ThrowsException_LOGINTOKEN_USERNAME,
                                                                   LoggedInAirlineFacadeTest_Constants.CreateFlight_FlightAlreadyExists_ThrowsException_LOGINTOKEN_PASSWORD);
            Flight flight = LoggedInAirlineFacadeTest_Constants.CreateFlight_FlightAlreadyExists_ThrowsException_EXISTING_FLIGHT;

            Assert.ThrowsException <DataAlreadyExistsException>(new Action(() => airlineFacade.CreateFlight(airlineFacade.LoginToken, flight)));
        }
Пример #12
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);
        }
Пример #13
0
        public void CreateFlight()
        {
            Flights f = new Flights(1, 4, 5, DateTime.Now, new DateTime(2021, 05, 30), 54);

            loggedInAirline.CreateFlight(airline, f);
            Flights f_expected = new Flights(1, 4, 5, DateTime.Now, new DateTime(2021, 05, 30), 54);

            Assert.AreEqual(f_expected, f);
        }
Пример #14
0
        public IHttpActionResult CreateFlight([FromBody] Flight flight)
        {
            var loginToken = GetLoginToken();

            if (loginToken == null)
            {
                return(Unauthorized());
            }
            _facade.CreateFlight(loginToken, flight);
            return(Ok());
        }
Пример #15
0
        public IHttpActionResult CreateFlight([FromBody] Flight flight)
        {
            GetLoginToken();
            if (AirLineToken != null)
            {
                F.CreateFlight(AirLineToken, flight);
                return(Ok($"{flight.ID} has been created"));
            }

            return(NotFound());
        }
        public IActionResult CreateFlight([FromBody] Flight flight)
        {
            IActionResult result = SafeExecute(() =>
            {
                int facadeIndex = RetriveFacadeIndex();
                LoggedInAirlineFacade airlineFacade = (LoggedInAirlineFacade)FlyingCenterSystem.FacadeList[facadeIndex];
                airlineFacade.CreateFlight(airlineFacade.LoginToken, flight);
                return(Ok());
            });

            return(result);
        }
Пример #17
0
        public async Task <ActionResult <Customer> > CreateFlight([FromBody] Flight flight)
        {
            FlightsCenterSystem.GetInstance().login(GetLoginToken().Name, GetLoginToken().Password,
                                                    out LoginToken <Object> l, out FacadeBase f);
            facade        = f as LoggedInAirlineFacade;
            token_airline = GetLoginToken();
            User u = new UserDAOPGSQL().GetAll().FirstOrDefault(_ => _.Password == token_airline.Password && _.Username == token_airline.Name);

            token_airline.User = new AirlineDAOPGSQL().GetAll().FirstOrDefault(_ => _.UserId == u.Id);
            await Task.Run(() => facade.CreateFlight(token_airline, flight));

            return(StatusCode(200, flight));
        }
Пример #18
0
        private void FlightDBCreator()
        {
            while (true)
            {
                if (FlightsPerCompanyDataSet.runThread)
                {
                    List <Flight>   flights         = new List <Flight>();
                    RandomGenerator randomGenerator = new RandomGenerator();
                    List <DateTime> DepartureDates  = randomGenerator.DepartureDateGenerator(FlightsPerCompanyDataSet.listSize).ToList <DateTime>();
                    List <DateTime> LandingDates    = randomGenerator.LandingDateGenerator(DepartureDates).ToList <DateTime>();

                    int listBoxIndex   = GetListBoxIndex($"Creating Flight List. (0/{FlightsPerCompanyDataSet.listSize})");
                    int CompletedItems = 0;
                    for (int keyIndex = 0; keyIndex < AirlineDataSet.listSize; keyIndex++)
                    {
                        DictionaryOfFlightListSizeByAirline.TryGetValue(keyIndex, out int currentFlightListSize);
                        for (int index = 1; index <= currentFlightListSize; index++)
                        {
                            Flight flight = new Flight(keyIndex + 1, Random.Next(1, CountriesDataSet.listSize + 1), Random.Next(1, CountriesDataSet.listSize + 1), DepartureDates[index], LandingDates[index], Random.Next(100, 300));
                            flights.Add(flight);
                            CompletedItems++;
                            Dispatcher.Invoke(() => LogList[listBoxIndex] = $"Creating Flight List. ({CompletedItems}/{FlightsPerCompanyDataSet.listSize})");
                            UpdateProgress();
                        }
                    }
                    AirlineDataSet.DBCreated.WaitOne();

                    int totalIndex = 0;
                    for (int keyIndex = 0; keyIndex < AirlineDataSet.listSize; keyIndex++)
                    {
                        int facadeIndex = UserLogin(airlineCompanies[keyIndex].UserName, airlineCompanies[keyIndex].Password);
                        LoggedInAirlineFacade airlineFacade = (LoggedInAirlineFacade)FlyingCenterSystem.FacadeList[facadeIndex];
                        DictionaryOfFlightListSizeByAirline.TryGetValue(keyIndex, out int CurrentFlightListSize);

                        for (int flightListIndex = 1; flightListIndex <= CurrentFlightListSize; totalIndex++, flightListIndex++)
                        {
                            airlineFacade.CreateFlight(airlineFacade.LoginToken, flights[totalIndex]);
                            UpdateProgress();
                        }
                    }
                    GetListBoxIndex($"Flights Registered to Database.");
                    FlightsPerCompanyDataSet.DBCreated.Set();
                    FlightsPerCompanyDataSet.runThread = false;
                }
                else
                {
                    Thread.Sleep(500);
                }
            }
        }
Пример #19
0
        public IHttpActionResult CreateFlight([FromBody] HTTPFlight flight)
        {
            LoginToken <AirlineCompany> token  = (LoginToken <AirlineCompany>)Request.Properties["User"];
            LoggedInAirlineFacade       facade = (LoggedInAirlineFacade)(FlyingCenterSystem.GetFlyingCenterSystem().GetFacade(token));

            if (!CheckNewFlightInput(flight, token, facade))
            {
                return(BadRequest());
            }

            facade.CreateFlight(token, new Flight(-1, flight.AirlineCompanyID, flight.OriginCountryID, flight.DestinationCountryID, flight.DepartureTime,
                                                  flight.LandingTime, flight.RemainingTickets, flight.MaxTickets));

            return(Ok());
        }
Пример #20
0
        public IHttpActionResult CreateFlight(Flight flight)
        {
            LoginToken <AirlineCompany> airlineToken = new LoginToken <AirlineCompany>();

            try
            {
                airlineCompanyFacade.CreateFlight(airlineToken, flight);
                return(Ok(flight));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(BadRequest());
            }
        }
        public void TicketNotMatchWhenTryGetTicketThatNotMatchToCurrentCustomer()
        {
            AirlineCompany airline = CreateRandomCompany();

            airline.Airline_Number = adminFacade.CreateNewAirline(adminToken, airline);
            FlyingCenterSystem.GetUserAndFacade(airline.User_Name, "123", out ILogin token, out FacadeBase facade);
            LoginToken <AirlineCompany> newToken  = token as LoginToken <AirlineCompany>;
            LoggedInAirlineFacade       newfacade = facade as LoggedInAirlineFacade;
            Flight flight = CreateNewFlight();

            flight.AirlineCompany_Id = newToken.User.Id;
            flight.Id = newfacade.CreateFlight(newToken, flight);
            long   newId  = customerFacade.PurchaseTicket(customerToken, flight);
            Ticket ticket = airlineFacade.GetSoldTicketById(airlineToken, (int)newId);
        }
Пример #22
0
        public void AirlineFacadeTest()
        {
            FlightCenterConfig.DeleteDataBase();
            CountryDAOMSSQL cydao = new CountryDAOMSSQL();

            cydao.Add(new Country {
                COUNTRY_NAME = "Israel"
            });
            long countryId1 = cydao.GetCountryId("Israel");

            cydao.Add(new Country {
                COUNTRY_NAME = "Germany"
            });
            long countryId2 = cydao.GetCountryId("Germany");

            AirLineDAOMSSQL adao = new AirLineDAOMSSQL();

            adao.Add(new AirlineCompany {
                AIRLINE_NAME = "IsrLines", USER_NAME = "ISR91", PASSWORD = "******", COUNTRY_CODE = countryId1
            });
            long airlineCompanyId1 = adao.GetAirlineCompanyId("ISR91");

            adao.Add(new AirlineCompany {
                AIRLINE_NAME = "British Airlines", USER_NAME = "British555", PASSWORD = "******", COUNTRY_CODE = countryId2
            });
            long airlineCompanyId2 = adao.GetAirlineCompanyId("British555");


            LoginToken <AirlineCompany> airlineLogin = new LoginToken <AirlineCompany>();

            airlineLogin.User           = new AirlineCompany();
            airlineLogin.User.USER_NAME = "airline4life";
            airlineLogin.User.PASSWORD  = "******";
            LoggedInAirlineFacade airlineFacade = new LoggedInAirlineFacade();
            Flight flight = new Flight(airlineCompanyId1, airlineCompanyId2, countryId1, new DateTime(2019, 05, 10, 10, 30, 00), new DateTime(2019, 05, 10, 15, 05, 00), 15, "HajajaOnile", "555");

            airlineFacade.CreateFlight(airlineLogin, flight);
            FlightDAOMSSQL fdao     = new FlightDAOMSSQL();
            long           flightid = fdao.GetFlightId("555");

            Assert.AreEqual(flight, airlineFacade.GetFlightById((int)flightid));
            airlineFacade.CancelFlight(airlineLogin, flight);
            Assert.IsNotNull(airlineFacade.GetFlightById((int)flightid));

            airlineFacade.ChangeMyPassword(airlineLogin, "Na123456", "Aa100200");
            Assert.AreEqual("Aa100200", airlineLogin.User.PASSWORD);
        }
        public void TicketNotMatchWhenTryGetTicketThatNotMatchToCurrentCustomer()
        {
            tc.PrepareDBForTests();
            AirlineCompany airline = new AirlineCompany("AirlineForUpdate", "Airline " + tc.UserTest(), "123", (int)tc.adminFacade.GetCountryByName("Israel").Id);

            airline.Airline_Number = tc.adminFacade.CreateNewAirline(tc.adminToken, airline);
            FlyingCenterSystem.GetUserAndFacade(airline.User_Name, "123", out ILogin token, out FacadeBase facade);
            LoginToken <AirlineCompany> newToken  = token as LoginToken <AirlineCompany>;
            LoggedInAirlineFacade       newfacade = facade as LoggedInAirlineFacade;
            Flight flight = new Flight {
                AirlineCompany_Id = newToken.User.Id, Departure_Time = new DateTime(2020, 12, 10, 00, 00, 00), Landing_Time = new DateTime(2020, 12, 11), Origin_Country_Code = tc.adminFacade.GetCountryByName("Israel").Id, Destination_Country_Code = tc.adminFacade.GetCountryByName("Israel").Id, Remaining_Tickets = 100
            };

            flight.Id = newfacade.CreateFlight(newToken, flight);
            long   newId  = tc.customerFacade.PurchaseTicket(tc.customerToken, flight);
            Ticket ticket = tc.airlineFacade.GetSoldTicketById(tc.airlineToken, (int)newId);
        }
Пример #24
0
        public Flight CreateFlightForTests()
        {
            ClearDataBase();
            AirlineCompany a      = CreateAirlineCompanyForTests();
            Flight         flight = new Flight
            {
                ID = 1,
                AIRLINECOMPANY_ID        = a.ID,
                ORIGIN_COUNTRY_CODE      = a.COUNTRY_CODE,
                DESTINATION_COUNTRY_CODE = a.COUNTRY_CODE,
                DEPARTURE_TIME           = new DateTime(2019, 10, 01),
                LANDING_TIME             = new DateTime(2019, 10, 02),
                REMAINGING_TICKETS       = 100
            };

            airlinecompanyFacade.CreateFlight(airlinecompanyToken, flight);
            return(flight);
        }
        public void InsertData()
        {
            LoginToken <Administrator> adminToken = new LoginToken <Administrator>()
            {
                User = new Administrator("admin", "monro", 3, 500)
            };

            administratorFacade.CreateUser(adminToken, new User("admin_username", "admin_password", "admin_email", 1));
            administratorFacade.CreateUser(adminToken, new User("airline_username", "airline_passsword", "airline_email", 2));
            administratorFacade.CreateUser(adminToken, new User("customer_username", "customer_password", "customer_email", 3));

            administratorFacade.CreateAdmin(adminToken, new Administrator("adminfirst_name", "admin_last_name", 3, 1));
            administratorFacade.CreateNewAirline(adminToken, new AirlineCompany("airline_name", 3, 2));
            administratorFacade.CreateNewCustomer(adminToken, new Customer("customer_first_name", "customer_last_name", "customer_address", "customer_phone_no", "customer_credit_card_no", 3));

            airlineFacade.CreateFlight(new LoginToken <AirlineCompany>(), new Flight(1, 1, 1, new DateTime(2000, 01, 01), new DateTime(2000, 01, 01), 1));
            administratorFacade.CreateTicket(adminToken, new Ticket(1, 1));
        }
Пример #26
0
        public IHttpActionResult CreateFlight([FromBody] Flight flight)
        {
            LoginToken <AirlineCompany> airlineToken  = (LoginToken <AirlineCompany>)Request.Properties["airlineToken"];
            LoggedInAirlineFacade       airlineFacade = (LoggedInAirlineFacade)Request.Properties["airlineFacade"];

            if (flight == null)
            {
                return(Content(HttpStatusCode.NotAcceptable, "you didn't send a flight to post"));
            }
            try
            {
                airlineFacade.CreateFlight(airlineToken, flight);
                return(Ok($"flight {flight.ID} was created"));
            }
            catch (Exception e)
            {
                return(Content(HttpStatusCode.NotAcceptable, e.Message));
            }
        }
Пример #27
0
        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);
                }
            }
        }
Пример #28
0
        public void CreateFlight_Test()
        {
            FlightCenterSystem.Instance.Login(out FacadeBase facadebase, out ILoginToken token, "dana432", "gdfds");
            LoginToken <AirlineCompany> loginToken = (LoginToken <AirlineCompany>)token;
            LoggedInAirlineFacade       facade     = (LoggedInAirlineFacade)facadebase;
            Flight flight = new Flight
            {
                Airline_Company_Id     = 1,
                Origin_Country_Id      = 4,
                Destination_Country_Id = 3,
                Departure_Time         = new DateTime(2021, 5, 14, 19, 30, 00),
                Landing_Time           = new DateTime(2021, 5, 14, 22, 30, 00),
                Remaining_Tickets      = 30
            };

            facade.CreateFlight(loginToken, flight);
            Flight check_flight = _flightDAO.Get(10);

            Assert.AreEqual(check_flight.Id, 10);
        }
        public IHttpActionResult CreateFlight([FromBody] Flight flight)
        {
            GetLoginToken();

            try
            {
                airlineFacade.CreateFlight(loginToken, flight);
                Flight f = airlineFacade.GetAllFlights(loginToken).Last();
                flight.Id = f.Id;
                if (f == flight)
                {
                    return(Ok(flight));
                }
                return(NotFound());
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
        public void GetAllMyFlights()
        {
            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();
            Customer            customer               = new Customer("asdjkb", "fgh", "adthv", "0506794532", "123479520589243", 2);
            UserRepository      customerUserRepository = new UserRepository("radp", "ass", RolesEnum.customer);

            anonymousUserFacade.CreateCustomerAndUserRepository(customerUserRepository, customer);
            FlyingCenterSystem.GetInstance().TryLogin(customerUserRepository.UserName, customerUserRepository.Password, out ILogin tokenCustomer,
                                                      out FacadeBase facadeCustomer);
            LoginToken <Customer>  myTokencustomer        = tokenCustomer as LoginToken <Customer>;
            LoggedInCustomerFacade loggedInCustomerFacade = facadeCustomer as LoggedInCustomerFacade;

            loggedInCustomerFacade.PurchaseTicket(myTokencustomer, flight);
            List <Flight> flights = (List <Flight>)loggedInCustomerFacade.GetAllMyFlights(myTokencustomer);

            Assert.IsNotNull(flights);
        }