コード例 #1
0
        public void CanEncodeToken()
        {
            // arrange
            var token            = Guid.NewGuid().ToString();
            var jwtIssuerOptions = new JwtIssuerOptions
            {
                Issuer             = "",
                Audience           = "",
                SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(Encoding.ASCII.GetBytes("secretkey")), SecurityAlgorithms.HmacSha256)
            };

            var mockJwtTokenHandler = new Mock <IJwtTokenHandler>();

            mockJwtTokenHandler.Setup(handler => handler.WriteToken(It.IsAny <JwtSecurityToken>())).Returns(token);
            var jwtFactory = new JwtFactory(mockJwtTokenHandler.Object, Options.Create(jwtIssuerOptions));

            // act
            var result = jwtFactory.EncodeToken("userName");

            // assert
            Assert.Equal(token, result);
        }