Esempio n. 1
0
        public async Task CreateAccessTokenAsync_IfCorrect_ShouldReturSuccessResult()
        {
            Guid userId = new Guid();

            User user = new User
            {
                Id = userId
            };

            IDataResult <List <Role> > claims = new SuccessDataResult <List <Role> >(new List <Role> {
                new Role
                {
                    Name = "Test Name 1"
                }
            });

            AccessToken accessToken = new AccessToken
            {
                Token      = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImFobWV0dW5nZUBvdXRsb29rLmNvbSIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL25hbWUiOiJBaG1ldCDDnG5nZSIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL25hbWVpZGVudGlmaWVyIjoiY2Q3NDQ3MGMtNGNlNy00ODE3LWJjZTYtZmY5YzMxZDM2Y2Y0IiwiaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS93cy8yMDA4LzA2L2lkZW50aXR5L2NsYWltcy9yb2xlIjoiQWRtaW4iLCJuYmYiOjE1ODQyNzY4MjIsImV4cCI6MTU4NDI3NzQyMiwiaXNzIjoid3d3LmFobWV0dW5nZS5jb20iLCJhdWQiOiJ3d3cuYWhtZXR1bmdlLmNvbSJ9.FeWXYaH4_1YrCW2jz3HqyDS4lD3FGNoDHk5M0e-LgnQ",
                Expiration = new DateTime(1907, 10, 20)
            };

            _mockUserService.Setup(s => s.GetRolesAsync(It.IsAny <Guid>()))
            .ReturnsAsync(claims);

            _mockTokenHelper.Setup(th => th.CreateToken(It.IsAny <User>(), It.IsAny <List <Role> >()))
            .Returns(accessToken);


            AuthManager authManager = new AuthManager(_mockUserService.Object, _mockTokenHelper.Object);


            IDataResult <AccessToken> result = await authManager.CreateAccessTokenAsync(user);

            Assert.True(result.Success);

            Assert.Equal(accessToken.Token, result.Data.Token);
            Assert.Equal(accessToken.Expiration, result.Data.Expiration);
        }