public MainWindowViewModel()
        {
            FlightNumber = 0;

            facade = FlightCenterSystem.GetInstacne().GetAnonymousFacade();

            BuyCommand = new DelegateCommand(() => { MessageBox.Show("Buying ticket! yeah!"); }, () => { return(MyFlight != null && MyFlight.Vacancy > 0); });

            SearchFlightCommand = new DelegateCommand(() => {
                MyFlight = facade.GetFlightById(FlightNumber);

                PropertyChanged(this, new PropertyChangedEventArgs("MyFlight"));

                BuyCommand.RaiseCanExecuteChanged();
            }, () => { return(true); });
        }
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            if (actionContext.Request.Headers.Authorization == null)
            {
                actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized,
                                                                              "you must send user name + pwd in basic authentication");
                return;
            }
            string basicAuthBase64Token = actionContext.Request.Headers.Authorization.Parameter;

            string decodedString = Encoding.UTF8.GetString(Convert.FromBase64String(basicAuthBase64Token)); // itay:12345

            string[] authParams = decodedString.Split(':');

            string username = authParams[0];
            string pwd      = authParams[1];

            ILoginToken token = FlightCenterSystem.Login(username, pwd, out BaseFacade facade);

            // checked if facade/token is null

            // 1 examine the token
            //if (token is LoginToken<Administrator>)
            if (facade is AdminFacade)
            {
                // ok to go
                actionContext.Request.Properties["facade"] = facade;
                actionContext.Request.Properties["token"]  = token;
            }
            else
            {
                actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized,
                                                                              "User is not admin. please try again");
            }

            if (username.ToUpper() == "itay".ToUpper() && pwd == "1234")
            {
                actionContext.Request.Properties["username"] = username;
                return;
            }
        }
        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();
        }
Esempio n. 4
0
        public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.UseStartup <Startup>();
        }).ConfigureServices((hostContext, services) =>
        {
            if (hostContext.HostingEnvironment.EnvironmentName == "Test")
            {
                FlightsManagmentSystemConfig.Instance.Init("FlightsManagmentSystemTests.Config.json");
            }
            else
            {
                FlightsManagmentSystemConfig.Instance.Init();
            }

            services.AddSingleton(FlightsManagmentSystemConfig.Instance);
            services.AddSingleton <IFlightCenterSystem>(FlightCenterSystem.GetInstance());
        })
        .ConfigureLogging(builder =>
        {
            builder.SetMinimumLevel(LogLevel.Debug);
            builder.AddLog4Net("Log4Net.config");
        });
Esempio n. 5
0
        static AirlineFacadeController()
        {
            FlightCenterSystem fcs = FlightCenterSystem.GetInstance();

            facade = fcs.GetFacade(new LoginToken <AirlineCompany>()) as LoggedInAirlineFacade;
        }
        static AdministratorFacadeController()
        {
            FlightCenterSystem fcs = FlightCenterSystem.GetInstance();

            facade = fcs.GetFacade(new LoginToken <Administrator>()) as LoggedInAdministratorFacade;
        }
Esempio n. 7
0
        static AnonymousFacadeController()
        {
            FlightCenterSystem fcs = FlightCenterSystem.GetInstance();

            facade = fcs.GetFacade(new LoginToken <Anonymous>()) as AnonymousUserFacade;
        }
