public async Task Get_Endpoint_Test_Role_Permission(string page, string user, HttpStatusCode statusCode)
        {
            // Arrange
            var client = _factory.CreateClient();

            client.DefaultRequestHeaders.Authorization = AutorizationHeader.CreateRoleAuthorizationHeader(user);

            // Act
            var response = await client.GetAsync(page);

            // Assert
            Assert.Equal(statusCode, response.StatusCode);
        }
Esempio n. 2
0
        public async Task Get_Endpoint_Admin_Should_No_Return_Unauthorized(string url)
        {
            // Arrange
            var client = _factory.CreateClient();

            client.DefaultRequestHeaders.Authorization = AutorizationHeader.CreateRoleAuthorizationHeader(UserDataGenerator.Admin);

            // Act
            var response = await client.GetAsync(url);

            // Assert
            Assert.NotEqual(HttpStatusCode.Unauthorized, response.StatusCode);
        }
Esempio n. 3
0
        public async Task Get_Endpoint_No_Admin(string url)
        {
            // Arrange
            var client = _factory.CreateClient();

            client.DefaultRequestHeaders.Authorization = AutorizationHeader.CreateRoleAuthorizationHeader(UserDataGenerator.PageOne);

            // Act
            var response = await client.GetAsync(url);

            // Assert
            Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
        }
Esempio n. 4
0
        public async Task Delete_Admin_User_Not_Exist(string url)
        {
            // Arrange
            var client = _factory.CreateClient();

            client.DefaultRequestHeaders.Authorization = AutorizationHeader.CreateRoleAuthorizationHeader(UserDataGenerator.Admin);

            // Act
            var response = await client.DeleteAsync(url);

            // Assert
            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
        }
Esempio n. 5
0
        public async Task Get_Endpoint_Should_Return_Not_Acceptable(string url, string contentType)
        {
            // Arrange
            var client = _factory.CreateClient();

            client.DefaultRequestHeaders.Authorization = AutorizationHeader.CreateRoleAuthorizationHeader(UserDataGenerator.Admin);
            client.DefaultRequestHeaders.Add(HttpRequestHeader.Accept.ToString(), contentType);

            // Act
            var response = await client.GetAsync(url);

            // Assert
            Assert.Equal(HttpStatusCode.NotAcceptable, response.StatusCode);
        }
Esempio n. 6
0
        public async Task Get_Endpoint_Should_Return_Json_Content(string url, string contentType)
        {
            // Arrange
            var client = _factory.CreateClient();

            client.DefaultRequestHeaders.Authorization = AutorizationHeader.CreateRoleAuthorizationHeader(UserDataGenerator.Admin);
            client.DefaultRequestHeaders.Add(HttpRequestHeader.Accept.ToString(), contentType);

            // Act
            var response = await client.GetAsync(url);

            // Assert
            Assert.Contains(contentType, response.Content.Headers.ContentType.MediaType);
        }
Esempio n. 7
0
        public async Task Delete_Admin_Success(string url)
        {
            // Arrange
            var client = _factory.CreateClient();

            client.DefaultRequestHeaders.Authorization = AutorizationHeader.CreateRoleAuthorizationHeader(UserDataGenerator.Admin);

            // Act
            var response = await client.DeleteAsync(url + UserDataGenerator.GuidUserPageOne);

            // Assert
            response.EnsureSuccessStatusCode();
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
Esempio n. 8
0
        public async Task Put_No_Admin_Forbidden(string url)
        {
            // Arrange
            var client = _factory.CreateClient();

            client.DefaultRequestHeaders.Authorization = AutorizationHeader.CreateRoleAuthorizationHeader(UserDataGenerator.NoRole);

            var userDto = new UserDto();

            // Act
            var response = await client.PutAsync(url, new StringContent(JsonConvert.SerializeObject(userDto), Encoding.UTF8, "application/json"));

            // Assert
            Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
        }
Esempio n. 9
0
        public async Task Put_Admin_User_Not_Exist(string url)
        {
            // Arrange
            var client = _factory.CreateClient();

            client.DefaultRequestHeaders.Authorization = AutorizationHeader.CreateRoleAuthorizationHeader(UserDataGenerator.Admin);

            var userDto = new UserDto();

            userDto.Id = Guid.NewGuid().ToString();

            // Act
            var response = await client.PutAsync(url,
                                                 new StringContent(JsonConvert.SerializeObject(userDto), Encoding.UTF8, "application/json"));

            // Assert
            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
        }
Esempio n. 10
0
        public async Task Post_Admin_Success(string url)
        {
            // Arrange
            var client = _factory.CreateClient();

            client.DefaultRequestHeaders.Authorization = AutorizationHeader.CreateRoleAuthorizationHeader(UserDataGenerator.Admin);

            var userDto = new UserDto
            {
                Username = UserSeed.Username,
                Password = UserSeed.Password,
                Id       = Guid.NewGuid().ToString()
            };

            // Act
            var response = await client.PostAsync(url, new StringContent(JsonConvert.SerializeObject(userDto), Encoding.UTF8, "application/json"));

            // Assert
            response.EnsureSuccessStatusCode();
        }