Пример #1
0
        public async Task GenerateJwtTokenAsync()
        {
            string email    = "*****@*****.**";
            string password = "******";

            var identity = await GetClaimsIdentity(email, password);

            if (identity == null)
            {
                throw new ServiceException(HttpStatusCode.Unauthorized, "Failed Login attempt");
            }
            var jwtFactory = new Mock <IJwtFactory>();

            jwtFactory.Setup(It => It.GenerateEncodedToken(email, userDomain.Name, identity))
            .Returns(Task.FromResult("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJwY2F2YXVsdEBnbWFpbC5jb20iLCJqdGkiOiIwYzgzMTE3YS05NmUzLTQ4ZTYt" +
                                     "ODBjYi1jM2IwZGQ1MjYzYmIiLCJpYXQiOjE1MjQ0ODIxMjAsInJvbGUiOiJhcGlfYWNjZXNzIiwiaWQiOiI3OWZkMjU2Yi1kMDY2LTQ0MTktOG" +
                                     "I0OC1iMGZjN2M2OTkxNTQiLCJuYmYiOjE1MjQ0ODIxMjAsImV4cCI6MTUyNDQ4NTcyMCwiaXNzIjoiUGNhSWRlbnRpdHlTZXJ2aWNlIiwiYXVkI" +
                                     "joiaHR0cDovL2xvY2FsaG9zdDoyNTMxOC8ifQ.L9J4fTyN7rHyuHgPyzj6ZC179xB13HBu1ft0_4Kp_O8"));

            string token = await Tokens.GenerateJwt(identity, jwtFactory.Object, email, userDomain.Name, new JsonSerializerSettings { Formatting = Formatting.Indented });

            Assert.NotNull(token);
        }