public void Create_And_Get_List_Of_New_Airlines() { Execute_Test(() => { int country_id = administrator_facade.CreateNewCountry(administrator_token, TestData.Get_Countries_Data()[0]); int country_id2 = administrator_facade.CreateNewCountry(administrator_token, TestData.Get_Countries_Data()[2]); int country_id3 = administrator_facade.CreateNewCountry(administrator_token, TestData.Get_Countries_Data()[5]); AirlineCompany[] data = TestData.Get_AirlineCompanies_Data(); AirlineCompany[] demi_airline_companies = { data[0], data[1], data[2] }; demi_airline_companies[0].CountryId = country_id; demi_airline_companies[1].CountryId = country_id2; demi_airline_companies[2].CountryId = country_id3; for (int i = 0; i < demi_airline_companies.Length; i++) { long airline_company_id = administrator_facade.CreateNewAirlineCompany(administrator_token, demi_airline_companies[i]); Assert.AreEqual(airline_company_id, i + 1); demi_airline_companies[i].Id = airline_company_id; } IList <AirlineCompany> airline_companies_from_db = administrator_facade.GetAllAirlineCompanies(); Assert.AreEqual(demi_airline_companies.Length, airline_companies_from_db.Count); for (int i = 0; i < airline_companies_from_db.Count; i++) { TestData.CompareProps(airline_companies_from_db[i], demi_airline_companies[i]); } }); }
public override void OnAuthorization(HttpActionContext actionContext) { if (actionContext.Request.Headers.Authorization == null) { actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Forbidden, "You must login with user name and password!"); return; } string authenticationToken = actionContext.Request.Headers.Authorization.Parameter; string decodedAuthenticationToken = Encoding.UTF8.GetString(Convert.FromBase64String(authenticationToken)); string[] userNameAndPasswordArray = decodedAuthenticationToken.Split(':'); string userName = userNameAndPasswordArray[0]; string password = userNameAndPasswordArray[1]; ILoginTokenBase loginToken = FlyingCenterSystem.GetInstance().Login("admin", "9999"); adminFacade = new LoggedInAdministratorFacade(); List <AirlineCompany> airlines = adminFacade.GetAllAirlineCompanies(); foreach (AirlineCompany airline in airlines) { if (userName == airline.USER_NAME && password == airline.PASSWORD) { ILoginTokenBase AirlineUserLoginToken = FlyingCenterSystem.GetInstance().Login(userName, password); actionContext.Request.Properties["login-airlineCompany"] = airline; actionContext.Request.Properties["airlineCompany-login-token"] = AirlineUserLoginToken; } if (userName == airline.USER_NAME && password != airline.PASSWORD) { actionContext.Request.CreateResponse(HttpStatusCode.Forbidden, "Wrong password"); return; } } actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized, "You are not allowed!"); }
public void AirlineFacade_RemoveAirline() { LoggedInAdministratorFacade facade = FlyingCenterSystem.GetInstance().Login(TestResource.adminName, TestResource.adminPassWord, out LoginTokenBase login) as LoggedInAdministratorFacade; IList <AirlineCompany> airlines = facade.GetAllAirlineCompanies(); facade.RemoveAirline(login as LoginToken <Administrator>, airlines[0]); }
public async Task <ActionResult <List <Flight> > > GetAllAirlineCompanies() { FlightsCenterSystem.GetInstance().login(GetLoginToken().Name, GetLoginToken().Password, out LoginToken <Object> l, out FacadeBase f); facade = f as LoggedInAdministratorFacade; var result = await Task.Run(() => facade.GetAllAirlineCompanies()); return(StatusCode(200, result)); }
public IHttpActionResult RemoveAirline(int id) { GetLoginToken(); if (AdminToken != null) { AirlineCompany A = F.GetAllAirlineCompanies().ToList().Find(c => c.ID == id); if (A == null) { return(Content(HttpStatusCode.NotFound, $"{id} was not found")); } F.RemoveAirline(AdminToken, A); return(Ok($"{A.UserName} has been Removed")); } return(NotFound()); }
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); } } }
public void GetAllAirlineCompanies() { 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); List <AirlineCompany> airlineCompanies = (List <AirlineCompany>)myFacade.GetAllAirlineCompanies(); Assert.IsNotNull(airlineCompanies); }
// Create a random amount of flights public void CreateRandomFlights(int randomNum) { Random random = new Random(); Country randomCountry = new Country(); Country randomCountry2 = new Country(); AirLineCompany randomAirline = new AirLineCompany(); List <Flight> flights = new List <Flight>(); IList <Country> dbCountries = adminF.GetAllCountries(adminT); IList <AirLineCompany> dbAirlines = adminF.GetAllAirlineCompanies(); for (int i = 0; i < randomNum; i++) { randomCountry = dbCountries[random.Next(0, dbCountries.Count)]; randomAirline = dbAirlines[random.Next(0, dbAirlines.Count)]; dbCountries.Remove(randomCountry); randomCountry2 = dbCountries[random.Next(0, dbCountries.Count)]; Flight flight = new Flight { AirLineCompanyID = randomAirline.ID, OriginCountryCode = randomCountry.ID, DestinationCountryCode = randomCountry2.ID, DepartureTime = DateTime.Now, LandingTime = DateTime.Now, RemaniningTickets = random.Next(0, 200), }; foreach (Flight f in flights) { if (f.OriginCountryCode == flight.OriginCountryCode && f.DestinationCountryCode == flight.DestinationCountryCode) { i--; } else { flights.Add(flight); } } } }
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 }
public void RemoveAirline() { IList <AirlineCompany> airlines = Admin.GetAllAirlineCompanies(); Admin.RemoveAirline(AdminLogin, airlines[0]); }
public IEnumerable <AirlineCompany> GetByTextAndSender([FromUri] string text) { IEnumerable <AirlineCompany> result_text = facade.GetAllAirlineCompanies().Where(m => m.AirlineName.ToUpper().Contains(text.ToUpper())); return(result_text); }