Exemplo n.º 1
0
        public async Task GetAll()
        {
            var token = MockJwtTokens.GenerateJwtToken(ClaimsData.GetClaims());

            _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            var response = await _client.GetAsync("api/animals/getall");
        }
Exemplo n.º 2
0
        public async Task TokenAthorizeTest()
        {
            var token = MockJwtTokens.GenerateJwtToken(ClaimsData.GetClaims());

            _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            var response = await _client.GetAsync("api/animals/getall");

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }
Exemplo n.º 3
0
        public async Task TokenAuthorizeTest()
        {
            var token = MockJwtTokens.GenerateJwtToken(ClaimsData.GetClaims());

            Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            var response = await Client.GetAsync("api/users/getall");

            response.StatusCode.Should().Be(HttpStatusCode.OK);
        }
Exemplo n.º 4
0
        public async Task TokenExpiredTest()
        {
            var token = MockJwtTokens.GenerateJwtToken(ClaimsData.GetClaims());

            _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            Thread.Sleep(10000);

            var response = await _client.GetAsync("api/users/getall");

            Assert.AreEqual(HttpStatusCode.Unauthorized, response.StatusCode);
        }
Exemplo n.º 5
0
        public async Task TokenAuthorizeTest()
        {
            //Arrange
            var token = MockJwtTokens.GenerateJwtToken(ClaimsData.GetClaims());

            Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(AuthenticationScheme, token);

            //Act
            var response = await Client.GetAsync(RequestUri);

            //Assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);
        }
Exemplo n.º 6
0
        public async Task GetAll()
        {
            const string authenticationScheme = "Bearer";
            const string requestUri           = "api/users/getall";

            //Arrange
            var token = MockJwtTokens.GenerateJwtToken(ClaimsData.GetClaims());

            Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(authenticationScheme, token);

            //Act
            var response = await Client.GetAsync(requestUri);

            //Assert
            response.StatusCode.Should()?.Be(HttpStatusCode.OK);
        }
Exemplo n.º 7
0
        public async Task TokenExpiredTest()
        {
            const int delayAmount = 10000;

            //Arrange
            var token = MockJwtTokens.GenerateJwtToken(ClaimsData.GetClaims());

            Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(AuthenticationScheme, token);

            //Act
            await Task.Delay(delayAmount);

            var response = await Client.GetAsync(RequestUri);

            //Assert
            response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
        }
Exemplo n.º 8
0
        public async Task TokenAuthorizeTest()
        {
            // Arrange
            var token = MockJwtTokens.GenerateJwtToken(ClaimsData.GetClaims());

            HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(AuthenticationScheme, token);
            var cache = new MemoryCacheManager();

            cache.Add($"{CacheKeys.UserIdForClaim}=1", new List <string>()
            {
                "GetUsersQuery"
            });
            // Act
            var response = await HttpClient.GetAsync(RequestUri);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);
        }