public async Task VarifyUserAsync_ShouldReturnAppUserObject()
        {
            //preparing the Data Access Layer class that going in the Busineess Logic class
            //Mocking
            //1. Arrange
            var mockDalClass = new Mock <IAppUserDal>();
            //hash of password qwer1234
            var hashedPassword = "******";

            mockDalClass.Setup(x => x.GetAppUserByIdAsync(It.IsAny <string>()))
            .ReturnsAsync(new AppUser()
            {
                No       = 1,
                Id       = "test123",
                NickName = "nickDan"
                ,
                Password    = hashedPassword,
                AccessLevel = 1
            });

            var userBll = new AppUserBll(mockDalClass.Object);

            //2. Act
            var returnAppUser = await userBll.VerifyUserAsync("test123", "qwer1234");

            //3.Assert
            Assert.NotNull(returnAppUser);
        }
Example #2
0
        public async Task <ActionResult <AppUser> > LogicAsync([FromBody] AppUser userDto)
        {
            var resultUser = await _userBll.VerifyUserAsync(userDto.Id, userDto.Password);

            if (resultUser == null)
            {
                return(Unauthorized());
            }

            var userClaims = _userBll.GenerateClaimsIdentity(resultUser);

            var jwtToken = this.GenerateJwtToken(userClaims);

            HttpContext.User = new ClaimsPrincipal(userClaims);
            this.RefreshCSRFToken();

            HttpContext.Response.Cookies.Append("jwt", jwtToken, new CookieOptions()
            {
                HttpOnly = false
            });

            return(Ok(resultUser.NickName));
        }