예제 #1
0
        public async Task SearchByQueryWithTimeSeriesAsync()
        {
            var utcNow       = SystemClock.UtcNow;
            var yesterdayLog = await _dailyRepository.AddAsync(LogEventGenerator.Generate(ObjectId.GenerateNewId(utcNow.AddDays(-1)).ToString(), createdUtc: utcNow.AddDays(-1), companyId: "1234567890"), o => o.ImmediateConsistency());

            Assert.NotNull(yesterdayLog?.Id);

            var nowLog = await _dailyRepository.AddAsync(LogEventGenerator.Default, o => o.ImmediateConsistency());

            Assert.NotNull(nowLog?.Id);

            var results = await _dailyRepository.GetByIdsAsync(new[] { yesterdayLog.Id, nowLog.Id });

            Assert.NotNull(results);
            Assert.Equal(2, results.Count);

            var searchResults = await _dailyRepository.SearchAsync(new RepositoryQuery().Company("test"));

            Assert.Equal(0, searchResults.Total);

            searchResults = await _dailyRepository.SearchAsync(new RepositoryQuery().Company(yesterdayLog.CompanyId));

            Assert.Equal(1, searchResults.Total);

            searchResults = await _dailyRepository.SearchAsync(new RepositoryQuery().Company(yesterdayLog.CompanyId).DateRange(utcNow.Subtract(TimeSpan.FromHours(1)), utcNow, "created"));

            Assert.Equal(0, searchResults.Total);

            searchResults = await _dailyRepository.SearchAsync(new RepositoryQuery().Id(yesterdayLog.Id));

            Assert.Equal(1, searchResults.Total);
        }