public void CustomerFacadeGetAllMyFlightsMethod()
        {
            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);
            Flight flight2 = new Flight(0, 0, TestData.chadID, TestData.denmarkID, TestData.futureDate1, TestData.futureDate3, 190);
            ILoggedInAirlineFacade airlineFacade1 = (ILoggedInAirlineFacade)TestConfig.fcs.Login(TestData.airline1.UserName, TestData.airline1.Password, out ILoginToken airlineToken1);

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

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

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

            Assert.AreEqual(0, customerFacade1.GetAllMyFlights((LoginToken <Customer>)customerToken1).Count);

            Ticket ticket1 = customerFacade1.PurchaseTicket((LoginToken <Customer>)customerToken1, flight1);
            Ticket ticket2 = customerFacade1.PurchaseTicket((LoginToken <Customer>)customerToken1, flight2);

            IList <Flight> actualflights = customerFacade1.GetAllMyFlights((LoginToken <Customer>)customerToken1);

            Assert.AreEqual(2, customerFacade1.GetAllMyFlights((LoginToken <Customer>)customerToken1).Count);
            Assert.AreEqual(flight1, actualflights[0]);
            Assert.AreEqual(flight2, actualflights[1]);
        }
        public async Task <ActionResult <IList <CustomerFlightDTO> > > GetAllCustomerFlights()
        {
            LoginToken <Customer> token   = GetLoginToken();
            IList <Flight>        flights = null;

            try
            {
                flights = await Task.Run(() => m_facade.GetAllMyFlights(token));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, $"{{ error: \"{ex.Message}\" }}"));
            }
            if (flights.Count == 0)
            {
                return(StatusCode(204, "{ }"));
            }
            List <CustomerFlightDTO> flightDTOs = new List <CustomerFlightDTO>();

            foreach (Flight flight in flights)
            {
                CustomerFlightDTO flightDTO = m_mapper.Map <CustomerFlightDTO>(flight);
                flightDTOs.Add(flightDTO);
            }
            return(Ok(JsonConvert.SerializeObject(flightDTOs)));
        }
        public IHttpActionResult GetAllMyFlights(string username = "")
        {
            IList <Flight>    flights = null;
            IHttpActionResult result  = null;

            GetLoginToken();
            if (customerLoginToken == null)
            {
                return(Unauthorized());
            }
            FCS = FlyingCenterSystem.GetFlyingCenterSystemInstance();
            ILoggedInCustomerFacade customerFacade = FCS.GetFacade(customerLoginToken) as ILoggedInCustomerFacade;

            if (username != "")
            {
                flights = customerFacade.GetAllMyFlights(customerLoginToken, username);
                result  = Ok(flights);
            }
            else if ((username != "" && flights.Count == 0) || username == "")
            {
                result = NotFound();
            }

            return(result);
        }
        public void CustomerFacadeCancelTicketMethod()
        {
            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);

            customerFacade1.CancelTicket((LoginToken <Customer>)customerToken1, ticket1);

            Assert.AreEqual(200, anonymousFacade.GetFlight(flight1.ID).RemainingTickets);
            Assert.AreEqual(0, customerFacade1.GetAllMyFlights((LoginToken <Customer>)customerToken1).Count);
        }
 public void CustomerFacade_GetAllMyFlights_FlightsReceived()
 {
     AddToLogFile("run CustomerFacade GetAllMyFlights");
     InitDBUnitTest.InitDB();
     IList<Flight> flights1 = null;
     IList<Flight> flights2 = null;
     Customer customer = AdministratorFacade_CreateNewCustomer();
     CustomerFacade_CreateNewTicket();
     ILoggedInCustomerFacade customerFacade = GetCustomerFacade(out LoginToken<Customer> tCustomer);
     flights1 = customerFacade.GetAllMyFlights(tCustomer, customer.USER_NAME);
     Flight newFlight = CreateNewFlight1();
     newFlight.ID = flights1[0].ID;
     newFlight.AIRLINECOMPANY_ID = flights1[0].AIRLINECOMPANY_ID;
     newFlight.ORIGIN_COUNTRY_CODE = flights1[0].ORIGIN_COUNTRY_CODE;
     newFlight.DESTINATION_COUNTRY_CODE = flights1[0].DESTINATION_COUNTRY_CODE;
     flights2 = new List<Flight>();
     flights2.Add(newFlight);
     Assert.AreNotEqual(null, flights1);
     List <Flight> f1 = (List<Flight>)flights1;
     List<Flight> f2 = (List<Flight>)flights2;
     CollectionAssert.AreEqual(f1, f2);
     Assert.AreEqual(flights1[0].ID, flights2[0].ID);
     Assert.AreEqual(flights1[0].AIRLINECOMPANY_ID, flights2[0].AIRLINECOMPANY_ID);
     Assert.AreEqual(flights1[0].ORIGIN_COUNTRY_CODE, flights2[0].ORIGIN_COUNTRY_CODE);
     Assert.AreEqual(flights1[0].DESTINATION_COUNTRY_CODE, flights2[0].DESTINATION_COUNTRY_CODE);
     Assert.AreEqual(flights1[0].DEPARTURE_TIME, flights2[0].DEPARTURE_TIME);
     Assert.AreEqual(flights1[0].LANDING_TIME, flights2[0].LANDING_TIME);
     Assert.AreEqual(flights1[0].REMANING_TICKETS, flights2[0].REMANING_TICKETS-1);
     Assert.AreEqual(flights1[0].TOTAL_TICKETS, flights2[0].TOTAL_TICKETS);
 }
        public ActionResult <FlightDetailsDTO> GetAllMyFlights()
        {
            LoginToken <Customer> customer_token = DesirializeToken();

            IList <Flight> flights = _loggedInCustomerFacade.GetAllMyFlights(customer_token);

            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));
        }
Exemplo n.º 7
0
        public void CREATE_TICKET()
        {
            bool                  actual     = false;
            LoginService          ls         = new LoginService();
            LoginToken <Customer> ltCustomer = null;
            bool                  res        = ls.TryCustomerLogin("0021", "inna34", out ltCustomer);

            if (res == true)
            {
                FlyingCenterSystem      fs          = FlyingCenterSystem.Instance;
                ILoggedInCustomerFacade iCustomerFS = fs.GetFacade <ILoggedInCustomerFacade>();

                Ticket ticket = new Ticket(1, 1, 2);
                Flight flight = iCustomerFS.GetFlightByIdFlight(ltCustomer, 1);
                iCustomerFS.PurchaseTicket(ltCustomer, flight, ticket.id);
                IList <Flight> listFlights   = new List <Flight>();
                IList <Flight> originFlights = new List <Flight>();
                originFlights.Add(flight);
                listFlights = iCustomerFS.GetAllMyFlights(ltCustomer);
                actual      = originFlights.SequenceEqual(listFlights);

                Assert.IsTrue(actual);
            }
        }