Exemplo n.º 1
0
        public IHttpActionResult CreateNewFlight([FromBody] Flight flight)
        {
            GetLoginToken();
            if (airlineCompanyLoginToken == null)
            {
                return(Unauthorized());
            }
            FlyCenter = FlyingCenterSystem.GetInstance();
            ILoggedInAirlineFacade airlineFacade = FlyCenter.GetFacede(airlineCompanyLoginToken) as ILoggedInAirlineFacade;
            long flightId = airlineFacade.CreateFlight(airlineCompanyLoginToken, flight);

            return(CreatedAtRoute("createFlight", new { id = flightId }, flight));
        }
Exemplo n.º 2
0
        public void AnonymousFacadeGetFlightsByOriginCountryMethod()
        {
            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.argentinaID, TestData.chadID, TestData.futureDate1, TestData.futureDate3, 190);
            Flight flight3 = new Flight(0, 0, TestData.barbadosID, TestData.chadID, TestData.futureDate2, TestData.futureDate3, 180);

            airlineFacade.CreateFlight((LoginToken <AirlineCompany>)airlineToken, flight1);
            airlineFacade.CreateFlight((LoginToken <AirlineCompany>)airlineToken, flight2);
            airlineFacade.CreateFlight((LoginToken <AirlineCompany>)airlineToken, flight3);

            IAnonymousUserFacade anonymousFacade = (IAnonymousUserFacade)TestConfig.fcs.Login("testAnonymous", "99999", out ILoginToken anonymousToken);
            IList <Flight>       flights         = anonymousFacade.GetFlightsByOriginCountry(TestData.argentinaID);

            Assert.AreEqual(flight1, flights[0]);
            Assert.AreEqual(flight2, flights[1]);
            Assert.AreEqual(2, flights.Count);
        }
Exemplo n.º 3
0
        public void AirlineFacadeGetAllFlightsMethod()
        {
            ILoggedInAdministratorFacade adminFacade = (ILoggedInAdministratorFacade)TestConfig.fcs.Login(AirlineProjectConfig.ADMIN_USERNAME, AirlineProjectConfig.ADMIN_PASSWORD, out ILoginToken adminToken);

            adminFacade.CreateNewAirline((LoginToken <Administrator>)adminToken, TestData.airline1);
            adminFacade.CreateNewAirline((LoginToken <Administrator>)adminToken, TestData.airline2);

            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.futureDate3, 200);
            Flight flight3 = new Flight(0, 0, TestData.egyptID, TestData.franceID, TestData.futureDate2, TestData.futureDate3, 200);
            ILoggedInAirlineFacade airlineFacade1 = (ILoggedInAirlineFacade)TestConfig.fcs.Login(TestData.airline1.UserName, TestData.airline1.Password, out ILoginToken airlineToken1);
            ILoggedInAirlineFacade airlineFacade2 = (ILoggedInAirlineFacade)TestConfig.fcs.Login(TestData.airline2.UserName, TestData.airline2.Password, out ILoginToken airlineToken2);

            airlineFacade1.CreateFlight((LoginToken <AirlineCompany>)airlineToken1, flight1);
            airlineFacade1.CreateFlight((LoginToken <AirlineCompany>)airlineToken1, flight2);
            airlineFacade2.CreateFlight((LoginToken <AirlineCompany>)airlineToken2, flight3);

            IList <Flight> flights1 = airlineFacade1.GetAllFlights((LoginToken <AirlineCompany>)airlineToken1);

            Assert.AreEqual(flight1, flights1[0]);
            Assert.AreEqual(flight2, flights1[1]);
            Assert.AreEqual(2, flights1.Count);
        }
 public Flight AirlineCompanyFacadeFacade_CreateNewFlight1()
 {
     Flight newFlight1 = null;
     AirlineCompany airlineCompany1 = AdministratorFacade_CreateNewAirline1();
     ILoggedInAirlineFacade airlineCompanyFacade = GetAirlineCompanyFacade(out LoginToken<AirlineCompany> tAirlineCompany);
     newFlight1 = CreateNewFlight1();
     newFlight1.AIRLINECOMPANY_ID = airlineCompany1.ID;
     newFlight1.ORIGIN_COUNTRY_CODE = airlineCompany1.COUNTRY_CODE;
     Country country2 = AdministratorFacade_CreateNewCountry2();
     newFlight1.DESTINATION_COUNTRY_CODE = country2.ID;
     long ID = airlineCompanyFacade.CreateFlight(tAirlineCompany, newFlight1);
     newFlight1.ID = ID;
     return newFlight1;
 }
        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);
        }
