public async Task CountAsync() { Assert.Equal(0, await _identityRepository.CountAsync()); var identity = IdentityGenerator.Default; var result = await _identityRepository.AddAsync(identity, o => o.ImmediateConsistency()); Assert.Equal(identity, result); Assert.Equal(1, await _identityRepository.CountAsync()); }
public async Task Count() { Assert.Equal(0, await _identityRepository.CountAsync()); var identity = IdentityGenerator.Default; var result = await _identityRepository.AddAsync(identity); Assert.Equal(identity, result); await _client.RefreshAsync(); Assert.Equal(1, await _identityRepository.CountAsync()); }
public async Task AddDuplicateAsync() { var identity1 = await _identityRepository.AddAsync(IdentityGenerator.Default, o => o.ImmediateConsistency()); Assert.NotNull(identity1?.Id); await Assert.ThrowsAsync <DuplicateDocumentException>(async() => await _identityRepository.AddAsync(IdentityGenerator.Default, o => o.ImmediateConsistency())); Assert.Equal(1, await _identityRepository.CountAsync()); }
public async Task CountByQueryAsync() { Assert.Equal(0, await _identityRepository.CountAsync()); var identity = IdentityGenerator.Default; var result = await _identityRepository.AddAsync(identity, o => o.ImmediateConsistency()); Assert.Equal(identity, result); Assert.Equal(0, await _identityRepository.CountBySearchAsync(null, "id:test")); Assert.Equal(1, await _identityRepository.CountBySearchAsync(null, $"id:{identity.Id}")); }
public async Task CountByQuery() { Assert.Equal(0, await _identityRepository.CountAsync()); var identity = IdentityGenerator.Default; var result = await _identityRepository.AddAsync(identity); Assert.Equal(identity, result); await _client.RefreshAsync(); Assert.Equal(0, await _identityRepository.CountBySearchAsync(null, "id:test")); Assert.Equal(1, await _identityRepository.CountBySearchAsync(null, $"id:{identity.Id}")); }
public async Task AddDuplicate() { var identity1 = await _identityRepository.AddAsync(IdentityGenerator.Default); Assert.NotNull(identity1?.Id); var identity2 = await _identityRepository.AddAsync(IdentityGenerator.Default); Assert.NotNull(identity2?.Id); Assert.Equal(identity1, identity2); await _client.RefreshAsync(); Assert.Equal(1, await _identityRepository.CountAsync()); }
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(); } }
public async Task RemoveAllWithDeleteByQuery() { const int COUNT = 10000; Log.SetLogLevel <IdentityWithNoCachingRepository>(LogLevel.Information); await _identityRepositoryWithNoCaching.AddAsync(IdentityGenerator.GenerateIdentities(COUNT)); await _client.RefreshAsync(); Log.SetLogLevel <IdentityWithNoCachingRepository>(LogLevel.Trace); var sw = Stopwatch.StartNew(); Assert.Equal(COUNT, await _identityRepositoryWithNoCaching.RemoveAllAsync()); sw.Stop(); _logger.Info($"Deleted {COUNT} documents in {sw.ElapsedMilliseconds}ms"); await _client.RefreshAsync(); Assert.Equal(0, await _identityRepositoryWithNoCaching.CountAsync()); // TODO: Ensure only one removed notification is sent out. }