Ejemplo n.º 1
0
        public void CreateToken_ShouldReturnResultOfExpectedLength()
        {
            //arrange
            var appSettings  = Options.Create(MockAppSettings().Object);
            var tokenManager = new TokenManager(appSettings, TestDateTime());

            //act
            var result = tokenManager.CreateToken(UserModelHelper.GetUser());

            //assert
            Assert.NotSame(7, result.Length);
        }
Ejemplo n.º 2
0
        public void CreateToken_ShouldReturnBearerString()
        {
            //arrange
            var appSettings  = Options.Create(MockAppSettings().Object);
            var tokenManager = new TokenManager(appSettings, TestDateTime());

            //act
            var result = tokenManager.CreateToken(UserModelHelper.GetUser());

            //assert
            Assert.NotSame(-1, result.IndexOf("Bearer ", StringComparison.Ordinal));
        }
Ejemplo n.º 3
0
        public void CreateJsonWebToken_ValidFromSultMatchTestDateTime()
        {
            //arrange
            var userModel    = UserModelHelper.GetUser();
            var appSettings  = MockAppSettings();
            var tokenManager = new TokenManager(Options.Create(appSettings.Object), TestDateTime());

            //act
            var result = tokenManager.CreateJsonWebToken(userModel);

            //assert
            Assert.Equal(TestDateTime(), result.ValidFrom);
        }
Ejemplo n.º 4
0
        public void CreateJsonWebToken_TokenAudienceShouldMatchExpectedString()
        {
            //arrange
            var userModel    = UserModelHelper.GetUser();
            var appSettings  = MockAppSettings();
            var tokenManager = new TokenManager(Options.Create(appSettings.Object), TestDateTime());

            //act
            var result = tokenManager.CreateJsonWebToken(userModel);

            //assert
            Assert.Equal("ThoseWhoRock", result.Audiences.FirstOrDefault());
        }
Ejemplo n.º 5
0
        public void CreateJsonWebToken_TokenIssuerShouldMatchExpectedString()
        {
            //arrange
            var userModel    = UserModelHelper.GetUser();
            var appSettings  = MockAppSettings();
            var tokenManager = new TokenManager(Options.Create(appSettings.Object), TestDateTime());

            //act
            var result = tokenManager.CreateJsonWebToken(userModel);

            //assert
            Assert.Equal("FusionAlliance", result.Issuer);
        }
Ejemplo n.º 6
0
        public void CreateJsonWebToken_ShoulReturnJwtSecurityToken()
        {
            //arrange
            var userModel    = UserModelHelper.GetUser();
            var appSettings  = MockAppSettings();
            var tokenManager = new TokenManager(Options.Create(appSettings.Object), TestDateTime());

            //act
            var result = tokenManager.CreateJsonWebToken(userModel);

            //assert
            Assert.IsType(typeof(JwtSecurityToken), result);
        }
Ejemplo n.º 7
0
        public void CreateJsonWebToken_TokenExperationMinutesShouldBeAccessedOnce()
        {
            //arrange
            var userModel    = UserModelHelper.GetUser();
            var appSettings  = MockAppSettings();
            var tokenManager = new TokenManager(Options.Create(appSettings.Object), TestDateTime());

            //act
            var result = tokenManager.CreateJsonWebToken(userModel);

            //assert
            appSettings.VerifyGet(i => i.TokenSettings.ExpirationMinutes, Times.Once);
        }
Ejemplo n.º 8
0
        public void CreateJsonWebToken_ValidToShouldMatchExpectedDateTime()
        {
            //arrange
            var userModel    = UserModelHelper.GetUser();
            var appSettings  = MockAppSettings();
            var tokenManager = new TokenManager(Options.Create(appSettings.Object), TestDateTime());

            //act
            var result = tokenManager.CreateJsonWebToken(userModel);

            //assert
            Assert.Equal(TestDateTime().AddMinutes(5), result.ValidTo);
        }
        public void CreateJsonWebToken_ResultShouldHaveCorrectClaimsCount()
        {
            //arrange
            var userModel    = UserModelHelper.GetUser();
            var appSettings  = MockAppSettings();
            var tokenManager = new TokenManager(Options.Create(appSettings.Object), TestDateTime());

            //act
            var result = tokenManager.CreateJsonWebToken(userModel);

            //assert
            Assert.Equal(9, result.Claims.Count());
        }
        public void GetClaims_ShouldReturnNonAdministratorUser()
        {
            //arrange
            var userModel    = UserModelHelper.GetUser();
            var appSettings  = Options.Create(new AppSettings());
            var tokenManager = new TokenManager(appSettings);

            //act
            var result = tokenManager.GetClaims(userModel);

            //assert
            Assert.False(Convert.ToBoolean(result.ToList().FirstOrDefault(i => i.Type == AutoRenterClaimNames.IsAdministrator).Value));
        }
        public void GetClaims_ShouldReturnMatchingLastNameClaim()
        {
            //arrange
            var userModel    = UserModelHelper.GetUser();
            var appSettings  = Options.Create(new AppSettings());
            var tokenManager = new TokenManager(appSettings);

            //act
            var result = tokenManager.GetClaims(userModel);

            //assert
            Assert.Equal(userModel.LastName, result.ToList().FirstOrDefault(i => i.Type == AutoRenterClaimNames.LastName).Value);
        }
        public void GetClaims_ShouldReturnArraryOfExpectedLength()
        {
            //arrange
            var userModel    = UserModelHelper.GetUser();
            var appSettings  = Options.Create(new AppSettings());
            var tokenManager = new TokenManager(appSettings);

            //act
            var result = tokenManager.GetClaims(userModel);

            //assert
            Assert.Equal(5, result.Length);
        }