Esempio n. 8
0
        public void AdministratorFacadeTest()
        {
            new TestFacade().DeleteAllTables();

            FlightCenterSystem fcs = FlightCenterSystem.GetInstance();

            LoginToken <Administrator> loginToken = new LoginToken <Administrator>()
            {
                User = new Administrator()
            };

            LoggedInAdministratorFacade facade = fcs.GetFacade <Administrator>(loginToken) as LoggedInAdministratorFacade;

            #region Create New Airline

            Assert.ThrowsException <InvalidTokenException>(() =>
            {
                facade.CreateNewAirline(null, new AirlineCompany("name", "username", "*****@*****.**", "123", 1));
                // Token is null, should cause an exception to be thrown
            });

            Assert.ThrowsException <InvalidAirlineCompanyException>(() =>
            {
                facade.CreateNewAirline(loginToken, new AirlineCompany("", "username", "*****@*****.**", "123", 1));
                // No name, should cause an exception to be thrown
            });

            Assert.ThrowsException <InvalidAirlineCompanyException>(() =>
            {
                facade.CreateNewAirline(loginToken, new AirlineCompany("name", "", "*****@*****.**", "123", 1));
                // No user name, should cause an exception to be thrown
            });

            Assert.ThrowsException <InvalidAirlineCompanyException>(() =>
            {
                facade.CreateNewAirline(loginToken, new AirlineCompany("name", "username", "", "123", 1));
                // No email, should cause an exception to be thrown
            });

            Assert.ThrowsException <InvalidAirlineCompanyException>(() =>
            {
                facade.CreateNewAirline(loginToken, new AirlineCompany("name", "username", "*****@*****.**", "", 1));
                // No password, should cause an exception to be thrown
            });

            Assert.ThrowsException <InvalidAirlineCompanyException>(() =>
            {
                facade.CreateNewAirline(loginToken, new AirlineCompany("name", "username", "*****@*****.**", "123", 0));
                // Origin country ID cannot be zero (null), should cause an exception to be thrown
            });

            Assert.ThrowsException <CountryNotFoundException>(() =>
            {
                facade.CreateNewAirline(loginToken, new AirlineCompany("name", "username", "*****@*****.**", "123", 500));
                // Origin country ID does not exist, should cause an exception to be thrown
            });


            Assert.ThrowsException <UserNameAlreadyExistException>(() =>
            {
                facade.CreateNewAirline(loginToken, new AirlineCompany("name", "admin", "*****@*****.**", "123", 1));
                // User name is taken by the admin, should cause an exception to be thrown
            });

            Assert.ThrowsException <UserNameAlreadyExistException>(() =>
            {
                facade.CreateNewAirline(loginToken, new AirlineCompany("Sky Team", "skt", "*****@*****.**", "666", 1));
                facade.CreateNewAirline(loginToken, new AirlineCompany("Sky Tour", "skt", "*****@*****.**", "777", 1));
                // User name is taken, should cause an exception to be thrown
            });

            Assert.ThrowsException <AirlineCompanyNameAlreadyExistException>(() =>
            {
                facade.CreateNewAirline(loginToken, new AirlineCompany("Air One", "airone", "*****@*****.**", "555", 1));
                facade.CreateNewAirline(loginToken, new AirlineCompany("Air One", "airy", "*****@*****.**", "333", 1));
                // Company name already exist, should cause an exception to be thrown
            });

            new TestFacade().DeleteAllTables();

            facade.CreateNewAirline(loginToken, new AirlineCompany("One World", "one", "*****@*****.**", "777", 1));
            IList <AirlineCompany> airlines = facade.GetAllAirlineCompanies();

            Assert.AreEqual(airlines[0].Name, "One World");
            Assert.AreEqual(airlines[0].UserName, "one");
            Assert.AreEqual(airlines[0].Email, "*****@*****.**");
            Assert.AreEqual(airlines[0].Password, "777");
            Assert.AreEqual(airlines[0].CountryCode, 1);

            #endregion

            #region Create New Customer

            Assert.ThrowsException <InvalidTokenException>(() =>
            {
                facade.CreateNewCustomer(null, new Customer("John", "Doe", "jd", "*****@*****.**", "j123", "unknown", "555", "4580"));
                // Token is null, should cause an exception to be thrown
            });

            Assert.ThrowsException <InvalidCustomerException>(() =>
            {
                facade.CreateNewCustomer(loginToken, new Customer("", "Doe", "jd", "*****@*****.**", "j123", "unknown", "555", "4580"));
                // No first name, should cause an exception to be thrown
            });

            Assert.ThrowsException <InvalidCustomerException>(() =>
            {
                facade.CreateNewCustomer(loginToken, new Customer("John", "", "jd", "*****@*****.**", "j123", "unknown", "555", "4580"));
                // No last name, should cause an exception to be thrown
            });

            Assert.ThrowsException <InvalidCustomerException>(() =>
            {
                facade.CreateNewCustomer(loginToken, new Customer("John", "Doe", "", "*****@*****.**", "j123", "unknown", "555", "4580"));
                // No user name, should cause an exception to be thrown
            });

            Assert.ThrowsException <InvalidCustomerException>(() =>
            {
                facade.CreateNewCustomer(loginToken, new Customer("John", "Doe", "jd", "", "j123", "unknown", "555", "4580"));
                // No email, should cause an exception to be thrown
            });

            Assert.ThrowsException <InvalidCustomerException>(() =>
            {
                facade.CreateNewCustomer(loginToken, new Customer("John", "Doe", "jd", "*****@*****.**", "", "unknown", "555", "4580"));
                // No password, should cause an exception to be thrown
            });

            Assert.ThrowsException <UserNameAlreadyExistException>(() =>
            {
                facade.CreateNewCustomer(loginToken, new Customer("John", "Doe", "jd", "*****@*****.**", "j123", "unknown", "555", "4580"));
                facade.CreateNewCustomer(loginToken, new Customer("Jane", "Dean", "jd", "*****@*****.**", "j999", "NY", "458", "4580"));
                // User name is already taken, should cause an exception to be thrown
            });

            new TestFacade().DeleteAllTables();

            facade.CreateNewCustomer(loginToken, new Customer("John", "Doe", "jd", "*****@*****.**", "j123", "unknown", "555", "4580"));
            IList <Customer> customers = facade.GetAllCustomers(loginToken);

            Assert.AreEqual(customers[0].FirstName, "John");
            Assert.AreEqual(customers[0].LastName, "Doe");
            Assert.AreEqual(customers[0].UserName, "jd");
            Assert.AreEqual(customers[0].Email, "*****@*****.**");
            Assert.AreEqual(customers[0].Password, "j123");
            Assert.AreEqual(customers[0].Address, "unknown");
            Assert.AreEqual(customers[0].PhoneNo, "555");
            Assert.AreEqual(customers[0].CreditCardNo, "4580");

            #endregion

            #region Update airline details

            Assert.ThrowsException <InvalidTokenException>(() =>
            {
                facade.CreateNewAirline(loginToken, new AirlineCompany("Air One", "airone", "*****@*****.**", "555", 1));
                airlines = facade.GetAllAirlineCompanies();

                facade.UpdateAirlineDetails(null, new AirlineCompany("Air two", "airtwo", "*****@*****.**", "555", 1)
                {
                    Id = airlines[0].Id
                });
                // Token is null, should cause an exception to be thrown
            });

            facade.UpdateAirlineDetails(loginToken, new AirlineCompany("Air two", "airtwo", "*****@*****.**", "555", 1)
            {
                Id = airlines[0].Id
            });
            airlines = facade.GetAllAirlineCompanies();

            Assert.AreEqual(airlines[0].Name, "Air two");
            Assert.AreEqual(airlines[0].UserName, "airtwo");
            Assert.AreEqual(airlines[0].Email, "*****@*****.**");
            Assert.AreEqual(airlines[0].Password, "555");
            Assert.AreEqual(airlines[0].CountryCode, 1);

            new TestFacade().DeleteAllTables();

            #endregion

            #region Update customer details

            Assert.ThrowsException <InvalidTokenException>(() =>
            {
                facade.CreateNewCustomer(loginToken, new Customer("John", "Doe", "jd", "*****@*****.**", "j123", "unknown", "555", "4580"));
                customers = facade.GetAllCustomers(loginToken);

                facade.UpdateCustomerDetails(null, new Customer("Jane", "Darwin", "jd", "*****@*****.**", "j123", "CA", "255", "4580")
                {
                    Id = customers[0].Id
                });
                // Token is null, should cause an exception to be thrown
            });

            facade.UpdateCustomerDetails(loginToken, new Customer("Jane", "Darwin", "jd", "*****@*****.**", "j123", "CA", "255", "4580")
            {
                Id = customers[0].Id
            });
            customers = facade.GetAllCustomers(loginToken);

            Assert.AreEqual(customers[0].FirstName, "Jane");
            Assert.AreEqual(customers[0].LastName, "Darwin");
            Assert.AreEqual(customers[0].UserName, "jd");
            Assert.AreEqual(customers[0].Email, "*****@*****.**");
            Assert.AreEqual(customers[0].Password, "j123");
            Assert.AreEqual(customers[0].Address, "CA");
            Assert.AreEqual(customers[0].PhoneNo, "255");
            Assert.AreEqual(customers[0].CreditCardNo, "4580");

            #endregion

            new TestFacade().DeleteAllTables();

            #region Remove airline

            facade.CreateNewAirline(loginToken, new AirlineCompany("Air One", "airone", "*****@*****.**", "555", 1));
            airlines = facade.GetAllAirlineCompanies();

            Assert.ThrowsException <InvalidTokenException>(() =>
            {
                facade.RemoveAirline(null, airlines[0]);
                // Token is null, should cause an exception to be thrown
            });

            facade.RemoveAirline(loginToken, airlines[0]);
            airlines = facade.GetAllAirlineCompanies();

            Assert.AreEqual(airlines.Count, 0);

            #endregion

            #region Remove customer

            facade.CreateNewCustomer(loginToken, new Customer("John", "Doe", "jd", "*****@*****.**", "j123", "unknown", "555", "4580"));
            customers = facade.GetAllCustomers(loginToken);

            Assert.ThrowsException <InvalidTokenException>(() =>
            {
                facade.RemoveCustomer(null, customers[0]);
                // Token is null, should cause an exception to be thrown
            });

            facade.RemoveCustomer(loginToken, customers[0]);
            customers = facade.GetAllCustomers(loginToken);

            Assert.AreEqual(customers.Count, 0);

            #endregion

            #region Get all customers

            facade.CreateNewAirline(loginToken, new AirlineCompany("Air One", "airone", "*****@*****.**", "555", 1));
            facade.CreateNewAirline(loginToken, new AirlineCompany("Fly Far", "flyfar", "*****@*****.**", "931", 1));

            airlines = facade.GetAllAirlineCompanies();

            Assert.AreEqual(airlines[0].Name, "Air One");
            Assert.AreEqual(airlines[0].UserName, "airone");
            Assert.AreEqual(airlines[0].Email, "*****@*****.**");
            Assert.AreEqual(airlines[0].Password, "555");
            Assert.AreEqual(airlines[0].CountryCode, 1);

            Assert.AreEqual(airlines[1].Name, "Fly Far");
            Assert.AreEqual(airlines[1].UserName, "flyfar");
            Assert.AreEqual(airlines[1].Email, "*****@*****.**");
            Assert.AreEqual(airlines[1].Password, "931");
            Assert.AreEqual(airlines[1].CountryCode, 1);

            #endregion
        }
