예제 #1
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);
        }
예제 #2
0
        public Tickets PurchaseTicket(LoginToken <Customer> token, Flight flight)
        {
            Tickets ticket    = new Tickets();
            Flight  newFlight = new Flight(flight.AIRLINECOMPANY_ID, flight.ORIGIN_COUNTRY_CODE, flight.DESTINATION_COUNTRY_CODE, flight.DEPARTURE_TIME, flight.LANDING_TIME, flight.REMAINING_TICKETS, flight.AIRLINECOMPANY_NAME, flight.FLIGHT_NAME);

            if (token != null)
            {
                _flightDAO = new FlightDAOMSSQL();
                if (newFlight.REMAINING_TICKETS > 0)
                {
                    newFlight.REMAINING_TICKETS--;
                    _flightDAO.Update(newFlight);
                }
                long flightID = _flightDAO.GetFlightId(flight.FLIGHT_NAME);
                ticket.FLIGHT_ID = flightID;
            }
            return(ticket);
        }
예제 #3
0
        public void AdminFacadeTest()
        {
            // Deleting database
            FlightCenterConfig.DeleteDataBase();
            //Creating DAO'S samples to test
            long             airlineCompanyId1 = 0, airlineCompanyId2 = 0, countryId1 = 0, countryId2 = 0, flightId1 = 0, customerId1 = 0;
            AirLineDAOMSSQL  adao = new AirLineDAOMSSQL();
            FlightDAOMSSQL   fdao = new FlightDAOMSSQL();
            CustomerDAOMSSQL cdao = new CustomerDAOMSSQL();
            CountryDAOMSSQL  cydao = new CountryDAOMSSQL();
            TicketDAOMSSQL   tdao = new TicketDAOMSSQL();

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

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

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

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

            // Adding new Flight
            fdao.Add(new Flight {
                AIRLINECOMPANY_ID = airlineCompanyId1, ORIGIN_COUNTRY_CODE = countryId1, DESTINATION_COUNTRY_CODE = countryId2, DEPARTURE_TIME = new DateTime(2019, 05, 10, 10, 30, 00), LANDING_TIME = new DateTime(2019, 05, 10, 15, 05, 00), REMAINING_TICKETS = 15, AIRLINECOMPANY_NAME = "IsrLines", FLIGHT_NAME = "555"
            });
            flightId1 = fdao.GetFlightId("555");

            // Adding new Customer
            cdao.Add(new Customer {
                FIRST_NAME = "Efrat", LAST_NAME = "Patihi", USER_NAME = "Efrat_kapara", PASSWORD = "******", ADDRESS = "Netanya , Raziel 40", PHONE_NO = "05011554875", CREDIT_CARD_NUMBER = "123456789"
            });
            customerId1 = cdao.GetCustomerId("Efrat_kapara");

            // Adding new Ticket
            tdao.Add(new Tickets {
                CUSTOMER_ID = customerId1, FLIGHT_ID = flightId1
            });
            // Testing
            FlyingCenterSystem         fcs        = FlyingCenterSystem.GetInstance();
            LoginToken <Administrator> adminLogin = new LoginToken <Administrator>();

            adminLogin.User = new Administrator();
            adminLogin.User.AdminUserName = "******";
            adminLogin.User.Password      = "******";


            // Trying to login
            fcs.login.TryAdminLogin(adminLogin.User.AdminUserName, adminLogin.User.Password, out LoginToken <Administrator> adminToken);
            fcs.login.TryAirlineLogin("ISR91", "Is789", out LoginToken <AirlineCompany> airlineToken);
            fcs.login.TryCustomerLogin("Efrat_kapara", "Efi93", out LoginToken <Customer> customerToken);


            // Testing admin facade fucntions
            LoggedInAdministratorFacade adminFacadae = fcs.GetFacade(adminLogin) as LoggedInAdministratorFacade;

            adminFacadae.CreateNewCountry(adminLogin, new Country {
                COUNTRY_NAME = "Israel"
            });
            AirlineCompany airline = new AirlineCompany()
            {
                AIRLINE_NAME = "Nassa",
                USER_NAME    = "Nassa28",
                PASSWORD     = "******",
                COUNTRY_CODE = adminFacadae.GetCountryId("Israel")
            };

            adminFacadae.CreateNewAirline(adminLogin, airline);
            Assert.AreEqual(adminFacadae.GetAirlineByUserame("Nassa28"), airline);

            Customer cust = new Customer()
            {
                FIRST_NAME         = "Tal",
                LAST_NAME          = "Rdt",
                USER_NAME          = "TalGever",
                PASSWORD           = "******",
                ADDRESS            = "Hazfira 20, Pardes hanna",
                PHONE_NO           = "0505001245",
                CREDIT_CARD_NUMBER = "456123456789"
            };

            adminFacadae.CreateNewCustomer(adminLogin, cust);
            Assert.AreEqual(cust, adminFacadae.GetCustomerByUserName("TalGever")); // works
            adminFacadae.UpdateAirlineDetails(adminLogin, new AirlineCompany {
                AIRLINE_NAME = "Nasa4Life", USER_NAME = "Nassa28", PASSWORD = "******", COUNTRY_CODE = adminFacadae.GetCountryId("Israel")
            });
            adminFacadae.UpdateCustomerDetails(adminLogin, new Customer {
                FIRST_NAME = "Tal", LAST_NAME = "Rdt", USER_NAME = "TalGever", PASSWORD = "******", ADDRESS = "Raziel 50 , Netanya", PHONE_NO = "0505001245", CREDIT_CARD_NUMBER = "456123456789"
            });
            AirlineCompany airl = new AirlineCompany()
            {
                AIRLINE_NAME = "Nasa4Life",
                USER_NAME    = "Nassa28",
                PASSWORD     = "******",
                COUNTRY_CODE = adminFacadae.GetCountryId("Israel")
            };

            adminFacadae.RemoveAirline(adminLogin, airl);
        }