Ejemplo n.º 1
0
        public async Task Invoke_AttachsUserToContext_WhenTokenNotNull()
        {
            // Arrange
            var newAuthenticateRequest = new AuthenticateRequestDto
            {
                Username = "******",
                Password = "******"
            };
            var response = await _testingService.AuthenticateAsync(newAuthenticateRequest);

            _mockContext.Request.Headers.Add("Authorization", response.Token);

            // Act
            await _authenticationMiddleware.InvokeAsync(_mockContext, _next);

            // Assert
            Assert.True(_mockContext.Items.TryGetValue("User", out var header));
            var user = header as Task <UserDto>;

            Assert.Equal(2, user.Result.Id);
        }
Ejemplo n.º 2
0
        public async Task Invoke_AttachsUserToContext_WhenTokenNotNull()
        {
            // Arrange
            var newAuthenticateRequest = new AuthenticateRequestDto
            {
                Username = "******",
                Password = "******"
            };
            var response = await _userController.AuthenticateAsync(newAuthenticateRequest);

            var result = response.Result as OkObjectResult;

            _mockContext.Request.Headers.Add("Authorization",
                                             _mockMapper.Map <AuthenticateResponseDto>(result.Value).Token);

            // Act
            await _authenticationMiddleware.InvokeAsync(_mockContext, _next);

            // Assert
            Assert.True(_mockContext.Items.TryGetValue("User", out var header));
            var user = header as Task <User>;

            Assert.Equal(2, user.Result.Id);
        }