public async Task RemoveAll_Entries() { var now = DateTime.Now; _clock.Setup(x => x.UtcNow).Returns(now); string subjectId = $"{nameof(RemoveAll_Entries)}-subjectId"; var expected = Enumerable.Range(0, 5).Select(x => new PersistedGrant { Key = $"{nameof(RemoveAll_Entries)}-{now:O}-{x}", SubjectId = subjectId, Expiration = now.AddSeconds(2), ClientId = "client1", Type = "type1", } ).ToList(); Task.WaitAll(expected.Select(x => _store.StoreAsync(x)).ToArray()); await _store.RemoveAllAsync(subjectId, "client1"); var actual = (await _store.GetAllAsync(subjectId)).ToList(); Assert.Empty(actual); }
public async Task PersistedGrantStore_RemoveSubjectClientTypeSessionTest() { var storageContext = Services.BuildServiceProvider().GetService <PersistedGrantStorageContext>(); Assert.IsNotNull(storageContext); var store = new PersistedGrantStore(storageContext, _logger); Assert.IsNotNull(store); string subject = Guid.NewGuid().ToString(); string client = Guid.NewGuid().ToString(); string type = Guid.NewGuid().ToString(); string session = Guid.NewGuid().ToString(); List <PersistedGrant> grants = new List <PersistedGrant>(); for (int iCounter = 0; iCounter < 10; iCounter++) { var grant = CreateTestObject(subjectId: subject, clientId: client, type: type, session: (session + iCounter.ToString())); Console.WriteLine(JsonConvert.SerializeObject(grant)); await store.StoreAsync(grant); grants.Add(grant); } string sessionTarget = session + "0"; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); var returnGrants = (await store.GetAllAsync(new PersistedGrantFilter() { SubjectId = subject, ClientId = client, Type = type, SessionId = sessionTarget })).ToList(); stopwatch.Stop(); Console.WriteLine($"PersistedGrantStore.GetAllAsync({subject}, {client}, {type}, {sessionTarget}): {stopwatch.ElapsedMilliseconds} ms"); Assert.AreEqual <int>(1, returnGrants.Count); returnGrants.ForEach(g => AssertGrantsEqual(g, grants.FirstOrDefault(f => f.Key == g.Key))); stopwatch.Reset(); stopwatch.Start(); await store.RemoveAllAsync(new PersistedGrantFilter() { SubjectId = subject, ClientId = client, Type = type, SessionId = sessionTarget }); stopwatch.Stop(); Console.WriteLine($"PersistedGrantStore.RemoveAllAsync({subject}, {client}, {type}, {sessionTarget}): {stopwatch.ElapsedMilliseconds} ms"); returnGrants = (await store.GetAllAsync(new PersistedGrantFilter() { SubjectId = subject, ClientId = client, Type = type })).ToList(); Assert.AreEqual <int>(grants.Count - 1, returnGrants.Count); }
public void GetAsync_WithSubAndTypeAndPersistedGrantExists_ExpectPersistedGrantReturned( DbContextOptions <PersistedGrantDbContext> options) { var persistedGrant = CreateTestObject(); using (var context = new PersistedGrantDbContext(options, StoreOptions)) { context.PersistedGrants.Add(persistedGrant.ToEntity()); context.SaveChanges(); } IList <PersistedGrant> foundPersistedGrants; using (var context = new PersistedGrantDbContext(options, StoreOptions)) { var store = new PersistedGrantStore( context, NullLogger <PersistedGrantStore> .Create() ); foundPersistedGrants = store .GetAllAsync(persistedGrant.SubjectId).Result .ToList(); } Assert.NotNull(foundPersistedGrants); Assert.NotEmpty(foundPersistedGrants); }
public async Task GetAsync_WithSubAndTypeAndPersistedGrantExists_ExpectPersistedGrantReturned() { using var ravenStore = GetDocumentStore(); await new PersistentGrantIndex().ExecuteAsync(ravenStore); var persistedGrant = CreateTestObject(); using (var session = ravenStore.OpenSession()) { session.Store(persistedGrant.ToEntity()); session.SaveChanges(); } WaitForIndexing(ravenStore); IList <PersistedGrant> foundPersistedGrants; using (var session = ravenStore.OpenAsyncSession()) { var store = new PersistedGrantStore(session, FakeLogger <PersistedGrantStore> .Create()); var filter = new PersistedGrantFilter { SubjectId = persistedGrant.SubjectId }; foundPersistedGrants = (await store.GetAllAsync(filter)).ToList(); } Assert.NotNull(foundPersistedGrants); Assert.NotEmpty(foundPersistedGrants); }
public async Task GetAsync_WithSubAndTypeAndPersistedGrantExists_ExpectPersistedGrantReturned() { var storeHolder = GetOperationalDocumentStoreHolder(); var persistedGrant = CreateTestObject(); using (var session = storeHolder.OpenAsyncSession()) { await session.StoreAsync(persistedGrant.ToEntity()); await session.SaveChangesAsync(); } WaitForIndexing(storeHolder.IntegrationTest_GetDocumentStore()); var store = new PersistedGrantStore(storeHolder, FakeLogger <PersistedGrantStore> .Create()); var filter = new PersistedGrantFilter { SubjectId = persistedGrant.SubjectId }; var foundPersistedGrants = (await store.GetAllAsync(filter)).ToList(); Assert.NotNull(foundPersistedGrants); Assert.NotEmpty(foundPersistedGrants); }
public async Task PersistedGrantStore_SaveGetBySubjectTest() { var storageContext = Services.BuildServiceProvider().GetService <PersistedGrantStorageContext>(); Assert.IsNotNull(storageContext); var store = new PersistedGrantStore(storageContext, _logger); Assert.IsNotNull(store); string subject = Guid.NewGuid().ToString(); List <PersistedGrant> grants = new List <PersistedGrant>(); for (int iCounter = 0; iCounter < 10; iCounter++) { var grant = CreateTestObject(subjectId: subject); Console.WriteLine(JsonConvert.SerializeObject(grant)); await store.StoreAsync(grant); grants.Add(grant); } Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); var returnGrants = (await store.GetAllAsync(subject)).ToList(); stopwatch.Stop(); Console.WriteLine($"PersistedGrantStore.GetAllAsync({subject}): {stopwatch.ElapsedMilliseconds} ms"); Assert.AreEqual <int>(grants.Count, returnGrants.Count); grants.ForEach(g => AssertGrantsEqual(g, returnGrants.FirstOrDefault(f => f.Key == g.Key))); }
public async void GetAllBySubjectId() { //Arrange var subjectId = "subjectId5"; //Act var result = await PersistedGrantStore.GetAllAsync(subjectId); //Assert result.Should().HaveCountGreaterThan(0); }
public async Task GetAllAsync_Retrieves_All_Grants_For_SubjectId() { var now = DateTime.Now; _clock.Setup(x => x.UtcNow).Returns(now); string subjectId = $"{nameof(GetAllAsync_Retrieves_All_Grants_For_SubjectId)}-subjectId"; var expected = Enumerable.Range(0, 5).Select(x => new PersistedGrant { Key = $"{nameof(GetAllAsync_Retrieves_All_Grants_For_SubjectId)}-{now:O}-{x}", SubjectId = subjectId, Expiration = now.AddSeconds(2) } ).ToList(); Task.WaitAll(expected.Select(x => _store.StoreAsync(x)).ToArray()); var actual = (await _store.GetAllAsync(subjectId)).ToList(); Assert.NotNull(actual); actual.Should().BeEquivalentTo(expected); }
public void GetAsync_WithSubAndTypeAndPersistedGrantExists_ExpectPersistedGrantReturned() { var store = new PersistedGrantStore(new TestOptions(), new FakeLogger <PersistedGrantStore>()); var persistedGrant = CreateTestObject(); store.StoreAsync(persistedGrant).Wait(); var foundPersistedGrants = store.GetAllAsync(persistedGrant.SubjectId).Result.ToList(); Assert.NotNull(foundPersistedGrants); Assert.NotEmpty(foundPersistedGrants); Assert.Equal(1, foundPersistedGrants.Count); Assert.Equal(persistedGrant.SubjectId, foundPersistedGrants[0].SubjectId); }
public async Task GetAllAsync_WithSubAndTypeAndPersistedGrantExists_ExpectPersistedGrantReturned() { var persistedGrant = CreateTestObject(); await _context.PersistedGrants.Document(persistedGrant.Key).SetAsync(persistedGrant.ToEntity()); IList <PersistedGrant> foundPersistedGrants; var store = new PersistedGrantStore(_context, FakeLogger <PersistedGrantStore> .Create()); foundPersistedGrants = (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = persistedGrant.SubjectId })).ToList(); Assert.NotNull(foundPersistedGrants); Assert.NotEmpty(foundPersistedGrants); }
public void GetAllAsync_ShouldReturnSavedGrants() { int count = 10; string subject = Guid.NewGuid().ToString(); GenFu.GenFu.Configure <PersistedGrant>().Fill(x => x.SubjectId, subject); var persistedGrants = GenFu.GenFu.ListOf <PersistedGrant>(count); using (var session = martenFixture.Store.LightweightSession()) { session.StoreObjects(persistedGrants); session.SaveChanges(); } using (var session = martenFixture.Store.LightweightSession()) { var _store = new PersistedGrantStore(session); var foundGrants = _store.GetAllAsync(subject).Result; Assert.True(foundGrants.Count() == count); } }
public async Task GetAsync_WithSubAndTypeAndPersistedGrantExists_ExpectPersistedGrantReturned(ISessionFactory sessionFactory) { var persistedGrant = CreateTestObject(); using (var provider = new OperationalSessionProvider(sessionFactory.OpenSession)) { await provider.Session.SaveAsync(_mapper.Map <Entities.PersistedGrant>(persistedGrant)); } IEnumerable <PersistedGrant> foundPersistedGrants; using (var provider = new OperationalSessionProvider(sessionFactory.OpenSession)) { var store = new PersistedGrantStore(provider); foundPersistedGrants = await store.GetAllAsync(persistedGrant.SubjectId); } Assert.NotNull(foundPersistedGrants); Assert.NotEmpty(foundPersistedGrants); }
public async Task GetAllAsync_WithSubAndTypeAndPersistedGrantExists_ExpectPersistedGrantReturned() { var persistedGrant = CreateTestObject(); var repo = g.operationalDb.GetRepository <Storage.Entities.PersistedGrant>(); var entity = persistedGrant.ToEntity(); repo.Insert(entity); IList <PersistedGrant> foundPersistedGrants; var store = new PersistedGrantStore(g.operationalDb, FakeLogger <PersistedGrantStore> .Create()); foundPersistedGrants = (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = persistedGrant.SubjectId })).ToList(); Assert.NotNull(foundPersistedGrants); Assert.NotEmpty(foundPersistedGrants); }
public async Task GetAsync_WithSubAndTypeAndPersistedGrantExists_ExpectPersistedGrantReturned(DbContextOptions <PersistedGrantDbContext> options) { var persistedGrant = CreateTestObject(); using (var context = new PersistedGrantDbContext(options, StoreOptions)) { context.PersistedGrants.Add(persistedGrant.ToEntity()); await context.SaveChangesAsync(); } IEnumerable <PersistedGrant> foundPersistedGrants; using (var context = new PersistedGrantDbContext(options, StoreOptions)) { var store = new PersistedGrantStore(context, FakeLogger <PersistedGrantStore> .Create()); foundPersistedGrants = await store.GetAllAsync(persistedGrant.SubjectId); } Assert.NotNull(foundPersistedGrants); Assert.NotEmpty(foundPersistedGrants); }
public async Task Can_call_PersistedGrantStore_GetAllAsync() => await ExecuteWithStrategyInTransactionAsync( async context => { await SaveGrants(context); }, async context => { var store = new PersistedGrantStore(context, new FakeLogger <PersistedGrantStore>()); var results = (await store.GetAllAsync( new PersistedGrantFilter { Type = "T1", SessionId = "Se1", SubjectId = "Su1" })).ToList(); Assert.Equal(2, results.Count); } );
public async Task GetAllAsync_WithSubAndTypeAndPersistedGrantExists_ExpectPersistedGrantReturned(DbContextOptions <PersistedGrantDbContext> options) { var persistedGrant = CreateTestObject(); using (var context = new PersistedGrantDbContext(options)) { context.PersistedGrants.Add(persistedGrant.ToEntity()); context.SaveChanges(); } IList <PersistedGrant> foundPersistedGrants; using (var context = new PersistedGrantDbContext(options)) { var store = new PersistedGrantStore(context, FakeLogger <PersistedGrantStore> .Create(), new NoneCancellationTokenProvider()); foundPersistedGrants = (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = persistedGrant.SubjectId })).ToList(); } Assert.NotNull(foundPersistedGrants); Assert.NotEmpty(foundPersistedGrants); }
public async Task Should_Retrieve_Grant_By_SubjectId(TestDatabase testDb) { var testGrant = CreateTestGrant(); var loggerMock = new Mock <ILogger <PersistedGrantStore> >(); using (var session = testDb.OpenSession()) { await session.SaveAsync(testGrant.ToEntity()); await session.FlushAsync(); } IList <PersistedGrant> foundGrants; using (var session = testDb.OpenSession()) { var store = new PersistedGrantStore(session, loggerMock.Object); foundGrants = (await store.GetAllAsync(testGrant.SubjectId)).ToList(); } foundGrants.Should().NotBeEmpty(); await CleanupTestDataAsync(testDb); }
public async Task GetAllAsync_Should_Filter() { var repo = g.operationalDb.GetRepository <Storage.Entities.PersistedGrant>(); //clean last test data repo.Where(a => a.SubjectId == "sub1").ToDelete().ExecuteAffrows(); repo.Insert(CreateTestObject(sub: "sub1", clientId: "c1", sid: "s1", type: "t1").ToEntity()); repo.Insert(CreateTestObject(sub: "sub1", clientId: "c1", sid: "s1", type: "t2").ToEntity()); repo.Insert(CreateTestObject(sub: "sub1", clientId: "c1", sid: "s2", type: "t1").ToEntity()); repo.Insert(CreateTestObject(sub: "sub1", clientId: "c1", sid: "s2", type: "t2").ToEntity()); repo.Insert(CreateTestObject(sub: "sub1", clientId: "c2", sid: "s1", type: "t1").ToEntity()); repo.Insert(CreateTestObject(sub: "sub1", clientId: "c2", sid: "s1", type: "t2").ToEntity()); repo.Insert(CreateTestObject(sub: "sub1", clientId: "c2", sid: "s2", type: "t1").ToEntity()); repo.Insert(CreateTestObject(sub: "sub1", clientId: "c2", sid: "s2", type: "t2").ToEntity()); repo.Insert(CreateTestObject(sub: "sub1", clientId: "c3", sid: "s3", type: "t3").ToEntity()); repo.Insert(CreateTestObject().ToEntity()); var store = new PersistedGrantStore(g.operationalDb, FakeLogger <PersistedGrantStore> .Create()); (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = "sub1" })).ToList().Count.Should().Be(9); (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = "sub10" })).ToList().Count.Should().Be(0); (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = "sub1", ClientId = "c1" })).ToList().Count.Should().Be(4); (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = "sub1", ClientId = "c2" })).ToList().Count.Should().Be(4); (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = "sub1", ClientId = "c3" })).ToList().Count.Should().Be(1); (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = "sub1", ClientId = "c4" })).ToList().Count.Should().Be(0); (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = "sub1", ClientId = "c1", SessionId = "s1" })).ToList().Count.Should().Be(2); (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = "sub1", ClientId = "c3", SessionId = "s1" })).ToList().Count.Should().Be(0); (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = "sub1", ClientId = "c1", SessionId = "s1", Type = "t1" })).ToList().Count.Should().Be(1); (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = "sub1", ClientId = "c1", SessionId = "s1", Type = "t3" })).ToList().Count.Should().Be(0); }
public async Task GetAllAsync_Should_Filter(DbContextOptions <PersistedGrantDbContext> options) { using (var context = new PersistedGrantDbContext(options, StoreOptions)) { context.PersistedGrants.Add(CreateTestObject(sub: "sub1", clientId: "c1", sid: "s1", type: "t1").ToEntity()); context.PersistedGrants.Add(CreateTestObject(sub: "sub1", clientId: "c1", sid: "s1", type: "t2").ToEntity()); context.PersistedGrants.Add(CreateTestObject(sub: "sub1", clientId: "c1", sid: "s2", type: "t1").ToEntity()); context.PersistedGrants.Add(CreateTestObject(sub: "sub1", clientId: "c1", sid: "s2", type: "t2").ToEntity()); context.PersistedGrants.Add(CreateTestObject(sub: "sub1", clientId: "c2", sid: "s1", type: "t1").ToEntity()); context.PersistedGrants.Add(CreateTestObject(sub: "sub1", clientId: "c2", sid: "s1", type: "t2").ToEntity()); context.PersistedGrants.Add(CreateTestObject(sub: "sub1", clientId: "c2", sid: "s2", type: "t1").ToEntity()); context.PersistedGrants.Add(CreateTestObject(sub: "sub1", clientId: "c2", sid: "s2", type: "t2").ToEntity()); context.PersistedGrants.Add(CreateTestObject(sub: "sub1", clientId: "c3", sid: "s3", type: "t3").ToEntity()); context.PersistedGrants.Add(CreateTestObject().ToEntity()); context.SaveChanges(); } using (var context = new PersistedGrantDbContext(options, StoreOptions)) { var store = new PersistedGrantStore(context, FakeLogger <PersistedGrantStore> .Create()); (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = "sub1" })).ToList().Count.Should().Be(9); (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = "sub2" })).ToList().Count.Should().Be(0); (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = "sub1", ClientId = "c1" })).ToList().Count.Should().Be(4); (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = "sub1", ClientId = "c2" })).ToList().Count.Should().Be(4); (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = "sub1", ClientId = "c3" })).ToList().Count.Should().Be(1); (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = "sub1", ClientId = "c4" })).ToList().Count.Should().Be(0); (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = "sub1", ClientId = "c1", SessionId = "s1" })).ToList().Count.Should().Be(2); (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = "sub1", ClientId = "c3", SessionId = "s1" })).ToList().Count.Should().Be(0); (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = "sub1", ClientId = "c1", SessionId = "s1", Type = "t1" })).ToList().Count.Should().Be(1); (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = "sub1", ClientId = "c1", SessionId = "s1", Type = "t3" })).ToList().Count.Should().Be(0); } }
public async Task GetAllAsync_Should_Filter() { var snapshots = await _context.PersistedGrants.GetSnapshotAsync(); foreach (var doc in snapshots) { await doc.Reference.DeleteAsync(); } var model = CreateTestObject(sub: "sub1", clientId: "c1", sid: "s1", type: "t1"); await _context.PersistedGrants.Document(model.Key).SetAsync(model.ToEntity()); model = CreateTestObject(sub: "sub1", clientId: "c1", sid: "s1", type: "t2"); await _context.PersistedGrants.Document(model.Key).SetAsync(model.ToEntity()); model = CreateTestObject(sub: "sub1", clientId: "c1", sid: "s2", type: "t1"); await _context.PersistedGrants.Document(model.Key).SetAsync(model.ToEntity()); model = CreateTestObject(sub: "sub1", clientId: "c1", sid: "s2", type: "t2"); await _context.PersistedGrants.Document(model.Key).SetAsync(model.ToEntity()); model = CreateTestObject(sub: "sub1", clientId: "c2", sid: "s1", type: "t1"); await _context.PersistedGrants.Document(model.Key).SetAsync(model.ToEntity()); model = CreateTestObject(sub: "sub1", clientId: "c2", sid: "s1", type: "t2"); await _context.PersistedGrants.Document(model.Key).SetAsync(model.ToEntity()); model = CreateTestObject(sub: "sub1", clientId: "c2", sid: "s2", type: "t1"); await _context.PersistedGrants.Document(model.Key).SetAsync(model.ToEntity()); model = CreateTestObject(sub: "sub1", clientId: "c2", sid: "s2", type: "t2"); await _context.PersistedGrants.Document(model.Key).SetAsync(model.ToEntity()); model = CreateTestObject(sub: "sub1", clientId: "c3", sid: "s3", type: "t3"); await _context.PersistedGrants.Document(model.Key).SetAsync(model.ToEntity()); model = CreateTestObject(); await _context.PersistedGrants.Document(model.Key).SetAsync(model.ToEntity()); var store = new PersistedGrantStore(_context, FakeLogger <PersistedGrantStore> .Create()); (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = "sub1" })).ToList().Count.Should().Be(9); (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = "sub2" })).ToList().Count.Should().Be(0); (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = "sub1", ClientId = "c1" })).ToList().Count.Should().Be(4); (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = "sub1", ClientId = "c2" })).ToList().Count.Should().Be(4); (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = "sub1", ClientId = "c3" })).ToList().Count.Should().Be(1); (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = "sub1", ClientId = "c4" })).ToList().Count.Should().Be(0); (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = "sub1", ClientId = "c1", SessionId = "s1" })).ToList().Count.Should().Be(2); (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = "sub1", ClientId = "c3", SessionId = "s1" })).ToList().Count.Should().Be(0); (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = "sub1", ClientId = "c1", SessionId = "s1", Type = "t1" })).ToList().Count.Should().Be(1); (await store.GetAllAsync(new PersistedGrantFilter { SubjectId = "sub1", ClientId = "c1", SessionId = "s1", Type = "t3" })).ToList().Count.Should().Be(0); }