public async Task GetAllAsync()
        {
            var identities = IdentityGenerator.GenerateIdentities(25);
            await _identityRepository.AddAsync(identities, o => o.ImmediateConsistency());

            var results = await _identityRepository.GetAllAsync(o => o.PageLimit(100));

            Assert.NotNull(results);
            Assert.Equal(25, results.Total);
            Assert.Equal(25, results.Documents.Count);
            Assert.Equal(identities.OrderBy(i => i.Id), results.Documents.OrderBy(i => i.Id));

            results = await _identityRepository.GetAllAsync();

            Assert.NotNull(results);
            Assert.Equal(25, results.Total);
            Assert.Equal(10, results.Documents.Count);

            Assert.True(await results.NextPageAsync());
            Assert.Equal(10, results.Documents.Count);
            Assert.Equal(2, results.Page);
            Assert.Equal(25, results.Total);
            Assert.True(results.HasMore);

            Assert.True(await results.NextPageAsync());
            Assert.Equal(5, results.Documents.Count);
            Assert.Equal(3, results.Page);
            Assert.Equal(25, results.Total);
            Assert.False(results.HasMore);
        }
        public async Task GetAll()
        {
            var identities = IdentityGenerator.GenerateIdentities(25);
            await _identityRepository.AddAsync(identities);

            await _client.RefreshAsync();

            var results = await _identityRepository.GetAllAsync(paging : 100);

            Assert.NotNull(results);
            Assert.Equal(25, results.Total);
            Assert.Equal(25, results.Documents.Count);
            Assert.Equal(identities.OrderBy(i => i.Id), results.Documents.OrderBy(i => i.Id));
        }
        public async Task RemoveAllWithDeleteByQueryAsync()
        {
            const int COUNT = 10000;

            Log.SetLogLevel <IdentityWithNoCachingRepository>(LogLevel.Information);
            await _identityRepositoryWithNoCaching.AddAsync(IdentityGenerator.GenerateIdentities(COUNT), o => o.ImmediateConsistency());

            Log.SetLogLevel <IdentityWithNoCachingRepository>(LogLevel.Trace);

            var disposables    = new List <IDisposable>(2);
            var countdownEvent = new AsyncCountdownEvent(1);

            try {
                disposables.Add(_identityRepositoryWithNoCaching.DocumentsRemoving.AddSyncHandler((o, args) => {
                    countdownEvent.Signal();
                }));
                disposables.Add(_identityRepositoryWithNoCaching.DocumentsRemoved.AddSyncHandler((o, args) => {
                    countdownEvent.Signal();
                }));

                var sw = Stopwatch.StartNew();
                Assert.Equal(COUNT, await _identityRepositoryWithNoCaching.RemoveAllAsync(o => o.ImmediateConsistency(true)));
                sw.Stop();
                _logger.LogInformation($"Deleted {COUNT} documents in {sw.ElapsedMilliseconds}ms");

                await countdownEvent.WaitAsync(new CancellationTokenSource(TimeSpan.FromMilliseconds(250)).Token);

                Assert.Equal(0, countdownEvent.CurrentCount);

                Assert.Equal(0, await _identityRepositoryWithNoCaching.CountAsync());
            } finally {
                foreach (var disposable in disposables)
                {
                    disposable.Dispose();
                }

                disposables.Clear();
            }
        }
示例#4
0
        public async Task RemoveAllWithBatching()
        {
            const int COUNT = 10000;

            Log.SetLogLevel <IdentityRepository>(LogLevel.Information);
            await _identityRepository.AddAsync(IdentityGenerator.GenerateIdentities(COUNT));

            await _client.RefreshAsync();

            Log.SetLogLevel <IdentityRepository>(LogLevel.Trace);

            var sw = Stopwatch.StartNew();

            Assert.Equal(COUNT, await _identityRepository.RemoveAllAsync());
            sw.Stop();

            _logger.Info($"Deleted {COUNT} documents in {sw.ElapsedMilliseconds}ms");

            await _client.RefreshAsync();

            Assert.Equal(0, await _identityRepository.CountAsync());

            // TODO: Ensure only one removed notification is sent out.
        }