public void AddTicketsToCustomer(LoginToken <Administrator> token, long customerId, long flightId)
        {
            _ticketDAO = new TicketDAOMSSQL();
            Tickets ticket = new Tickets(customerId, flightId);

            _ticketDAO.Add(ticket);
        }
        public void GetAllTicketsTest()
        {
            t.ClearTables();
            t.FillDBForTest();
            AirlineCompany a = new AirlineCompany("airfrance", "airfrance", "134567", t.adminFacade.GetCountryByName(t.adminToken, "Israel").ID);

            t.adminFacade.CreateNewAirline(t.adminToken, a);
            t.airLineToken.User = a;

            Customer c = new Customer("Einat", "Mor", "Einat123", "191919", "Katzenelson", "0545552809", "000004400");

            t.customerToken.User = c;
            t.adminFacade.CreateNewCustomer(t.adminToken, c);

            Flight flight = new Flight(a.ID, a.CountryCode, a.CountryCode, new DateTime(2019, 10, 10), new DateTime(2019, 10, 10), 1);

            t.airLineToken.User = a;
            t.airlineFacade.CreateFlight(t.airLineToken, flight);

            Ticket         ticket         = new Ticket(flight.ID, c.ID);
            TicketDAOMSSQL ticketDAOMSSQL = new TicketDAOMSSQL();

            ticketDAOMSSQL.Add(ticket);

            Assert.AreEqual(t.airlineFacade.GetAllTickets(t.airLineToken).Count, 1);
        }
        public void PurchaseTicketException()
        {
            TicketDAOMSSQL t      = new TicketDAOMSSQL();
            Flight         Flight = new Flight(TestCenter.AirlineToken.User.Id, TestCenter.AirlineToken.User.CountryCode, TestCenter.AirlineToken.User.CountryCode, new DateTime(2020, 10, 10, 10, 00, 00), new DateTime(2020, 10, 11, 10, 00, 00), 0);

            TestCenter.AirlineFacade.CreateFlight(TestCenter.AirlineToken, Flight);
            TestCenter.CustomerFacade.PurchaseTicket(TestCenter.CustomerToken, Flight);
        }
