public void GetAllMyFlights_UserHasNoFlights_ReturnsNullList() { LoggedInCustomerFacade customerFacade = GetCustomerFacade("coo", "6542"); List <Flight> flights = (List <Flight>)customerFacade.GetAllMyFlights(customerFacade.LoginToken); Assert.AreEqual(0, flights.Count); }
public void GetAllMyFlights_Test() { FlightCenterSystem.Instance.Login(out FacadeBase facadeBase, out ILoginToken token, "uri321", "ddvrew1"); LoginToken <Customer> loginToken = (LoginToken <Customer>)token; LoggedInCustomerFacade facade = (LoggedInCustomerFacade)facadeBase; IList <Flight> list = facade.GetAllMyFlights(loginToken); Assert.AreEqual(list.Count, 1); }
public void GetAllMyFlightsSendNullGetException() { FlightCenterSystem.Instance.Login(out FacadeBase facadeBase, out ILoginToken token, "uri321", "vzd474"); LoginToken <Customer> loginToken = (LoginToken <Customer>)token; LoggedInCustomerFacade facade = (LoggedInCustomerFacade)facadeBase; IList <Flight> list = facade.GetAllMyFlights(null); Assert.AreEqual(list.Count, 2); }
public IHttpActionResult GetAllMyFlights() { var loginToken = GetLoginToken(); if (loginToken == null) { return(Unauthorized()); } return(Json(_facade.GetAllMyFlights(loginToken))); }
public void GetAllFlights() { List <Flights> flights = (List <Flights>)customerFacade.GetAllMyFlights(cus); List <Flights> expected = new List <Flights>() { new Flights(1, 1, 3, 6, new DateTime(2021, 03, 26), new DateTime(2021, 04, 26), 10), new Flights(2, 2, 5, 2, new DateTime(2021, 01, 17), new DateTime(2021, 04, 17), 23) }; CollectionAssert.AreEqual(expected, flights); }
public void GetAllMyFlights_UserHasOneFlight_ReturnsListWithAllUsersFlights() { LoggedInCustomerFacade customerFacade = GetCustomerFacade("goo", "684321"); List <Flight> flights = (List <Flight>)customerFacade.GetAllMyFlights(customerFacade.LoginToken); Assert.AreEqual(1, flights.Count); foreach (Flight flight in flights) { Assert.IsNotNull(flight); } }
public async Task <ActionResult <List <Flight> > > GetAllMyFlights() { FlightsCenterSystem.GetInstance().login(GetLoginToken().Name, GetLoginToken().Password, out LoginToken <Object> l, out FacadeBase f); facade = f as LoggedInCustomerFacade; token_customer = GetLoginToken(); User u = new UserDAOPGSQL().GetAll().FirstOrDefault(_ => _.Password == token_customer.Password && _.Username == token_customer.Name); token_customer.User = new CustomerDAOPGSQL().GetAll().FirstOrDefault(_ => _.User_id == u.Id); var result = await Task.Run(() => facade.GetAllMyFlights(token_customer)); return(StatusCode(200, result)); }
public IHttpActionResult GetAllMyFlights() { LoginToken <Customer> customerToken = (LoginToken <Customer>)Request.Properties["customerToken"]; LoggedInCustomerFacade custFacade = (LoggedInCustomerFacade)Request.Properties["customerFacade"]; IList <Flight> flights = custFacade.GetAllMyFlights(customerToken); if (flights == null || flights.Count == 0) { return(NotFound()); } return(Ok(flights)); }
public IHttpActionResult GetAllMyFlights() { if (GetLoginToken() == null) { return(Content(HttpStatusCode.Unauthorized, "User must be customer")); } if (CustomerToken != null) { List <Flight> myFLights = F.GetAllMyFlights(CustomerToken).ToList(); return(Ok(myFLights)); } return(NotFound()); }
public IHttpActionResult GetMyFlights() { LoginToken <Customer> token = (LoginToken <Customer>)Request.Properties["User"]; LoggedInCustomerFacade facade = (LoggedInCustomerFacade)(FlyingCenterSystem.GetFlyingCenterSystem().GetFacade(token)); IList <Flight> flights = facade.GetAllMyFlights(token); if (flights.Count == 0) { return(NotFound()); } else { return(Ok(flights)); } }
public IActionResult GetAllMyFlights() { IActionResult result = SafeExecute(() => { int facadeIndex = RetriveFacadeIndex(); LoggedInCustomerFacade customerFacade = (LoggedInCustomerFacade)FlyingCenterSystem.FacadeList[facadeIndex]; List <Flight> flights = (List <Flight>)customerFacade.GetAllMyFlights(customerFacade.LoginToken); if (flights.Count < 1) { return(NoContent()); } return(Ok(flights)); }); return(result); }
public IHttpActionResult GetAllMyFlights() { GetLoginToken(); try { IList <Flight> flights = customerFacade.GetAllMyFlights(loginToken); if (flights.Count == 0) { return(NotFound()); } return(Ok(flights)); } 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); }
public void Purchase_And_Get_Two_Tickets_And_Two_Flights() { Execute_Test(() => { Flight flight = customer_facade.GetFlightById(1); Flight flight2 = customer_facade.GetFlightById(2); Ticket ticket = customer_facade.PurchaseTicket(customer_token, flight); Ticket ticket2 = customer_facade.PurchaseTicket(customer_token, flight2); Assert.AreEqual(ticket.Id, 2); Assert.AreEqual(ticket2.Id, 3); IList <Ticket> my_tickets = customer_facade.GetAllMyTickets(customer_token); Assert.AreEqual(my_tickets.Count, 2); TestData.CompareProps(my_tickets[0], ticket); TestData.CompareProps(my_tickets[1], ticket2); IList <Flight> my_flights = customer_facade.GetAllMyFlights(customer_token); Assert.AreEqual(my_flights[0], flight); Assert.AreEqual(my_flights[1], flight2); }); }
public void CustomerFacade_GetAllMyFlights_FlightsFound() { LoggedInCustomerFacade facade = FlyingCenterSystem.GetInstance().Login(TestResource.CUSTOMER_USERNAME, TestResource.CUSTOMER_PASSWORD, out LoginTokenBase login) as LoggedInCustomerFacade; IList <Flight> flights = new List <Flight>(); flights = facade.GetAllMyFlights(login as LoginToken <Customer>); Assert.AreNotEqual(flights, null); for (int i = 0; i < flights.Count; i++) { Assert.AreEqual(TestResource.FlightsId[i], flights[i].Id); Assert.AreEqual(TestResource.AirlineCompaniesId[i], flights[i].AirlineCompanyId); Assert.AreEqual(TestResource.OriginCountryCodes[i], flights[i].OriginCountryCode); Assert.AreEqual(TestResource.DestinationCountryCodes[i], flights[i].DestinationCountryCode); Assert.AreEqual(TestResource.Vacancies[i], flights[i].RemainingTickets); Assert.AreEqual(TestResource.DepartureTimes[i], flights[i].DepartureTime); Assert.AreEqual(TestResource.LandingTimes[i], flights[i].LandingTime); } }
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 void GetAllMyFlights() { facade.GetAllMyFlights(CustomerLogin); }
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 }