Ejemplo n.º 1
0
        public void ModifyAirlineDetails()
        {
            IList <AirlineCompany> airlines = facade.GetAllAirlineCompanies();

            airlines[0].UserName = "******";
            facade.ModifyAirlineDetails(AirLineLogin, airlines[0]);
        }
Ejemplo n.º 2
0
        public void ModifyAirlineDetails()
        {
            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;

            airlineCompany.AirlineName = "Yes";
            myFacadeAir.ModifyAirlineDetails(myTokenair, airlineCompany);
            AirlineCompany airlineCompany1 = myFacade.GetAirlineCompanyByid(myToken, airlineCompany.ID.ToString());

            Assert.AreEqual(airlineCompany.AirlineName, airlineCompany1.AirlineName);
        }
Ejemplo n.º 3
0
        public void ModifyAirlineCompany_AttemptingToChangeUsername()
        {
            LoggedInAirlineFacade airlineFacade = GetAirlineFacade(LoggedInAirlineFacadeTest_Constants.ModifyAirlineCompany_AttemptingToChangeUsername_LOGINTOKEN_USERNAME,
                                                                   LoggedInAirlineFacadeTest_Constants.ModifyAirlineCompany_AttemptingToChangeUsername_LOGINTOKEN_PASSWORD);
            AirlineCompany airlineCompany = LoggedInAirlineFacadeTest_Constants.ModifyAirlineCompany_AttemptingToChangeUsername_UPDATED_AIRLINE_INFO;

            Assert.ThrowsException <UnauthorisedActionException>(new Action(() => airlineFacade.ModifyAirlineDetails(airlineFacade.LoginToken, airlineCompany)));
        }
Ejemplo n.º 4
0
        public void ModifyAirlineCompany_WrongPasswordEntered()
        {
            LoggedInAirlineFacade airlineFacade = GetAirlineFacade(LoggedInAirlineFacadeTest_Constants.ModifyAirlineCompany_WrongPasswordEntered_ThrowsException_LOGINTOKEN_USERNAME,
                                                                   LoggedInAirlineFacadeTest_Constants.ModifyAirlineCompany_WrongPasswordEntered_ThrowsException_LOGINTOKEN_PASSWORD);
            AirlineCompany airlineCompany = LoggedInAirlineFacadeTest_Constants.ModifyAirlineCompany_WrongPasswordEntered_ThrowsException_UPDATED_AIRLINE_INFO;

            Assert.ThrowsException <WrongPasswordException>(new Action(() => airlineFacade.ModifyAirlineDetails(airlineFacade.LoginToken, airlineCompany)));
        }
Ejemplo n.º 5
0
        public void ModifyAirlineDetails()
        {
            AirlineCompanies air = new AirlineCompanies(1, "airforce", 3, 3);

            loggedInAirline.ModifyAirlineDetails(airline, air);
            AirlineCompanies air_for_test = loggedInAirline.GetAirlineById(airline, 1);

            Assert.AreEqual(air, air_for_test);
        }
Ejemplo n.º 6
0
        public IHttpActionResult ModifyAirlineDetails([FromBody] AirlineCompany airlineCompany)
        {
            LoginToken <AirlineCompany> token = GetLoginToken();

            airlineCompany.Id = token.User.Id;

            facade.ModifyAirlineDetails(token, airlineCompany);

            return(Ok());
        }