Esempio n. 9
0
        public void G_CustomerFacadeTest()
        {
            new TestFacade().DeleteAllTables();

            Customer testCustomer = new Customer("Joe", "Fin", "jf", "*****@*****.**", "111", "China", "100", "4580");

            LoginToken <Administrator> token = new LoginToken <Administrator>()
            {
                User = new Administrator()
            };

            new LoggedInAdministratorFacade().CreateNewCustomer(token, testCustomer);

            testCustomer.Id = new LoggedInAdministratorFacade().GetAllCustomers(token)[0].Id;

            FlightCenterSystem fcs = FlightCenterSystem.GetInstance();

            LoginToken <Customer> loginToken = new LoginToken <Customer>()
            {
                User = testCustomer
            };

            LoggedInCustomerFacade facade = fcs.GetFacade <Customer>(loginToken) as LoggedInCustomerFacade;

            // Adding some data for testing:

            new LoggedInAdministratorFacade().CreateNewAirline(token, new AirlineCompany("Air One", "airone", "*****@*****.**", "555", 1));

            IList <AirlineCompany> airlines = facade.GetAllAirlineCompanies();

            LoginToken <AirlineCompany> airlineToken = new LoginToken <AirlineCompany>()
            {
                User = new AirlineCompany()
            };

            new LoggedInAirlineFacade().CreateFlight(airlineToken, new Flight(airlines[0].Id, 1, 2, new DateTime(2011, 11, 11), new DateTime(2010, 10, 10), 5, 99));
            new LoggedInAirlineFacade().CreateFlight(airlineToken, new Flight(airlines[0].Id, 2, 3, new DateTime(2012, 12, 12), new DateTime(2011, 11, 11), 0, 99));
            new LoggedInAirlineFacade().CreateFlight(airlineToken, new Flight(airlines[0].Id, 2, 3, new DateTime(2012, 12, 12), new DateTime(2012, 12, 12), 1, 99));
            new LoggedInAirlineFacade().CreateFlight(airlineToken, new Flight(airlines[0].Id, 2, 3, new DateTime(2010, 10, 10), new DateTime(2010, 10, 10), 10, 99));

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

            #region Purchase ticket

            Assert.ThrowsException <InvalidTokenException>(() =>
            {
                facade.PurchaseTicket(null, flights[0].Id);
                // Null token, should cause an exception to be thrown
            });

            Assert.ThrowsException <NoTicketsRemainingException>(() =>
            {
                facade.PurchaseTicket(loginToken, flights[1].Id);
                // A flight with no tickets left, should cause an exception to be thrown
            });

            facade.PurchaseTicket(loginToken, flights[0].Id);

            IList <Ticket> tickets = new LoggedInAdministratorFacade().GetAllTickets(token);
            flights = facade.GetAllFlights();

            Assert.AreEqual(tickets[0].CustomerId, testCustomer.Id);
            Assert.AreEqual(tickets[0].FlightId, flights[0].Id);

            Assert.AreEqual(flights[0].RemainingTickets, 4);

            Assert.ThrowsException <OneTicketForCustomerOnlyException>(() =>
            {
                facade.PurchaseTicket(loginToken, flights[0].Id);
                // A customer can buy only one ticket per flight, should cause an exception to be thrown
            });

            #endregion

            #region Cancel ticket

            Assert.ThrowsException <InvalidTokenException>(() =>
            {
                facade.CancelTicket(null, tickets[0].Id);
                // Null token, should cause an exception to be thrown
            });

            facade.CancelTicket(loginToken, tickets[0].Id);

            tickets = new LoggedInAdministratorFacade().GetAllTickets(token);

            flights = facade.GetAllFlights();

            Assert.AreEqual(tickets.Count, 0);

            Assert.AreEqual(flights[0].RemainingTickets, 5);

            #endregion

            #region Get all my flights

            facade.PurchaseTicket(loginToken, flights[0].Id);
            facade.PurchaseTicket(loginToken, flights[3].Id);

            flights = facade.GetAllMyFlights(loginToken);

            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(2011, 11, 11));
            Assert.AreEqual(flights[0].LandingTime, new DateTime(2010, 10, 10));
            Assert.AreEqual(flights[0].RemainingTickets, 4);

            Assert.AreEqual(flights[1].AirlineCompanyId, airlines[0].Id);
            Assert.AreEqual(flights[1].OriginCountryCode, 2);
            Assert.AreEqual(flights[1].DestinationCountryCode, 3);
            Assert.AreEqual(flights[1].DepartureTime, new DateTime(2010, 10, 10));
            Assert.AreEqual(flights[1].LandingTime, new DateTime(2010, 10, 10));
            Assert.AreEqual(flights[1].RemainingTickets, 9);

            #endregion
        }
