public void AirlineControllerCreateFlightAPI() { ILoggedInAdministratorFacade adminFacade = (ILoggedInAdministratorFacade)TestConfig.fcs.Login(AirlineProjectConfig.TEST_ADMIN_USERNAME, AirlineProjectConfig.TEST_ADMIN_PASSWORD, out ILoginToken adminToken); adminFacade.CreateNewAirline((LoginToken <Administrator>)adminToken, TestData.airline1); // ---------------------------------------------- HttpClient client = new HttpClient(); client.BaseAddress = new Uri(AirlineURL); // Add an Accept header for JSON format. client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); string airlineCreds = string.Format($"{TestData.airline1.UserName}:{TestData.airline1.Password}"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.Default.GetBytes(airlineCreds))); Flight newFlight = new Flight(0, 0, TestData.argentinaID, TestData.barbadosID, TestData.futureDate1, TestData.futureDate2, 200); HttpResponseMessage response = client.PostAsync("", new StringContent(JsonConvert.SerializeObject(newFlight), Encoding.Default, "application/json")).Result; // ----------------------------------------------------------------------------- IAnonymousUserFacade anonymousFacade = (IAnonymousUserFacade)TestConfig.fcs.Login("testAnonymous", "99999", out ILoginToken anonymousToken); IList <Flight> flights = anonymousFacade.GetAllFlights(); Assert.AreEqual(newFlight.DepartureTime, flights[0].DepartureTime); Assert.AreEqual(newFlight.DestinationCountryCode, flights[0].DestinationCountryCode); Assert.AreEqual(newFlight.LandingTime, flights[0].LandingTime); Assert.AreEqual(newFlight.OriginCountryCode, flights[0].OriginCountryCode); Assert.AreEqual(newFlight.RemainingTickets, flights[0].RemainingTickets); }
public IHttpActionResult GetAllFlights() { FlyingCenter = FlyingCenterSystem.GetInstance(); IAnonymousUserFacade anonymousUserFacade = FlyingCenter.GetFacede(null) as IAnonymousUserFacade; IList <Flight> flights = anonymousUserFacade.GetAllFlights(); if (flights.Count == 0) { return(NotFound()); } return(Ok(flights)); }
public IHttpActionResult GetAllFlights() { FCS = FlyingCenterSystem.GetInstance(); IAnonymousUserFacade af = FCS.GetFacade(null) as AnonymousUserFacade; IList <Flight> flighs = (List <Flight>)af.GetAllFlights(); if (flighs.Count == 0) { return(NotFound()); } return(Ok(flighs)); }
public IHttpActionResult GetFlightsByLandingDate(DateTime landingDate) { FCS = FlyingCenterSystem.GetInstance(); IAnonymousUserFacade af = FCS.GetFacade(null) as AnonymousUserFacade; IList <Flight> flights = (List <Flight>)af.GetAllFlights(); Flight flightByID = flights.FirstOrDefault(a => a.LandingTime == landingDate); if (flightByID == null) { return(NotFound()); } return(Ok(flightByID)); }
public IHttpActionResult GetFlightsByDestinationCountry(int countryCode) { FCS = FlyingCenterSystem.GetInstance(); IAnonymousUserFacade af = FCS.GetFacade(null) as AnonymousUserFacade; IList <Flight> flighs = (List <Flight>)af.GetAllFlights(); Flight flightByID = flighs.FirstOrDefault(a => a.DestinationCountryCode == countryCode); if (flightByID == null) { return(NotFound()); } return(Ok(flightByID)); }
public async Task <ActionResult <List <AirlineReducedDTO> > > GetAllFlights() { IList <Flight> flights = await Task.Run(() => m_facade.GetAllFlights()); List <AirlineFlightDTO> airlineFlightsDTOs = new List <AirlineFlightDTO>(); foreach (Flight flight in flights) { AirlineFlightDTO airlineDTO = m_mapper.Map <AirlineFlightDTO>(flight); airlineFlightsDTOs.Add(airlineDTO); } return(Ok(JsonConvert.SerializeObject(airlineFlightsDTOs))); }
public void CustomerControllerPurchaseTicketAPI() { ILoggedInAdministratorFacade adminFacade = (ILoggedInAdministratorFacade)TestConfig.fcs.Login(AirlineProjectConfig.TEST_ADMIN_USERNAME, AirlineProjectConfig.TEST_ADMIN_PASSWORD, out ILoginToken adminToken); adminFacade.CreateNewAirline((LoginToken <Administrator>)adminToken, TestData.airline1); adminFacade.CreateNewCustomer((LoginToken <Administrator>)adminToken, TestData.customer1); Flight flight1 = new Flight(0, 0, TestData.argentinaID, TestData.barbadosID, TestData.futureDate1, TestData.futureDate2, 200); ILoggedInAirlineFacade airlineFacade1 = (ILoggedInAirlineFacade)TestConfig.fcs.Login(TestData.airline1.UserName, TestData.airline1.Password, out ILoginToken airlineToken1); airlineFacade1.CreateFlight((LoginToken <AirlineCompany>)airlineToken1, flight1); // ---------------------------------------------- HttpClient client = new HttpClient(); client.BaseAddress = new Uri(CustomerURL); // Add an Accept header for JSON format. client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); string customerCreds = string.Format($"{TestData.customer1.UserName}:{TestData.customer1.Password}"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.Default.GetBytes(customerCreds))); HttpResponseMessage response = client.PostAsync("", new StringContent(JsonConvert.SerializeObject(flight1), Encoding.Default, "application/json")).Result; Ticket purchasedTicket; if (response.IsSuccessStatusCode) { purchasedTicket = response.Content.ReadAsAsync <Ticket>().Result; } else { purchasedTicket = new Ticket(0, 0, 0); } // ----------------------------------------------------------------------------- IAnonymousUserFacade anonymousFacade = (IAnonymousUserFacade)TestConfig.fcs.Login("testAnonymous", "99999", out ILoginToken anonymousToken); IList <Flight> flights = anonymousFacade.GetAllFlights(); Flight purchasedFlight = flights[0]; Assert.AreEqual(TestData.customer1.ID, purchasedTicket.CustomerId); Assert.AreEqual(purchasedFlight.ID, purchasedTicket.FlightId); }
public ActionResult <IList <FlightDetailsDTO> > GetAllFlights() { IList <Flight> flights = _anonymousUserFacade.GetAllFlights(); if (flights.Count == 0) { return(NoContent()); } List <FlightDetailsDTO> flightDetailsDTOs = new List <FlightDetailsDTO>(); foreach (var flight in flights) { flightDetailsDTOs.Add(_mapper.Map <FlightDetailsDTO>(flight)); } return(Ok(flightDetailsDTOs)); }
public void AnonymousFacadeGetAllFlightsMethod() { ILoggedInAdministratorFacade adminFacade = (ILoggedInAdministratorFacade)TestConfig.fcs.Login(AirlineProjectConfig.ADMIN_USERNAME, AirlineProjectConfig.ADMIN_PASSWORD, out ILoginToken adminToken); adminFacade.CreateNewAirline((LoginToken <Administrator>)adminToken, TestData.airline1); ILoggedInAirlineFacade airlineFacade = (ILoggedInAirlineFacade)TestConfig.fcs.Login(TestData.airline1.UserName, TestData.airline1.Password, out ILoginToken airlineToken); Flight flight1 = new Flight(0, 0, TestData.argentinaID, TestData.barbadosID, TestData.futureDate1, TestData.futureDate2, 200); Flight flight2 = new Flight(0, 0, TestData.chadID, TestData.denmarkID, TestData.futureDate1, TestData.futureDate2, 190); airlineFacade.CreateFlight((LoginToken <AirlineCompany>)airlineToken, flight1); airlineFacade.CreateFlight((LoginToken <AirlineCompany>)airlineToken, flight2); IAnonymousUserFacade anonymousFacade = (IAnonymousUserFacade)TestConfig.fcs.Login("testAnonymous", "99999", out ILoginToken anonymousToken); IList <Flight> flights = anonymousFacade.GetAllFlights(); Assert.AreEqual(flight1, flights[0]); Assert.AreEqual(flight2, flights[1]); }