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.FindAsync(q => q.Company("test")); Assert.Equal(0, searchResults.Total); searchResults = await _dailyRepository.FindAsync(q => q.Company(yesterdayLog.CompanyId)); Assert.Equal(1, searchResults.Total); searchResults = await _dailyRepository.FindAsync(q => q.Company(yesterdayLog.CompanyId).DateRange(utcNow.Subtract(TimeSpan.FromHours(1)), utcNow, "created")); Assert.Equal(0, searchResults.Total); searchResults = await _dailyRepository.FindAsync(q => q.Company(yesterdayLog.CompanyId).DateRange(utcNow.Subtract(TimeSpan.FromHours(1)), DateTime.MaxValue, (LogEvent e) => e.CreatedUtc)); Assert.Equal(0, searchResults.Total); searchResults = await _dailyRepository.FindAsync(q => q.Id(yesterdayLog.Id)); Assert.Equal(1, searchResults.Total); }
public async Task GetByCompanyWithIncludedFields() { var log = await _dailyRepository.AddAsync(LogEventGenerator.Generate(companyId: "1234567890", message: "test"), o => o.ImmediateConsistency()); Assert.NotNull(log?.Id); var results = await _dailyRepository.FindAsync(q => q.Company(log.CompanyId)); Assert.Equal(1, results.Documents.Count); Assert.Equal(log, results.Documents.First()); results = await _dailyRepository.FindAsync(q => q.Company(log.CompanyId).Include(e => e.Id).Include(l => l.CreatedUtc)); Assert.Equal(1, results.Documents.Count); var companyLog = results.Documents.First(); Assert.Equal(log.Id, companyLog.Id); Assert.Equal(log.CreatedUtc, companyLog.CreatedUtc); Assert.Null(companyLog.Message); Assert.Null(companyLog.CompanyId); }