Exemplo n.º 6
0
        public void AirlineFacadeCancelFlightMethod()
        {
            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 newFlight = new Flight(0, 0, TestData.argentinaID, TestData.barbadosID, TestData.futureDate1, TestData.futureDate2, 200);

            airlineFacade.CreateFlight((LoginToken <AirlineCompany>)airlineToken, newFlight);
            airlineFacade.CancelFlight((LoginToken <AirlineCompany>)airlineToken, newFlight);

            IAnonymousUserFacade anonymousFacade = (IAnonymousUserFacade)TestConfig.fcs.Login("testAnonymous", "99999", out ILoginToken anonymousToken);

            Assert.AreEqual(null, anonymousFacade.GetFlight(newFlight.ID));
        }
        public void CustomerFacadePurchaseTicketMethodNoMoreTicketsException()
        {
            ILoggedInAdministratorFacade adminFacade = (ILoggedInAdministratorFacade)TestConfig.fcs.Login(AirlineProjectConfig.ADMIN_USERNAME, AirlineProjectConfig.ADMIN_PASSWORD, out ILoginToken adminToken);

            adminFacade.CreateNewAirline((LoginToken <Administrator>)adminToken, TestData.airline1);
            adminFacade.CreateNewCustomer((LoginToken <Administrator>)adminToken, TestData.customer1);

            ILoggedInAirlineFacade airlineFacade1 = (ILoggedInAirlineFacade)TestConfig.fcs.Login(TestData.airline1.UserName, TestData.airline1.Password, out ILoginToken airlineToken1);
            Flight flight1 = new Flight(0, 0, TestData.argentinaID, TestData.barbadosID, TestData.futureDate1, TestData.futureDate2, 0);

            airlineFacade1.CreateFlight((LoginToken <AirlineCompany>)airlineToken1, flight1);

            ILoggedInCustomerFacade customerFacade1 = (ILoggedInCustomerFacade)TestConfig.fcs.Login(TestData.customer1.UserName, TestData.customer1.Password, out ILoginToken customerToken1);

            customerFacade1.PurchaseTicket((LoginToken <Customer>)customerToken1, flight1);
        }
        public async Task <ActionResult <AirlineFlightDTO> > CreateNewFlight([FromBody] AirlineFlightDTO airlineFlightDTO)
        {
            LoginToken <AirlineCompany> token = GetLoginToken();
            Flight flight = m_mapper.Map <Flight>(airlineFlightDTO);
            long   id;

            try
            {
                id = await Task.Run(() => m_facade.CreateFlight(token, flight));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, $"{{ error: \"{ex.Message}\" }}"));
            }
            airlineFlightDTO.Id = id;
            AirlineFlightDTO flightDTO = m_mapper.Map <AirlineFlightDTO>(airlineFlightDTO);

            return(Created($"api/Airline/CreateNewFlight/{flightDTO.Id}", JsonConvert.SerializeObject(flightDTO)));
        }
Exemplo n.º 9
0
        public ActionResult <Flight> CreateFlight(CreateFlightDTO createFlightDTO)
        {
            LoginToken <AirlineCompany> airline_token = DesirializeToken();

            Flight flight = _mapper.Map <Flight>(createFlightDTO);

            string uri = null;

            try
            {
                flight.Id = _loggedInAirlineFacade.CreateFlight(airline_token, flight);

                uri = _linkGenerator.GetPathByAction(nameof(AnonymousFacadeController.GetFlightById), "AnonymousFacade", new { id = flight.Id });
            }
            catch (RelatedRecordNotExistsException)
            {
                return(NotFound());
            }

            return(Created(uri, flight));
        }