Ejemplo n.º 7
0
        public void ModifyAirlineCompany_CorrectPasswordEntered_LoginTokenContainsUpdatedInfo()
        {
            LoggedInAirlineFacade airlineFacade = GetAirlineFacade(LoggedInAirlineFacadeTest_Constants.ModifyAirlineCompany_CorrectPasswordEntered_LoginTokenContainsUpdatedInfo_LOGINTOKEN_USERNAME,
                                                                   LoggedInAirlineFacadeTest_Constants.ModifyAirlineCompany_CorrectPasswordEntered_LoginTokenContainsUpdatedInfo_LOGINTOKEN_PASSWORD);
            AirlineCompany airlineCompany = LoggedInAirlineFacadeTest_Constants.ModifyAirlineCompany_CorrectPasswordEntered_LoginTokenContainsUpdatedInfo_UPDATED_AIRLINE_INFO;

            airlineFacade.ModifyAirlineDetails(airlineFacade.LoginToken, airlineCompany);

            Assert.AreEqual(airlineCompany.AirlineName, airlineFacade.LoginToken.User.AirlineName);
            Assert.AreEqual(airlineCompany.OriginCountry, airlineFacade.LoginToken.User.OriginCountry);
        }
Ejemplo n.º 8
0
        public IHttpActionResult ModifyAirlineDetails([FromBody] AirlineCompany airline)
        {
            var loginToken = GetLoginToken();

            if (loginToken == null)
            {
                return(Unauthorized());
            }
            _facade.ModifyAirlineDetails(loginToken, airline);
            return(Ok());
        }
        public IActionResult ChangeDetails([FromBody] AirlineCompany airlineCompany)
        {
            IActionResult result = SafeExecute(() =>
            {
                int facadeIndex = RetriveFacadeIndex();
                LoggedInAirlineFacade airlineFacade = (LoggedInAirlineFacade)FlyingCenterSystem.FacadeList[facadeIndex];
                airlineFacade.ModifyAirlineDetails(airlineFacade.LoginToken, airlineCompany);
                if (airlineFacade.LoginToken.User != airlineCompany)
                {
                    return(new StatusCodeResult(StatusCodes.Status304NotModified));
                }
                return(Ok());
            });

            return(result);
        }
        public IHttpActionResult MofidyAirlineDetails([FromBody] AirlineCompany airline)
        {
            GetLoginToken();

            try
            {
                if (airline.Id == loginToken.User.Id)
                {
                    airlineFacade.ModifyAirlineDetails(loginToken, airline);
                    return(Ok());
                }

                return(BadRequest());
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
Ejemplo n.º 11
0
        public IHttpActionResult MofidyAirlineDetails(AirlineCompany airline, [FromUri] int id)
        {
            LoginToken <AirlineCompany> airlineToken  = (LoginToken <AirlineCompany>)Request.Properties["airlineToken"];
            LoggedInAirlineFacade       airlineFacade = (LoggedInAirlineFacade)Request.Properties["airlineFacade"];

            if (airline == null || id <= 0)
            {
                return(Content(HttpStatusCode.NotFound, $"airline details haven't been filled out correctly"));
            }

            try
            {
                airlineFacade.ModifyAirlineDetails(airlineToken, airline);
                return(Ok($"airline {airline.USER_NAME} details updated"));
            }
            catch (Exception)
            {
                return(Content(HttpStatusCode.NotFound, $"airline {airline.ID} wasn't found"));
            }
        }
Ejemplo n.º 12
0
        public void AirlineFacadeTest()
        {
            new TestFacade().DeleteAllTables();

            AirlineCompany testAirline = new AirlineCompany("Air One", "airone", "*****@*****.**", "555", 1);

            LoginToken <Administrator> token = new LoginToken <Administrator>()
            {
                User = new Administrator()
            };

            new LoggedInAdministratorFacade().CreateNewAirline(token, testAirline);

            testAirline.Id = new AnonymousUserFacade().GetAllAirlineCompanies()[0].Id;

            FlightCenterSystem fcs = FlightCenterSystem.GetInstance();

            LoginToken <AirlineCompany> loginToken = new LoginToken <AirlineCompany>()
            {
                User = testAirline
            };

            LoggedInAirlineFacade facade = fcs.GetFacade <AirlineCompany>(loginToken) as LoggedInAirlineFacade;

            #region Create flight

            IList <AirlineCompany> airlines = new AnonymousUserFacade().GetAllAirlineCompanies();

            Assert.ThrowsException <InvalidTokenException>(() =>
            {
                facade.CreateFlight(null, new Flight(airlines[0].Id, 1, 2, DateTime.Now, DateTime.Now.AddHours(3), 5, 99));
                // Null token, should cause an exception to be thrown
            });

            // Airline company constraints:

            Assert.ThrowsException <InvalidFlightException>(() =>
            {
                facade.CreateFlight(loginToken, new Flight(0, 1, 2, new DateTime(2011, 11, 11), new DateTime(2011, 11, 11), 5, 99));
                // Airline company Id is 0, should cause an exception to be thrown
            });

            Assert.ThrowsException <AirlineCompanyNotFoundException>(() =>
            {
                facade.CreateFlight(loginToken, new Flight(9999, 1, 2, new DateTime(2011, 11, 11), new DateTime(2011, 11, 11), 5, 99));
                // Airline company Id doesn't exist, should cause an exception to be thrown from the sql
            });

            // Origin country constraints:

            Assert.ThrowsException <InvalidFlightException>(() =>
            {
                facade.CreateFlight(loginToken, new Flight(airlines[0].Id, 0, 2, new DateTime(2011, 11, 11), new DateTime(2011, 11, 11), 5, 99));
                // Origin country Id is 0, should cause an exception to be thrown
            });

            Assert.ThrowsException <CountryNotFoundException>(() =>
            {
                facade.CreateFlight(loginToken, new Flight(airlines[0].Id, 9999, 2, new DateTime(2011, 11, 11), new DateTime(2011, 11, 11), 5, 99));
                // Origin country Id doesn't exist, should cause an exception to be thrown from the sql
            });

            // Destination country constraints:

            Assert.ThrowsException <InvalidFlightException>(() =>
            {
                facade.CreateFlight(loginToken, new Flight(airlines[0].Id, 1, 0, new DateTime(2011, 11, 11), new DateTime(2011, 11, 11), 5, 99));
                // Destination country Id is 0, should cause an exception to be thrown
            });

            Assert.ThrowsException <CountryNotFoundException>(() =>
            {
                facade.CreateFlight(loginToken, new Flight(airlines[0].Id, 1, 9999, new DateTime(2011, 11, 11), new DateTime(2011, 11, 11), 5, 99));
                // Destination country Id doesn't exist, should cause an exception to be thrown from the sql
            });

            // Flight time constraints:

            Assert.ThrowsException <InvalidFlightException>(() =>
            {
                facade.CreateFlight(loginToken, new Flight(airlines[0].Id, 1, 2, new DateTime(), new DateTime(2011, 11, 11), 5, 99));
                // No departure time, should cause an exception to be thrown
            });

            Assert.ThrowsException <InvalidFlightException>(() =>
            {
                facade.CreateFlight(loginToken, new Flight(airlines[0].Id, 1, 2, new DateTime(2011, 11, 11), new DateTime(), 5, 99));
                // No landing time, should cause an exception to be thrown
            });

            int yearNow  = DateTime.Now.Year;
            int monthNow = DateTime.Now.Month;
            int dayNow   = DateTime.Now.Day;

            facade.CreateFlight(loginToken, new Flight(airlines[0].Id, 1, 2, new DateTime(2012, 12, 12), new DateTime(2012, 12, 12), 5, 120));
            IList <Flight> flights = facade.GetAllFlights();

            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(2012, 12, 12));
            Assert.AreEqual(flights[0].LandingTime, new DateTime(2012, 12, 12));
            Assert.AreEqual(flights[0].RemainingTickets, 5);
            Assert.AreEqual(flights[0].TicketPrice, 120);

            #endregion

            #region Update flight

            Assert.ThrowsException <InvalidTokenException>(() =>
            {
                facade.UpdateFlight(null, new Flight(airlines[0].Id, 3, 4, new DateTime(yearNow, monthNow, dayNow), new DateTime(yearNow, monthNow, dayNow), 10, 99));
                // Null token, should cause an exception to be thrown
            });

            flights = facade.GetAllFlights();
            facade.UpdateFlight(loginToken, new Flight(airlines[0].Id, 2, 3, new DateTime(yearNow, monthNow, dayNow), new DateTime(yearNow, monthNow, dayNow), 10, 99)
            {
                Id = flights[0].Id
            });

            flights = facade.GetAllFlights();

            Assert.AreEqual(flights[0].AirlineCompanyId, airlines[0].Id);
            Assert.AreEqual(flights[0].OriginCountryCode, 2);
            Assert.AreEqual(flights[0].DestinationCountryCode, 3);
            Assert.AreEqual(flights[0].DepartureTime, new DateTime(yearNow, monthNow, dayNow));
            Assert.AreEqual(flights[0].LandingTime, new DateTime(yearNow, monthNow, dayNow));
            Assert.AreEqual(flights[0].RemainingTickets, 10);
            Assert.AreEqual(flights[0].TicketPrice, 99);

            #endregion

            #region Change my password

            Assert.ThrowsException <InvalidTokenException>(() =>
            {
                facade.ChangeMyPassword(null, "555", "666");
                // Null token, should cause an exception to be thrown
            });

            Assert.ThrowsException <WrongPasswordException>(() =>
            {
                facade.ChangeMyPassword(loginToken, "444", "666");
                // wrong password, should cause an exception to be thrown
            });

            facade.ChangeMyPassword(loginToken, "555", "666");

            airlines = facade.GetAllAirlineCompanies();

            Assert.AreEqual(airlines[0].Password, "666");

            #endregion

            #region Modify airline details

            Assert.ThrowsException <InvalidTokenException>(() =>
            {
                facade.ModifyAirlineDetails(null, testAirline);
                // Null token, should cause an exception to be thrown
            });

            testAirline.Name = "Best Pilots";

            facade.ModifyAirlineDetails(loginToken, testAirline);
            airlines = facade.GetAllAirlineCompanies();

            Assert.AreEqual(airlines[0].Name, "Best Pilots");

            #endregion

            #region Get all my flights

            Assert.ThrowsException <InvalidTokenException>(() =>
            {
                facade.CreateFlight(null, new Flight(airlines[0].Id, 3, 4, new DateTime(2009, 9, 9), new DateTime(2009, 9, 9), 10, 99));
                // Null token, should cause an exception to be thrown
            });

            facade.CreateFlight(loginToken, new Flight(airlines[0].Id, 3, 4, new DateTime(yearNow, monthNow, dayNow), new DateTime(yearNow, monthNow, dayNow), 10, 99));

            flights = facade.GetAllMyFlights(loginToken);

            Assert.AreEqual(flights[0].AirlineCompanyId, airlines[0].Id);
            Assert.AreEqual(flights[0].OriginCountryCode, 2);
            Assert.AreEqual(flights[0].DestinationCountryCode, 3);
            Assert.AreEqual(flights[0].DepartureTime, new DateTime(yearNow, monthNow, dayNow));
            Assert.AreEqual(flights[0].LandingTime, new DateTime(yearNow, monthNow, dayNow));
            Assert.AreEqual(flights[0].RemainingTickets, 10);
            Assert.AreEqual(flights[0].TicketPrice, 99);

            Assert.AreEqual(flights[1].AirlineCompanyId, airlines[0].Id);
            Assert.AreEqual(flights[1].OriginCountryCode, 3);
            Assert.AreEqual(flights[1].DestinationCountryCode, 4);
            Assert.AreEqual(flights[1].DepartureTime, new DateTime(yearNow, monthNow, dayNow));
            Assert.AreEqual(flights[1].LandingTime, new DateTime(yearNow, monthNow, dayNow));
            Assert.AreEqual(flights[1].RemainingTickets, 10);
            Assert.AreEqual(flights[1].TicketPrice, 99);

            #endregion
        }