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); }
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)); }
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); }
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()); }
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); }
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); }
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); }
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); }