Exemplo n.º 10
0
        public void AnonymousFacadeGetFlightMethod()
        {
            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);

            airlineFacade.CreateFlight((LoginToken <AirlineCompany>)airlineToken, flight1);

            IAnonymousUserFacade anonymousFacade = (IAnonymousUserFacade)TestConfig.fcs.Login("testAnonymous", "99999", out ILoginToken anonymousToken);
            Flight actualFlight = anonymousFacade.GetFlight(flight1.ID);

            Assert.AreEqual(flight1.ID, actualFlight.ID);
            Assert.AreEqual(flight1.AirlineCompanyId, actualFlight.AirlineCompanyId);
            Assert.AreEqual(flight1.OriginCountryCode, actualFlight.OriginCountryCode);
            Assert.AreEqual(flight1.DestinationCountryCode, actualFlight.DestinationCountryCode);
            Assert.AreEqual(flight1.DepartureTime, actualFlight.DepartureTime);
            Assert.AreEqual(flight1.LandingTime, actualFlight.LandingTime);
            Assert.AreEqual(flight1.RemainingTickets, actualFlight.RemainingTickets);
        }
        public void CustomerFacadePurchaseTicketMethod()
        {
            ILoggedInAdministratorFacade adminFacade = (ILoggedInAdministratorFacade)TestConfig.fcs.Login(AirlineProjectConfig.ADMIN_USERNAME, AirlineProjectConfig.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);

            IAnonymousUserFacade anonymousFacade = (IAnonymousUserFacade)TestConfig.fcs.Login("", "", out ILoginToken anonymousToken);

            Assert.AreEqual(200, anonymousFacade.GetFlight(flight1.ID).RemainingTickets);

            ILoggedInCustomerFacade customerFacade1 = (ILoggedInCustomerFacade)TestConfig.fcs.Login(TestData.customer1.UserName, TestData.customer1.Password, out ILoginToken customerToken1);
            Ticket ticket1 = customerFacade1.PurchaseTicket((LoginToken <Customer>)customerToken1, flight1);

            Assert.AreEqual(199, anonymousFacade.GetFlight(flight1.ID).RemainingTickets);
            Assert.AreEqual(1, customerFacade1.GetAllMyFlights((LoginToken <Customer>)customerToken1).Count);
            Assert.AreEqual(ticket1.FlightId, anonymousFacade.GetFlight(flight1.ID).ID);
            Assert.AreEqual(ticket1.CustomerId, TestData.customer1.ID);
        }
        public void AnonymousControllerGetAllFlightsAPI()
        {
            ILoggedInAdministratorFacade adminFacade = (ILoggedInAdministratorFacade)TestConfig.fcs.Login(AirlineProjectConfig.TEST_ADMIN_USERNAME, AirlineProjectConfig.TEST_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 newFlight = new Flight(0, 0, TestData.argentinaID, TestData.barbadosID, TestData.futureDate1, TestData.futureDate2, 200);

            airlineFacade.CreateFlight((LoginToken <AirlineCompany>)airlineToken, newFlight);

            IAnonymousUserFacade anonymousFacade = (IAnonymousUserFacade)TestConfig.fcs.Login("testAnonymous", "99999", out ILoginToken anonymousToken);
            Flight actualFlight = anonymousFacade.GetFlight(newFlight.ID);

            ////////////////////////////////////////

            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri(AnonymousURL);

            // Add an Accept header for JSON format.
            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.Default.GetBytes("testAnonymous:99999")));

            //added by itay, can maybe be the alternate solution:

            /*
             * WebRequest req = WebRequest.Create(AnonymousURL);
             * req.Method = "GET";
             * req.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes("testAnonymous:99999"));
             * //req.Credentials = new NetworkCredential("username", "password");
             * HttpWebResponse resp = req.GetResponse() as HttpWebResponse;
             *
             * // Get the stream containing content returned by the server.
             * // The using block ensures the stream is automatically closed.
             * using (Stream dataStream = resp.GetResponseStream())
             * {
             *  // Open the stream using a StreamReader for easy access.
             *  StreamReader reader = new StreamReader(dataStream);
             *  // Read the content.
             *  string responseFromServer = reader.ReadToEnd();
             *  // Display the content.
             *  Console.WriteLine(responseFromServer);
             * }
             *
             * // Close the response.
             * resp.Close();
             */

            /*
             * // -------------------------- One item
             * HttpResponseMessage response = client.GetAsync("").Result;  // Blocking call! Program will wait here until a response is received or a timeout occurs.
             * if (response.IsSuccessStatusCode)
             * {
             *  var dataObjects = response.Content.ReadAsAsync<Flight>().Result;
             * }
             * else
             * {
             *  Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
             * }
             */

            // --------------------------- List
            // List data response.
            HttpResponseMessage response = client.GetAsync("").Result;  // Blocking call! Program will wait here until a response is received or a timeout occurs.

            if (response.IsSuccessStatusCode)
            {
                // Parse the response body.
                var dataObjects = response.Content.ReadAsAsync <IList <Flight> >().Result;  //Make sure to add a reference to System.Net.Http.Formatting.dll

                //Flight flight = new Flight(1, 1, 1, 2, new DateTime(2019, 4, 20), new DateTime(2019, 4, 21), 14);
                Assert.AreEqual(dataObjects[0].ID, actualFlight.ID);
                Assert.AreEqual(dataObjects[0].AirlineCompanyId, actualFlight.AirlineCompanyId);
                Assert.AreEqual(dataObjects[0].OriginCountryCode, actualFlight.OriginCountryCode);
                Assert.AreEqual(dataObjects[0].DestinationCountryCode, actualFlight.DestinationCountryCode);
                Assert.AreEqual(dataObjects[0].DepartureTime, actualFlight.DepartureTime);
                Assert.AreEqual(dataObjects[0].LandingTime, actualFlight.LandingTime);
                Assert.AreEqual(dataObjects[0].RemainingTickets, actualFlight.RemainingTickets);
            }
            else
            {
                //Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
                //nothing i guess?
                throw new AssertFailedException();
            }

            //Make any other calls using HttpClient here.

            //Dispose once all HttpClient calls are complete. This is not necessary if the containing object will be disposed of; for example in this case the HttpClient instance will be disposed automatically when the application terminates so the following call is superfluous.
            client.Dispose();
        }