示例#1
0
        public IHttpActionResult CreateCustomerAndUserRepository([FromBody] JObject jsonDataForCustomer)
        {
            string         userName       = jsonDataForCustomer["userName"].ToString();
            string         password       = jsonDataForCustomer["password"].ToString();
            string         firstName      = jsonDataForCustomer["firstName"].ToString();
            string         lastName       = jsonDataForCustomer["lastName"].ToString();
            string         address        = jsonDataForCustomer["address"].ToString();
            string         phoneNumber    = jsonDataForCustomer["phoneNumber"].ToString();
            string         creditCard     = jsonDataForCustomer["creditCard"].ToString();
            UserRepository userRepository = new UserRepository(userName, password, RolesEnum.customer);
            Customer       customer       = new Customer(firstName, lastName, address, phoneNumber, creditCard, 1);

            try
            {
                anonymousUserFacade.CreateCustomerAndUserRepository(userRepository, customer);
            }
            catch (TokenIsNullException)
            {
                return(Unauthorized());
            }
            catch (UserNameAlreadyExistsException nameAlreadyExists)
            {
                return(BadRequest($"Error: {nameAlreadyExists}"));
            }
            catch (Exception ex)
            {
                return(BadRequest($"Error: {ex}"));
            }
            return(CreatedAtRoute("getcustomerbyid", new { customerID = customer.ID }, customer));
        }
        public void GetAllMyFlights()
        {
            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;

            myFacadeAir.CreateFlight(myTokenair, flight);
            AnonymousUserFacade anonymousUserFacade    = new AnonymousUserFacade();
            Customer            customer               = new Customer("asdjkb", "fgh", "adthv", "0506794532", "123479520589243", 2);
            UserRepository      customerUserRepository = new UserRepository("radp", "ass", RolesEnum.customer);

            anonymousUserFacade.CreateCustomerAndUserRepository(customerUserRepository, customer);
            FlyingCenterSystem.GetInstance().TryLogin(customerUserRepository.UserName, customerUserRepository.Password, out ILogin tokenCustomer,
                                                      out FacadeBase facadeCustomer);
            LoginToken <Customer>  myTokencustomer        = tokenCustomer as LoginToken <Customer>;
            LoggedInCustomerFacade loggedInCustomerFacade = facadeCustomer as LoggedInCustomerFacade;

            loggedInCustomerFacade.PurchaseTicket(myTokencustomer, flight);
            List <Flight> flights = (List <Flight>)loggedInCustomerFacade.GetAllMyFlights(myTokencustomer);

            Assert.IsNotNull(flights);
        }
示例#3
0
        public void CreateACustomerAndAUserRepositoryForThatCustomer()
        {
            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);
            AnonymousUserFacade anonymousUserFacade    = new AnonymousUserFacade();
            Customer            customer               = new Customer("asd", "fgh", "adthv", "0506794532", "123479520589243", 2);
            UserRepository      customerUserRepository = new UserRepository("rad", "ass", RolesEnum.customer);

            anonymousUserFacade.CreateCustomerAndUserRepository(customerUserRepository, customer);
            Customer customer1 = myFacade.GetCustomerByid(myToken, customer.ID.ToString());

            Assert.AreEqual(customer.ID, customer1.ID);
        }