Ejemplo n.º 4
0
 {/// <summary>
  /// This class handle connecttion to Dao  Anonymous functions
  /// </summary>
     public AnonymousUserFacade()
     {
         _flightDAO        = new FlightDAOMSSQL();
         _airlineDAO       = new AirLineDAOMSSQL();
         _administratorDAO = new AdministratorDAOMSSQL();
         _ticketDAO        = new TicketDAOMSSQL();
         _customerDAO      = new CustomerDAOMMSQL();
         _countryDAO       = new CountryDAOMSSQL();
     }
        public List <Tickets> GetAllTickets(LoginToken <AirlineCompany> token)
        {
            List <Tickets> tickets = new List <Tickets>();

            if (token != null)
            {
                _ticketDAO = new TicketDAOMSSQL();
                tickets    = _ticketDAO.GetAll();
            }
            return(tickets);
        }
        public void PurchaseTicketTest()
        {
            TicketDAOMSSQL t = new TicketDAOMSSQL();

            Assert.AreEqual(t.GetAll().Count, 0);
            Flight Flight = new Flight(TestCenter.AirlineToken.User.Id, TestCenter.AirlineToken.User.CountryCode, TestCenter.AirlineToken.User.CountryCode, new DateTime(2020, 10, 10, 10, 00, 00), new DateTime(2020, 10, 11, 10, 00, 00), 100);

            TestCenter.AirlineFacade.CreateFlight(TestCenter.AirlineToken, Flight);
            Assert.AreEqual(TestCenter.AdminFacade.GetFlightById(Flight.Id).RemainingTickets, Flight.RemainingTickets);
            TestCenter.CustomerFacade.PurchaseTicket(TestCenter.CustomerToken, Flight);
            Assert.AreEqual(t.GetAll().Count, 1);
            Assert.AreEqual(TestCenter.AdminFacade.GetFlightById(Flight.Id).RemainingTickets, Flight.RemainingTickets - 1);
        }
 public RandomDataGenerator()
 {
     _random           = new Random();
     _countryDAO       = new CountryDAOMSSQL();
     _customerDAO      = new CustomerDAOMSSQL();
     _airlineDAO       = new AirlineDAOMSSQL();
     _flightDAO        = new FlightDAOMSSQL();
     _ticketDAO        = new TicketDAOMSSQL();
     _countries        = new List <Country>();
     _customers        = new List <Customer>();
     _airlineCompanies = new List <AirlineCompany>();
     _flights          = new List <Flight>();
     _tickets          = new List <Ticket>();
 }
Ejemplo n.º 8
0
        private void timer_Elapsed(object sender)
        {
            string time = ConfigurationManager.AppSettings["ClearHistoryTime"].ToString();
            int    hour = Convert.ToInt32(time);
            int    now  = DateTime.Now.Hour;

            if (now >= hour)
            {
                TicketDAOMSSQL t = new TicketDAOMSSQL();
                FlightDAOMSSQL f = new FlightDAOMSSQL();
                t.MoveToTicketsHistory();
                f.MoveToFlightsHistory();
            }
        }
Ejemplo n.º 9
0
        public void TestGetFlightByID()
        {
            test = new TestInfo();
            Country testCountry = new Country("usa");

            testCountry.ID = test.adminF.CreateNewCountry(test.adminT, testCountry);
            Flight         flight = new Flight(test.airlineT.User.ID, testCountry.ID, testCountry.ID, DateTime.ParseExact("2019-07-08 12:00:00", "yyyy-MM-dd HH:mm:ss", null), DateTime.ParseExact("2019-07-18 12:00:00", "yyyy-MM-dd HH:mm:ss", null), 5);
            FlightDAOMSSQL Fdao   = new FlightDAOMSSQL();

            flight.ID = Fdao.ADD(flight);
            TicketDAOMSSQL tDAO = new TicketDAOMSSQL();

            Assert.AreEqual(flight.RemaniningTickets, test.airlineF.GetFlightById(flight.ID).RemaniningTickets);
        }
Ejemplo n.º 10
0
        public void TestCancelTicket()
        {
            test = new TestInfo();
            Country testCountry = new Country("usa");

            testCountry.ID = test.adminF.CreateNewCountry(test.adminT, testCountry);
            Flight         flight = new Flight(test.airlineT.User.ID, testCountry.ID, testCountry.ID, DateTime.ParseExact("2019-07-08 12:00:00", "yyyy-MM-dd HH:mm:ss", null), DateTime.ParseExact("2019-07-18 12:00:00", "yyyy-MM-dd HH:mm:ss", null), 5);
            FlightDAOMSSQL Fdao   = new FlightDAOMSSQL();

            flight.ID = Fdao.ADD(flight);
            Ticket         t    = test.customerF.PurchaseTicket(test.customerT, flight);
            TicketDAOMSSQL tDAO = new TicketDAOMSSQL();

            test.customerF.CancelTicket(test.customerT, t);
            Assert.AreEqual(0, tDAO.Get(t.ID).ID);
        }
        public void CancleTicketTest()
        {
            Flight Flight = new Flight(TestCenter.AirlineToken.User.Id, TestCenter.AirlineToken.User.CountryCode, TestCenter.AirlineToken.User.CountryCode, new DateTime(2020, 10, 10, 10, 00, 00), new DateTime(2020, 10, 11, 10, 00, 00), 100);

            TestCenter.AirlineFacade.CreateFlight(TestCenter.AirlineToken, Flight);
            Ticket ticket = new Ticket(Flight.Id, TestCenter.CustomerToken.User.Id);

            ticket.Id = TestCenter.CustomerFacade.PurchaseTicket(TestCenter.CustomerToken, Flight).Id;
            TicketDAOMSSQL t = new TicketDAOMSSQL();

            Assert.AreEqual(t.GetAll().Count, 1);
            Assert.AreEqual(Flight.RemainingTickets - 1, TestCenter.CustomerFacade.GetFlightById(Flight.Id).RemainingTickets);
            TestCenter.CustomerFacade.CancelTicket(TestCenter.CustomerToken, ticket);
            Assert.AreEqual(TestCenter.CustomerFacade.GetAllMyFlights(TestCenter.CustomerToken).Count, 0);
            Assert.AreEqual(Flight.RemainingTickets, TestCenter.CustomerFacade.GetFlightById(Flight.Id).RemainingTickets);
        }
Ejemplo n.º 12
0
        public void TicketFuncsTest()
        {
            FlightDAOMSSQL flight = new FlightDAOMSSQL();

            flight.RemoveAll();
            CountryDAOMSSQL c = new CountryDAOMSSQL();

            c.RemoveAll();
            AirlineDAOMSSQL airline = new AirlineDAOMSSQL();

            airline.RemoveAll();
            Ticket         t1     = new Ticket(2, 3);
            Ticket         t2     = new Ticket(4, 1);
            TicketDAOMSSQL ticket = new TicketDAOMSSQL();
            //ticket.RemoveAll();
            //ticket.Add(t1);
            //ticket.Add(t2);
        }
 public void CancelFlight(LoginToken <AirlineCompany> token, Flight flight)
 {
     if (token != null)
     {
         if (flight.REMAINING_TICKETS > 0)
         {
             _ticketDAO = new TicketDAOMSSQL();
             Tickets t = new Tickets();
             t = _ticketDAO.GetTicketByFlightId((int)flight.ID);
             _ticketDAO.Remove(t);
         }
         if (flight.REMAINING_TICKETS == 0)
         {
             _flightDAO = new FlightDAOMSSQL();
             _flightDAO.Remove(flight);
         }
     }
 }
Ejemplo n.º 14
0
        public IHttpActionResult CancelTicket([FromUri] int ticketid)
        {
            LoginToken <Customer>  customerToken = (LoginToken <Customer>)Request.Properties["customerToken"];
            LoggedInCustomerFacade custFacade    = (LoggedInCustomerFacade)Request.Properties["customerFacade"];

            TicketDAOMSSQL ticketDAO = new TicketDAOMSSQL();
            Ticket         ticket    = ticketDAO.Get(ticketid);

            if (ticket == null || ticket.ID <= 0)
            {
                return(NotFound());
            }
            try
            {
                custFacade.CancelTicket(customerToken, ticket);
                return(Ok());
            }
            catch (Exception e)
            {
                return(Content(HttpStatusCode.NotAcceptable, e.Message));
            }
        }
Ejemplo n.º 15
0
        public void PurchaseTicket_OutOfTickets_Test()
        {
            t.ClearTables();
            t.FillDBForTest();

            AirlineCompany a = new AirlineCompany("airfrance", "airfrance", "134567", t.adminFacade.GetCountryByName(t.adminToken, "Israel").ID);

            t.adminFacade.CreateNewAirline(t.adminToken, a);
            t.airLineToken.User = a;

            Flight flight = new Flight(a.ID, a.CountryCode, a.CountryCode, new DateTime(2019, 10, 10), new DateTime(2019, 10, 10), 0);

            t.airlineFacade.CreateFlight(t.airLineToken, flight);

            Customer c = new Customer("Einat", "Mor", "Einat123", "191919", "Katzenelson", "0545552809", "000004400");

            t.adminFacade.CreateNewCustomer(t.adminToken, c);
            t.customerToken.User = c;

            t.customerFacade.PurchaseTicket(t.customerToken, flight);
            TicketDAOMSSQL ticketDAOMSSQL = new TicketDAOMSSQL();
        }
        public void TestInitialize()
        {
            airlineDAO = new AirlineDAOMSSQL();
            AirlineDAOMSSQL._connectionString = MyConfig._replicaConnectionString;
            ticketDAO = new TicketDAOMSSQL();
            TicketDAOMSSQL._connectionString = MyConfig._replicaConnectionString;
            flightDAO = new FlightDAOMSSQL();
            FlightDAOMSSQL._connectionString = MyConfig._replicaConnectionString;
            administratorDAO = new AdministratorDAOMSSQL();
            AdministratorDAOMSSQL._connectionString = MyConfig._replicaConnectionString;
            customerDAO = new CustomerDAOMSSQL();
            CustomerDAOMSSQL._connectionString = MyConfig._replicaConnectionString;
            countryDAO = new CountryDAOMSSQL();
            CountryDAOMSSQL._connectionString = MyConfig._replicaConnectionString;
            centerSystem = FlightCenterSystem.GetInstance();

            airlineDAO.RemoveAllReplica();
            ticketDAO.RemoveAllReplica();
            countryDAO.RemoveAllReplica();
            flightDAO.RemoveAllReplica();
            customerDAO.RemoveAllReplica();
            administratorDAO.RemoveAllReplica();
        }
Ejemplo n.º 17
0
        public void TestInitialize()
        {
            airlineDAO = new AirlineDAOMSSQL();
            AirlineDAOMSSQL._connectionString = MyConfig._replicaConnectionString;
            ticketDAO = new TicketDAOMSSQL();
            TicketDAOMSSQL._connectionString = MyConfig._replicaConnectionString;
            flightDAO = new FlightDAOMSSQL();
            FlightDAOMSSQL._connectionString = MyConfig._replicaConnectionString;
            administratorDAO = new AdministratorDAOMSSQL();
            AdministratorDAOMSSQL._connectionString = MyConfig._replicaConnectionString;
            customerDAO = new CustomerDAOMSSQL();
            CustomerDAOMSSQL._connectionString = MyConfig._replicaConnectionString;
            countryDAO = new CountryDAOMSSQL();
            CountryDAOMSSQL._connectionString = MyConfig._replicaConnectionString;

            airlineDAO.RemoveAllReplica();
            ticketDAO.RemoveAllReplica();
            countryDAO.RemoveAllReplica();
            flightDAO.RemoveAllReplica();
            customerDAO.RemoveAllReplica();
            administratorDAO.RemoveAllReplica();

            facade = new AnnonymousUserFacadeMSSQL();
        }
Ejemplo n.º 18
0
        public void TestCustomerFacade()
        {
            ResetWhatIsNeeded();
            FlyingCenterSystem flyingCenterSystem = FlyingCenterSystem.GetFlyingCenterSystem();

            //sign in as a airline company
            LoginToken <AirlineCompany> companyLoginToken     = flyingCenterSystem.AttemptLoginAirlineCompany("company", "company");
            LoggedInAirlineFacade       loggedInAirlineFacade = (LoggedInAirlineFacade)flyingCenterSystem.GetFacade(companyLoginToken);

            //create 4 flights
            DateTime now = DateTime.Now;

            loggedInAirlineFacade.CreateFlight(companyLoginToken,
                                               new Flight(-1, companyLoginToken.User.ID, 1, 3,
                                                          now.AddHours(1), now.AddHours(2), 10, 10));
            loggedInAirlineFacade.CreateFlight(companyLoginToken,
                                               new Flight(-1, companyLoginToken.User.ID, 1, 3,
                                                          now.AddHours(2), now.AddHours(3), 10, 10));
            loggedInAirlineFacade.CreateFlight(companyLoginToken,
                                               new Flight(-1, companyLoginToken.User.ID, 1, 3,
                                                          now.AddHours(3), now.AddHours(4), 10, 10));
            loggedInAirlineFacade.CreateFlight(companyLoginToken,
                                               new Flight(-1, companyLoginToken.User.ID, 1, 3,
                                                          now.AddHours(4), now.AddHours(5), 10, 10));

            IList <Flight> flights = loggedInAirlineFacade.GetFlightsByDestinationCountry(3);

            //login as the customer
            LoginToken <Customer>  customer = flyingCenterSystem.AttemptLoginCustomer("customer", "customer");
            LoggedInCustomerFacade loggedInCustomerFacade = (LoggedInCustomerFacade)flyingCenterSystem.GetFacade(customer);

            //buy a ticket for 4 flights
            loggedInCustomerFacade.PurchaseTicket(customer, flights[0]);
            loggedInCustomerFacade.PurchaseTicket(customer, flights[1]);
            loggedInCustomerFacade.PurchaseTicket(customer, flights[2]);
            loggedInCustomerFacade.PurchaseTicket(customer, flights[3]);

            TicketDAOMSSQL _ticketDAO = new TicketDAOMSSQL();
            IList <Ticket> tickets    = _ticketDAO.GetAll();

            Assert.IsTrue(LookForTicket(tickets, customer.User.ID, flights[0].ID));
            Assert.IsTrue(LookForTicket(tickets, customer.User.ID, flights[1].ID));
            Assert.IsTrue(LookForTicket(tickets, customer.User.ID, flights[2].ID));
            Assert.IsTrue(LookForTicket(tickets, customer.User.ID, flights[3].ID));

            Assert.AreEqual(4, loggedInCustomerFacade.GetAllMyFlights(customer).Count);

            loggedInCustomerFacade.CancelTicket(customer, tickets[0]);
            loggedInCustomerFacade.CancelTicket(customer, tickets[1]);
            loggedInCustomerFacade.CancelTicket(customer, tickets[2]);
            loggedInCustomerFacade.CancelTicket(customer, tickets[3]);

            tickets = _ticketDAO.GetAll();
            Assert.IsTrue(tickets.Count == 0);

            flights = loggedInAirlineFacade.GetFlightsByDestinationCountry(3);

            Assert.IsTrue(flights[0].RemainingTickets == 10);
            Assert.IsTrue(flights[1].RemainingTickets == 10);
            Assert.IsTrue(flights[2].RemainingTickets == 10);
            Assert.IsTrue(flights[3].RemainingTickets == 10);
        }
 public Tickets GetTicketByFlightId(int id)
 {
     _ticketDAO = new TicketDAOMSSQL();
     return(_ticketDAO.GetTicketByFlightId(id));
 }
 public void AddTicket(Tickets ticket)
 {
     _ticketDAO = new TicketDAOMSSQL();
     _ticketDAO.Add(ticket);
 }
Ejemplo n.º 21
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);
        }