public async Task Remove_Flight_That_Belongs_To_Another_Airline_Should_Return_Forbidden()
        {
            CreateAirlineCompanyDTO createAirlineCompanyDTO = new CreateAirlineCompanyDTO
            {
                Name      = "Arkia",
                CountryId = 1,
                User      = new CreateUserDTO
                {
                    UserName = "******",
                    Password = "******",
                    Email    = "*****@*****.**",
                }
            };

            await TestHelpers.Airline_Company_Login(_httpClient, createAirlineCompanyDTO);

            CreateFlightDTO createFlightDTO = new CreateFlightDTO
            {
                OriginCountryId      = 1,
                DestinationCountryId = 1,
                DepartureTime        = DateTime.Now.AddHours(12),
                LandingTime          = DateTime.Now.AddHours(16),
                RemainingTickets     = 15
            };

            await _httpClient.PostAsync("api/flights",
                                        new StringContent(JsonSerializer.Serialize(createFlightDTO), Encoding.UTF8, MediaTypeNames.Application.Json));

            await TestHelpers.Airline_Company_Login(_httpClient);

            var deleteResponse = await _httpClient.DeleteAsync($"api/flights/1");

            Assert.AreEqual(HttpStatusCode.Forbidden, deleteResponse.StatusCode);
        }
        public ActionResult <AirlineCompany> CreateNewAirlineCompany(CreateAirlineCompanyDTO createAirlineCompanyDTO)
        {
            LoginToken <Administrator> admin_token = DesirializeToken();

            AirlineCompany airline = _mapper.Map <AirlineCompany>(createAirlineCompanyDTO);

            string uri = null;

            try
            {
                airline.Id = _loggedInAdministratorFacade.CreateNewAirlineCompany(admin_token, airline);
                if (airline.Id == 0)
                {
                    return(Conflict());
                }

                uri = _linkGenerator.GetPathByAction(nameof(AnonymousFacadeController.GetAirlineCompanyById), "AnonymousFacade", new { id = airline.Id });
            }
            catch (RecordAlreadyExistsException)
            {
                return(Conflict());
            }
            catch (RelatedRecordNotExistsException)
            {
                return(NotFound($"Country with id: {createAirlineCompanyDTO.CountryId} doesn't exist"));
            }

            return(Created(uri, airline));
        }
Esempio n. 3
0
        internal static async Task Airline_Company_Login(HttpClient httpClient, CreateAirlineCompanyDTO createAirlineCompanyDTO = null, bool create_airline = true)
        {
            if (createAirlineCompanyDTO == null)
            {
                createAirlineCompanyDTO = new CreateAirlineCompanyDTO
                {
                    Name      = "El Al",
                    CountryId = 1,
                    User      = new CreateUserDTO
                    {
                        UserName = "******",
                        Password = "******",
                        Email    = "*****@*****.**",
                    }
                };
            }

            if (create_airline)
            {
                await Main_Admin_Login(httpClient);

                await Create_Airline_Company_For_Tests(httpClient, createAirlineCompanyDTO);
            }

            var credentials = new LoginRequest//Demi credentials
            {
                UserName = createAirlineCompanyDTO.User.UserName,
                Password = createAirlineCompanyDTO.User.Password
            };
            var loginResponse = await httpClient.PostAsync("api/account/login",
                                                           new StringContent(JsonSerializer.Serialize(credentials), Encoding.UTF8, MediaTypeNames.Application.Json));

            var loginResponseContent = await loginResponse.Content.ReadAsStringAsync();                                                                      //Get response content as json string

            var loginResult = JsonSerializer.Deserialize <LoginResult>(loginResponseContent);                                                                //Desirialize the json string back to LoginResult

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(JwtBearerDefaults.AuthenticationScheme, loginResult.AccessToken); //Set the Jwt access token in the request header
        }
Esempio n. 4
0
 private static async Task Create_Airline_Company_For_Tests(HttpClient httpClient, CreateAirlineCompanyDTO createAirlineCompanyDTO)
 {
     await httpClient.PostAsync("api/airline-companies",
                                new StringContent(JsonSerializer.Serialize(createAirlineCompanyDTO), Encoding.UTF8, MediaTypeNames.Application.Json));
 }