public async Task Should_Get_User_Profile_When_User_Found()
        {
            //Arrange
            var applicationUser = new ApplicationUser
            {
                Email        = String.Empty,
                UserName     = String.Empty,
                FirstName    = "Test",
                LastName     = "Test",
                Id           = 1,
                PasswordHash = String.Empty
            };
            var message = new UserQuery(applicationUser.Id);

            Mock <IUserManagerService> userManagerService = new Mock <IUserManagerService>();

            userManagerService.Setup(s => s.GetUserById(It.IsAny <int>())).ReturnsAsync(applicationUser);
            var sut = new UserQueryHandler(userManagerService.Object, _mapper);

            //ActT
            var result = await sut.Handle(message, default);

            //Assert
            result.ShouldNotBeNull();
            result.ShouldBeOfType <UserDetailInfoDto>();
            result.Id.ShouldBe(applicationUser.Id);
            result.FirstName.ShouldBe(applicationUser.FirstName);
            result.LastName.ShouldBe(applicationUser.LastName);
        }
Ejemplo n.º 2
0
        public async Task UserDoesNotExist()
        {
            var query = new UserQuery {
                UserId = string.Empty
            };
            var handler = new UserQueryHandler(Context);
            var result  = await handler.Handle(query);

            Assert.Null(result);
        }
Ejemplo n.º 3
0
        public async Task UserExists()
        {
            var query = new UserQuery()
            {
                UserId = _userId
            };
            var handler = new UserQueryHandler(Context);
            var result  = await handler.Handle(query);

            Assert.NotNull(result);
        }
Ejemplo n.º 4
0
        public ActionResult Login(LoginViewModel user)
        {
            var result = _userQuery.Handle(new UserInputLogin {
                Password = user.Password, UserName = user.UserName
            });

            if (result.UserId != Guid.Empty)
            {
                Authentication.UserAuthenticated = true;
                Authentication.UserId            = result.UserId;
            }
            else
            {
                user.Feedback = "Não foi possivel efetuar o Login.";
                return(View(user));
            }
            return(RedirectToAction("Index", "Home"));
        }
        public async Task Should_Throw_NotFoundException_In_Get_User_Profile_When_User_Not_Found()
        {
            //Arrange
            var applicationUser = new ApplicationUser
            {
                Email        = String.Empty,
                UserName     = String.Empty,
                FirstName    = "Test",
                LastName     = "Test",
                Id           = 1,
                PasswordHash = String.Empty
            };
            var message = new UserQuery(applicationUser.Id);

            Mock <IUserManagerService> userManagerService = new Mock <IUserManagerService>();

            userManagerService.Setup(s => s.GetUserById(It.IsAny <int>())).Throws <NotFoundException>();
            var sut = new UserQueryHandler(userManagerService.Object, _mapper);

            //Act/Assert
            await Assert.ThrowsAsync <NotFoundException>(async() => { await sut.Handle(message, default); });
        }
Ejemplo n.º 6
0
        public ActionResult <UserViewModel> login(LoginViewModel credentialsModel)
        {
            var user = _query.Handle(new GetUsername {
                Username = credentialsModel.Username
            });

            using var hmac = new HMACSHA512(user.PasswordSalt);

            var computedHash = hmac.ComputeHash(Encoding.UTF8.GetBytes(credentialsModel.Password));

            for (int i = 0; i < computedHash.Length; i++)
            {
                if (computedHash[i] != user.PasswordHash[i])
                {
                    return(new UnauthorizedResult());
                }
            }

            return(new UserViewModel
            {
                Username = credentialsModel.Username,
                Token = _token.CreateToken(user)
            });
        }
Ejemplo n.º 7
0
        public IEnumerable <User> QueryUsers(UserListQuery command)
        {
            var handler = new UserQueryHandler();

            return(handler.Handle(command));
        }
Ejemplo n.º 8
0
        public User QueryUserDetails(UserDetailsQuery command)
        {
            var handler = new UserQueryHandler();

            return(handler.Handle(command));
        }
Ejemplo n.º 9
0
 protected bool UserIsInRole(string role)
 {
     return(_userQuery.Handle(new UserInputIsInRole {
         Role = role, UserId = Authentication.UserId
     }).IsInRole);
 }
Ejemplo n.º 10
0
 public IEnumerable <User> GetAllUsers()
 {
     return(_query.Handle());
 }