public async Task TestRevokeAsync() { var insert = await CassandraTestHelper.InsertTestData_Tokens(10); ITokenHandleStore ths = new TokenHandleStore(); var subjectId = insert[0].SubjectId; var clientId = insert[0].ClientId; var find_metadata = await ths.GetAllAsync(subjectId); Assert.AreEqual(find_metadata.Count(), insert.Count); await ths.RevokeAsync(subjectId, clientId); find_metadata = await ths.GetAllAsync(subjectId); Assert.AreEqual(find_metadata.Count(), 0); }
public void TestGetAllAsync() { var insert = InsertTestData(_clientStore, _scopeStore, _tokenHandleStore, 10); Guid id = insert[0].Id; var subject = insert[0].Record.SubjectId; var result = _tokenHandleStore.GetAllAsync(subject); Assert.IsNotNull(result.Result); Assert.AreEqual(result.Result.Count(), 5); }
public void GetAllAsync_WhenCalled_ExpectThrows() { // Arrange var mockCacheManager = new Mock<ICacheManager<Token>>(); var mockCacheConfiguration = new Mock<IConfiguration<RedisCacheConfigurationEntity>>(); mockCacheConfiguration.Setup(r => r.Get).Returns(new RedisCacheConfigurationEntity { CacheDuration = 1 }); var tokenHandleStore = new TokenHandleStore( mockCacheManager.Object, mockCacheConfiguration.Object); // Act and Assert var stopwatch = Stopwatch.StartNew(); Assert.Throws<NotImplementedException>( () => tokenHandleStore.GetAllAsync("string").GetAwaiter().GetResult()); stopwatch.Stop(); this.WriteTimeElapsed(stopwatch); }
public async Task GetAllAsync() { //Arrange var sut = new TokenHandleStore(NhibernateSession, ScopeStoreMock.Object, ClientStoreMock.Object); var subjectId1 = Guid.NewGuid().ToString(); var subjectId2 = Guid.NewGuid().ToString(); var testKey1 = Guid.NewGuid().ToString(); var testCode1 = ObjectCreator.GetTokenHandle(subjectId1); var tokenHandle1 = new Token { Key = testKey1, SubjectId = testCode1.SubjectId, ClientId = testCode1.ClientId, JsonCode = ConvertToJson(testCode1), Expiry = DateTime.UtcNow.AddSeconds(testCode1.Client.AuthorizationCodeLifetime), TokenType = TokenType.TokenHandle }; var testKey2 = Guid.NewGuid().ToString(); var testCode2 = ObjectCreator.GetTokenHandle(subjectId1); var tokenHandle2 = new Token { Key = testKey2, SubjectId = testCode2.SubjectId, ClientId = testCode2.ClientId, JsonCode = ConvertToJson(testCode2), Expiry = DateTime.UtcNow.AddSeconds(testCode2.Client.AuthorizationCodeLifetime), TokenType = TokenType.TokenHandle }; var testKey3 = Guid.NewGuid().ToString(); var testCode3 = ObjectCreator.GetTokenHandle(subjectId2); var tokenHandle3 = new Token { Key = testKey3, SubjectId = testCode3.SubjectId, ClientId = testCode3.ClientId, JsonCode = ConvertToJson(testCode3), Expiry = DateTime.UtcNow.AddSeconds(testCode3.Client.AuthorizationCodeLifetime), TokenType = TokenType.TokenHandle }; var testKey4 = Guid.NewGuid().ToString(); var testCode4 = ObjectCreator.GetTokenHandle(subjectId2); var tokenHandle4 = new Token { Key = testKey4, SubjectId = testCode4.SubjectId, ClientId = testCode4.ClientId, JsonCode = ConvertToJson(testCode4), Expiry = DateTime.UtcNow.AddSeconds(testCode4.Client.AuthorizationCodeLifetime), TokenType = TokenType.TokenHandle }; SetupScopeStoreMock(); ExecuteInTransaction(session => { session.SaveOrUpdate(tokenHandle1); session.SaveOrUpdate(tokenHandle2); session.SaveOrUpdate(tokenHandle3); session.SaveOrUpdate(tokenHandle4); }); //Act var tokens = (await sut.GetAllAsync(subjectId1)).ToList(); //Assert Assert.True(tokens.Count == 2); Assert.True(tokens.All(t => t.SubjectId == subjectId1)); //CleanUp ExecuteInTransaction(session => { session.Delete(tokenHandle1); session.Delete(tokenHandle2); session.Delete(tokenHandle3); session.Delete(tokenHandle4); }); }