public void ShouldReturnCurrentLoggedInUser()
            {
                var securityContext = A.Fake <ISecurityContext>();

                ConfigureSecurityContextFactory_ToReturn(securityContext);
                var expectedRequest = new GetCurrentUserRequest {
                    SecurityContext = securityContext
                };

                var expectedUser = new Api.Models.User {
                    UniqueId = Guid.NewGuid()
                };

                A.CallTo(() => _getCurrentUserHandler.Handle(A <GetCurrentUserRequest> .That.HasSamePropertyValuesAs(expectedRequest))).Returns(expectedUser);

                var actual = Get();

                Assert.That(actual.StatusCode, Is.EqualTo(HttpStatusCode.OK));
                var actualDeserialized = actual.Body.DeserializeJson <Api.Models.User>();

                Assert.That(actualDeserialized.HasSamePropertyValuesAs(expectedUser));

                A.CallTo(() => _getCurrentUserHandler
                         .Handle(A <GetCurrentUserRequest> .That.Matches(req => req.HasSamePropertyValuesAs(expectedRequest))))
                .MustHaveHappened();
            }
Exemplo n.º 2
0
        public async Task <IActionResult> GetCurrentUser([FromQuery] GetCurrentUserRequest request)
        {
            var response = await mediator.Send(request);

            Log.Information($"User #{HttpContext.GetCurrentUserId()} displayed profile");

            return(this.CreateResponse(response));
        }
        public void ValidRequest_IsValid()
        {
            var input = new GetCurrentUserRequest {
                SecurityContext = A.Dummy <ISecurityContext>()
            };
            var actualResult = _sut.Validate(input);

            Assert.That(actualResult.IsValid, Is.True);
        }
        public void NullContext_IsInvalid()
        {
            var input = new GetCurrentUserRequest {
                SecurityContext = null
            };
            var actualResult = _sut.Validate(input);

            Assert.That(actualResult.IsValid, Is.False);
        }
Exemplo n.º 5
0
        public GetCurrentUserResponse GetCurrentUser(GetCurrentUserRequest request)
        {
            GetCurrentUserResponse    response = new GetCurrentUserResponse();
            SecurityBusinessComponent bc       = DependencyInjectionHelper.GetSecurityBusinessComponent();

            User user = bc.GetUserByName(Thread.CurrentPrincipal.Identity.Name);

            response.User = SecurityAdapter.UserToCurrentUserDTO(user);

            return(response);
        }
        public void GivenContextWithoutUser_ReturnsNull()
        {
            ConfigureSecurityContext_ToReturn(null);
            var request = new GetCurrentUserRequest {
                SecurityContext = _securityContext
            };

            var actual = _sut.Handle(request).Result;

            Assert.That(actual, Is.Null);
        }
        public void GivenContextWithValidUser_ReturnsUser()
        {
            var user = new User {
                Login = new Login {
                    Value = "JohnD"
                }
            };

            ConfigureSecurityContext_ToReturn(user);
            var request = new GetCurrentUserRequest {
                SecurityContext = _securityContext
            };

            var actual = _sut.Handle(request).Result;

            Assert.That(actual, Is.Not.Null);
            Assert.That(actual, Is.EqualTo(user));
        }
Exemplo n.º 8
0
            public async Task GivenContextWithUser_ReturnsAdaptedUser()
            {
                var user = new User {
                    Login = new Login {
                        Value = "JohnD"
                    }, LastName = "Doe"
                };

                ConfigureSecurityContext_ToReturn(user);
                var request = new GetCurrentUserRequest {
                    SecurityContext = _securityContext
                };

                var expected = new Api.Models.User {
                    LastName = "Doe"
                };

                A.CallTo(() => _userAdapter.Adapt(user)).Returns(expected);

                var actual = await _sut.Handle(request);

                actual.ShouldBeEquivalentTo(expected);
            }
Exemplo n.º 9
0
        public GetCurrentUserResponse GetCurrentUser(GetCurrentUserRequest request)
        {
            GetCurrentUserResponse response = new GetCurrentUserResponse();
            SecurityBusinessComponent bc = DependencyInjectionHelper.GetSecurityBusinessComponent();

            User user = bc.GetUserByName(Thread.CurrentPrincipal.Identity.Name);
            response.User = SecurityAdapter.UserToCurrentUserDTO(user);

            return response;
        }