public void PurchaseTicket() { Flights f = customerFacade.GetFlightById(1); Tickets a = customerFacade.PurchaseTicket(cus, f); Tickets ex = new Tickets(10, 1); Assert.AreEqual(ex, a); }
public void Purchase_And_Get_Ticket() { Execute_Test(() => { Flight flight = customer_facade.GetFlightById(1); int empty_seates_before_purchase = flight.RemainingTickets; Ticket ticket = customer_facade.PurchaseTicket(customer_token, flight); Assert.AreEqual(ticket.Id, 2); Ticket my_ticket = customer_facade.GetTicketById(customer_token, ticket.Id); TestData.CompareProps(ticket, my_ticket, true); flight = customer_facade.GetFlightById(1); int empty_seates_after_purchase = flight.RemainingTickets; Assert.AreEqual(empty_seates_before_purchase - 1, empty_seates_after_purchase); }); }
public void CustomerFacade_PurchaseTicket() { LoggedInCustomerFacade facade = FlyingCenterSystem.GetInstance().Login(TestResource.CUSTOMER_USERNAME, TestResource.CUSTOMER_PASSWORD, out LoginTokenBase login) as LoggedInCustomerFacade; Flight flight = facade.GetFlightById(7); Ticket ticket = facade.PurchaseTicket(login as LoginToken <Customer>, flight); Assert.AreEqual(7, ticket.FlightId); Assert.AreEqual(2, ticket.CustomerId); }
public IHttpActionResult PurchaseTicket([FromUri] int id) { GetLoginToken(); if (CustomerToken != null) { Flight flight = F.GetFlightById(id); F.PurchaseTicket(CustomerToken, flight); return(Ok($"{CustomerToken.User.LastName} {CustomerToken.User.FirstName} purchased ticket to flight:{flight.ID}")); } return(NotFound()); }
public IHttpActionResult GetFlightById(long flightId) { Flight flight = null; Action act = () => { flight = _loggedInCustomerFacade.GetFlightById(flightId); }; ProcessExceptions(act); if (flight == null) { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.NotFound, $"There is no flights for the flight with the ID {flightId} in the system."))); } return(ResponseMessage(Request.CreateResponse(HttpStatusCode.OK, flight))); }
public async Task <ActionResult <Flight> > GetFlightById(int flight_id) { FlightsCenterSystem.GetInstance().login(GetLoginToken().Name, GetLoginToken().Password, out LoginToken <Object> l, out FacadeBase f); facade = f as LoggedInCustomerFacade; Flight result = null; try { result = await Task.Run(() => facade.GetFlightById(flight_id)); } catch (IllegalFlightParameter ex) { return(StatusCode(400, $"{{ error: \"{ex.Message}\" }}")); } if (result.Id == 0) { return(StatusCode(204, $"{{there is no flight with the id \"{result.Id}\"}}")); } return(Ok(result)); }
public IHttpActionResult PurchaseTicket([FromUri] int flightid) { LoginToken <Customer> customerToken = (LoginToken <Customer>)Request.Properties["customerToken"]; LoggedInCustomerFacade custFacade = (LoggedInCustomerFacade)Request.Properties["customerFacade"]; Flight flight = custFacade.GetFlightById(flightid); if (flight == null || flight.ID <= 0) { return(NotFound()); } try { Ticket ticket = custFacade.PurchaseTicket(customerToken, flight); return(Ok(ticket)); } catch (Exception e) { return(Content(HttpStatusCode.NotAcceptable, e.Message)); } }
public IHttpActionResult PurchaseTicket([FromUri] int flightID) { if (flightID <= 0) { return(BadRequest()); } LoginToken <Customer> token = (LoginToken <Customer>)Request.Properties["User"]; LoggedInCustomerFacade facade = (LoggedInCustomerFacade)(FlyingCenterSystem.GetFlyingCenterSystem().GetFacade(token)); Flight flight = facade.GetFlightById(flightID); if (flight == null) { return(StatusCode(HttpStatusCode.NoContent)); } Ticket t = facade.PurchaseTicket(token, flight); if (t == null) { return(NotFound()); } return(Ok()); }
public void TestGetAllTicketsOfAirlineAndCancelFlight() { ResetWhatIsNeeded(); FlyingCenterSystem flyingCenterSystem = FlyingCenterSystem.GetFlyingCenterSystem(); //sign in as a airline company LoginToken <AirlineCompany> companyLoginToken = flyingCenterSystem.AttemptLoginAirlineCompany("company", "company"); LoggedInAirlineFacade loggedInAirlineFacade = (LoggedInAirlineFacade)flyingCenterSystem.GetFacade(companyLoginToken); //sign in as admin and add 2 customers LoginToken <Administrator> administratorLoginToken = flyingCenterSystem.AttemptLoginAdministrator("admin", "admin"); LoggedInAdministratorFacade loggedInAdministratorFacade = (LoggedInAdministratorFacade)flyingCenterSystem.GetFacade(administratorLoginToken); loggedInAdministratorFacade.CreateNewCustomer(administratorLoginToken, new Customer(-1, "john", "bravo", "john", "john", "places", "number", "anotherNumber")); loggedInAdministratorFacade.CreateNewCustomer(administratorLoginToken, new Customer(-1, "david", "david", "david", "david", "somewhere", "longnumber", "longnumber")); //create 4 flights DateTime now = DateTime.Now; loggedInAirlineFacade.CreateFlight(companyLoginToken, new Flight(-1, companyLoginToken.User.ID, 1, 2, now.AddHours(1), now.AddHours(2), 10, 10)); loggedInAirlineFacade.CreateFlight(companyLoginToken, new Flight(-1, companyLoginToken.User.ID, 1, 2, now.AddHours(2), now.AddHours(3), 10, 10)); loggedInAirlineFacade.CreateFlight(companyLoginToken, new Flight(-1, companyLoginToken.User.ID, 1, 2, now.AddHours(3), now.AddHours(4), 10, 10)); loggedInAirlineFacade.CreateFlight(companyLoginToken, new Flight(-1, companyLoginToken.User.ID, 1, 2, now.AddHours(4), now.AddHours(5), 10, 10)); IList <Flight> flights = loggedInAirlineFacade.GetFlightsByDestinationCountry(2); //login as 2 customers LoginToken <Customer> customer1 = flyingCenterSystem.AttemptLoginCustomer("john", "john"); LoginToken <Customer> customer2 = flyingCenterSystem.AttemptLoginCustomer("david", "david"); LoggedInCustomerFacade loggedInCustomerFacade = (LoggedInCustomerFacade)flyingCenterSystem.GetFacade(customer1); //purchase tickets loggedInCustomerFacade.PurchaseTicket(customer1, flights[0]); loggedInCustomerFacade.PurchaseTicket(customer1, flights[1]); loggedInCustomerFacade.PurchaseTicket(customer1, flights[2]); loggedInCustomerFacade.PurchaseTicket(customer1, flights[3]); loggedInCustomerFacade.PurchaseTicket(customer2, flights[0]); loggedInCustomerFacade.PurchaseTicket(customer2, flights[1]); //check to see if the flights data has been updated Flight flight0 = loggedInCustomerFacade.GetFlightById(flights[0].ID); Flight flight1 = loggedInCustomerFacade.GetFlightById(flights[1].ID); Flight flight2 = loggedInCustomerFacade.GetFlightById(flights[2].ID); Flight flight3 = loggedInCustomerFacade.GetFlightById(flights[3].ID); Assert.AreEqual(8, flight0.RemainingTickets); Assert.AreEqual(8, flight1.RemainingTickets); Assert.AreEqual(9, flight2.RemainingTickets); Assert.AreEqual(9, flight3.RemainingTickets); //check to see if tickets table has been updated IList <Ticket> tickets = loggedInAirlineFacade.GetAllTickets(companyLoginToken); Assert.IsTrue(LookForTicket(tickets, customer1.User.ID, flight0.ID)); Assert.IsTrue(LookForTicket(tickets, customer1.User.ID, flight1.ID)); Assert.IsTrue(LookForTicket(tickets, customer1.User.ID, flight2.ID)); Assert.IsTrue(LookForTicket(tickets, customer1.User.ID, flight3.ID)); Assert.IsTrue(LookForTicket(tickets, customer2.User.ID, flight0.ID)); Assert.IsTrue(LookForTicket(tickets, customer2.User.ID, flight1.ID)); //remove the flights loggedInAirlineFacade.CancelFlight(companyLoginToken, flight0); loggedInAirlineFacade.CancelFlight(companyLoginToken, flight1); loggedInAirlineFacade.CancelFlight(companyLoginToken, flight2); loggedInAirlineFacade.CancelFlight(companyLoginToken, flight3); tickets = loggedInAirlineFacade.GetAllTickets(companyLoginToken); Assert.IsTrue(tickets.Count == 0); flights = loggedInAirlineFacade.GetAllFlights(companyLoginToken); Assert.IsTrue(flights.Count == 0); }