Example #1
0
        public void GetCurrentUser_Returns_CurrentUser_With_Empty_Guid()
        {
            //Arrange
            var mockHttpContextAccessor = new Mock <IHttpContextAccessor>();
            var claims = new List <Claim>
            {
                new Claim(ClaimTypes.Email, "*****@*****.**"),
                new Claim("firstName", "Normal"),
                new Claim(ClaimTypes.Role, "Normal"),
                new Claim("lastName", "Access"),
            };
            var claimsIdentity = new ClaimsIdentity();

            claimsIdentity.AddClaims(claims);
            var claimsPrincipal = new ClaimsPrincipal(claimsIdentity);

            mockHttpContextAccessor.Setup(d => d.HttpContext !.User).Returns(claimsPrincipal);
            var service = new UserAccessorService(mockHttpContextAccessor.Object);

            //Act
            var result = service.GetCurrentUser();

            //Assert
            result.Should().NotBeNull().And.BeOfType <CurrentUser>();
            result !.UserId.Should().Be(Guid.Empty);
        }
        public void ParseValidJwtString()
        {
            var clock = FakeClock.FromUtc(2020, 01, 16, 12, 0, 0);

            bool success = JsonWebToken.TryParseFromJwtString(JWT_STRING, clock, out var jwt);

            success.Should().BeTrue();
            jwt.Should().NotBeNull();
            jwt !.UserId.Should().Be(UserId);
        }