示例#1
0
        public async Task SearchByQuery()
        {
            var identity = IdentityGenerator.Default;
            var result   = await _identityRepository.AddAsync(identity);

            Assert.Equal(identity, result);

            await _client.RefreshAsync();

            var results = await _identityRepository.SearchAsync(null, "id:test");

            Assert.Equal(0, results.Documents.Count);

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

            try {
                var filter = $"id:{identity.Id}";
                disposables.Add(_identityRepository.BeforeQuery.AddSyncHandler((o, args) => {
                    Assert.Equal(filter, ((ElasticQuery)args.Query).Filter);
                    countdownEvent.Signal();
                }));

                results = await _identityRepository.SearchAsync(null, filter);

                Assert.Equal(1, results.Documents.Count);
                await countdownEvent.WaitAsync(new CancellationTokenSource(TimeSpan.FromMilliseconds(250)).Token);

                Assert.Equal(0, countdownEvent.CurrentCount);
            } finally {
                foreach (var disposable in disposables)
                {
                    disposable.Dispose();
                }

                disposables.Clear();
            }
        }