Esempio n. 10
0
        public void AirlineFacadeTest()
        {
            new TestFacade().DeleteAllTables();

            AirlineCompany testAirline = new AirlineCompany("Air One", "airone", "*****@*****.**", "555", 1);

            LoginToken <Administrator> token = new LoginToken <Administrator>()
            {
                User = new Administrator()
            };

            new LoggedInAdministratorFacade().CreateNewAirline(token, testAirline);

            testAirline.Id = new AnonymousUserFacade().GetAllAirlineCompanies()[0].Id;

            FlightCenterSystem fcs = FlightCenterSystem.GetInstance();

            LoginToken <AirlineCompany> loginToken = new LoginToken <AirlineCompany>()
            {
                User = testAirline
            };

            LoggedInAirlineFacade facade = fcs.GetFacade <AirlineCompany>(loginToken) as LoggedInAirlineFacade;

            #region Create flight

            IList <AirlineCompany> airlines = new AnonymousUserFacade().GetAllAirlineCompanies();

            Assert.ThrowsException <InvalidTokenException>(() =>
            {
                facade.CreateFlight(null, new Flight(airlines[0].Id, 1, 2, DateTime.Now, DateTime.Now.AddHours(3), 5, 99));
                // Null token, should cause an exception to be thrown
            });

            // Airline company constraints:

            Assert.ThrowsException <InvalidFlightException>(() =>
            {
                facade.CreateFlight(loginToken, new Flight(0, 1, 2, new DateTime(2011, 11, 11), new DateTime(2011, 11, 11), 5, 99));
                // Airline company Id is 0, should cause an exception to be thrown
            });

            Assert.ThrowsException <AirlineCompanyNotFoundException>(() =>
            {
                facade.CreateFlight(loginToken, new Flight(9999, 1, 2, new DateTime(2011, 11, 11), new DateTime(2011, 11, 11), 5, 99));
                // Airline company Id doesn't exist, should cause an exception to be thrown from the sql
            });

            // Origin country constraints:

            Assert.ThrowsException <InvalidFlightException>(() =>
            {
                facade.CreateFlight(loginToken, new Flight(airlines[0].Id, 0, 2, new DateTime(2011, 11, 11), new DateTime(2011, 11, 11), 5, 99));
                // Origin country Id is 0, should cause an exception to be thrown
            });

            Assert.ThrowsException <CountryNotFoundException>(() =>
            {
                facade.CreateFlight(loginToken, new Flight(airlines[0].Id, 9999, 2, new DateTime(2011, 11, 11), new DateTime(2011, 11, 11), 5, 99));
                // Origin country Id doesn't exist, should cause an exception to be thrown from the sql
            });

            // Destination country constraints:

            Assert.ThrowsException <InvalidFlightException>(() =>
            {
                facade.CreateFlight(loginToken, new Flight(airlines[0].Id, 1, 0, new DateTime(2011, 11, 11), new DateTime(2011, 11, 11), 5, 99));
                // Destination country Id is 0, should cause an exception to be thrown
            });

            Assert.ThrowsException <CountryNotFoundException>(() =>
            {
                facade.CreateFlight(loginToken, new Flight(airlines[0].Id, 1, 9999, new DateTime(2011, 11, 11), new DateTime(2011, 11, 11), 5, 99));
                // Destination country Id doesn't exist, should cause an exception to be thrown from the sql
            });

            // Flight time constraints:

            Assert.ThrowsException <InvalidFlightException>(() =>
            {
                facade.CreateFlight(loginToken, new Flight(airlines[0].Id, 1, 2, new DateTime(), new DateTime(2011, 11, 11), 5, 99));
                // No departure time, should cause an exception to be thrown
            });

            Assert.ThrowsException <InvalidFlightException>(() =>
            {
                facade.CreateFlight(loginToken, new Flight(airlines[0].Id, 1, 2, new DateTime(2011, 11, 11), new DateTime(), 5, 99));
                // No landing time, should cause an exception to be thrown
            });

            int yearNow  = DateTime.Now.Year;
            int monthNow = DateTime.Now.Month;
            int dayNow   = DateTime.Now.Day;

            facade.CreateFlight(loginToken, new Flight(airlines[0].Id, 1, 2, new DateTime(2012, 12, 12), new DateTime(2012, 12, 12), 5, 120));
            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(2012, 12, 12));
            Assert.AreEqual(flights[0].LandingTime, new DateTime(2012, 12, 12));
            Assert.AreEqual(flights[0].RemainingTickets, 5);
            Assert.AreEqual(flights[0].TicketPrice, 120);

            #endregion

            #region Update flight

            Assert.ThrowsException <InvalidTokenException>(() =>
            {
                facade.UpdateFlight(null, new Flight(airlines[0].Id, 3, 4, new DateTime(yearNow, monthNow, dayNow), new DateTime(yearNow, monthNow, dayNow), 10, 99));
                // Null token, should cause an exception to be thrown
            });

            flights = facade.GetAllFlights();
            facade.UpdateFlight(loginToken, new Flight(airlines[0].Id, 2, 3, new DateTime(yearNow, monthNow, dayNow), new DateTime(yearNow, monthNow, dayNow), 10, 99)
            {
                Id = flights[0].Id
            });

            flights = facade.GetAllFlights();

            Assert.AreEqual(flights[0].AirlineCompanyId, airlines[0].Id);
            Assert.AreEqual(flights[0].OriginCountryCode, 2);
            Assert.AreEqual(flights[0].DestinationCountryCode, 3);
            Assert.AreEqual(flights[0].DepartureTime, new DateTime(yearNow, monthNow, dayNow));
            Assert.AreEqual(flights[0].LandingTime, new DateTime(yearNow, monthNow, dayNow));
            Assert.AreEqual(flights[0].RemainingTickets, 10);
            Assert.AreEqual(flights[0].TicketPrice, 99);

            #endregion

            #region Change my password

            Assert.ThrowsException <InvalidTokenException>(() =>
            {
                facade.ChangeMyPassword(null, "555", "666");
                // Null token, should cause an exception to be thrown
            });

            Assert.ThrowsException <WrongPasswordException>(() =>
            {
                facade.ChangeMyPassword(loginToken, "444", "666");
                // wrong password, should cause an exception to be thrown
            });

            facade.ChangeMyPassword(loginToken, "555", "666");

            airlines = facade.GetAllAirlineCompanies();

            Assert.AreEqual(airlines[0].Password, "666");

            #endregion

            #region Modify airline details

            Assert.ThrowsException <InvalidTokenException>(() =>
            {
                facade.ModifyAirlineDetails(null, testAirline);
                // Null token, should cause an exception to be thrown
            });

            testAirline.Name = "Best Pilots";

            facade.ModifyAirlineDetails(loginToken, testAirline);
            airlines = facade.GetAllAirlineCompanies();

            Assert.AreEqual(airlines[0].Name, "Best Pilots");

            #endregion

            #region Get all my flights

            Assert.ThrowsException <InvalidTokenException>(() =>
            {
                facade.CreateFlight(null, new Flight(airlines[0].Id, 3, 4, new DateTime(2009, 9, 9), new DateTime(2009, 9, 9), 10, 99));
                // Null token, should cause an exception to be thrown
            });

            facade.CreateFlight(loginToken, new Flight(airlines[0].Id, 3, 4, new DateTime(yearNow, monthNow, dayNow), new DateTime(yearNow, monthNow, dayNow), 10, 99));

            flights = facade.GetAllMyFlights(loginToken);

            Assert.AreEqual(flights[0].AirlineCompanyId, airlines[0].Id);
            Assert.AreEqual(flights[0].OriginCountryCode, 2);
            Assert.AreEqual(flights[0].DestinationCountryCode, 3);
            Assert.AreEqual(flights[0].DepartureTime, new DateTime(yearNow, monthNow, dayNow));
            Assert.AreEqual(flights[0].LandingTime, new DateTime(yearNow, monthNow, dayNow));
            Assert.AreEqual(flights[0].RemainingTickets, 10);
            Assert.AreEqual(flights[0].TicketPrice, 99);

            Assert.AreEqual(flights[1].AirlineCompanyId, airlines[0].Id);
            Assert.AreEqual(flights[1].OriginCountryCode, 3);
            Assert.AreEqual(flights[1].DestinationCountryCode, 4);
            Assert.AreEqual(flights[1].DepartureTime, new DateTime(yearNow, monthNow, dayNow));
            Assert.AreEqual(flights[1].LandingTime, new DateTime(yearNow, monthNow, dayNow));
            Assert.AreEqual(flights[1].RemainingTickets, 10);
            Assert.AreEqual(flights[1].TicketPrice, 99);

            #endregion
        }
Esempio n. 11
0
        static CustomerFacadeController()
        {
            FlightCenterSystem fcs = FlightCenterSystem.GetInstance();

            facade = fcs.GetFacade(new LoginToken <Customer>()) as LoggedInCustomerFacade;
        }
Esempio n. 12
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
        }