public void GetPagedLogEntriesSql_returns_correct_sql_for_events_before_specified_timestamp_with_specified_filter() { // Arrange var timestamp = new DateTime(2017, 8, 3, 14, 56, 33, 876); var levelFilter = "info"; var provider = new SejilSqlProvider(Mock.Of <ISejilSettings>()); // Act var sql = provider.GetPagedLogEntriesSql(2, 100, timestamp, new LogQueryFilter { LevelFilter = levelFilter }); // Assert Assert.Equal( @"SELECT l.*, p.* from ( SELECT * FROM log WHERE (timestamp <= '2017-08-03 14:56:33.876') AND (level = 'info') ORDER BY timestamp DESC LIMIT 100 OFFSET 100 ) l LEFT JOIN log_property p ON l.id = p.logId ORDER BY l.timestamp DESC, p.name", sql); }
public void GetPagedLogEntriesSql_returns_correct_sql_for_events_with_specified_query_with_specified_filter() { // Arrange var query = "p=v"; var levelFilter = "info"; var provider = new SejilSqlProvider(Mock.Of <ISejilSettings>()); // Act var sql = provider.GetPagedLogEntriesSql(2, 100, null, new LogQueryFilter { QueryText = query, LevelFilter = levelFilter }); // Assert Assert.Equal( @"SELECT l.*, p.* from ( SELECT * FROM log WHERE (id IN (SELECT logId FROM log_property WHERE name = 'p' AND value = 'v')) AND (level = 'info') ORDER BY timestamp DESC LIMIT 100 OFFSET 100 ) l LEFT JOIN log_property p ON l.id = p.logId ORDER BY l.timestamp DESC, p.name", sql); }
public void GetPagedLogEntriesSql_returns_correct_sql_for_events_before_specified_timestamp_with_specified_query() { // Arrange var timestamp = new DateTime(2017, 8, 3, 14, 56, 33, 876); var query = "p='v'"; var provider = new SejilSqlProvider(Mock.Of <ISejilSettings>()); // Act var sql = provider.GetPagedLogEntriesSql(2, 100, timestamp, new LogQueryFilter { QueryText = query }); // Assert Assert.Equal( @"SELECT l.*, p.* from ( SELECT * FROM log WHERE (timestamp <= '2017-08-03 14:56:33.876') AND (id IN (SELECT logId FROM log_property GROUP BY logId HAVING SUM(name = 'p' AND value = 'v') > 0)) ORDER BY timestamp DESC LIMIT 100 OFFSET 100 ) l LEFT JOIN log_property p ON l.id = p.logId ORDER BY l.timestamp DESC, p.name", sql); }
public void GetPagedLogEntriesSql_throws_when_pageSize_arg_is_less_than_zero() { // Arrange var provider = new SejilSqlProvider(Mock.Of <ISejilSettings>()); // Act & assert var ex = Assert.Throws <ArgumentOutOfRangeException>("pageSize", () => provider.GetPagedLogEntriesSql(1, -1, null, null)); Assert.Equal($"Argument must be greater than zero. (Parameter 'pageSize')", ex.Message); }
public void GetPagedLogEntriesSql_throws_when_page_arg_is_zero() { // Arrange var provider = new SejilSqlProvider(Mock.Of <ISejilSettings>()); // Act & assert var ex = Assert.Throws <ArgumentOutOfRangeException>("page", () => provider.GetPagedLogEntriesSql(0, 1, null, null)); Assert.Equal($"Argument must be greater than zero.{Environment.NewLine}Parameter name: page", ex.Message); }
public void GetPagedLogEntriesSql_returns_correct_sql_for_events_with_specified_filter(string levelFilter, bool exceptionsOnly, string expectedSql) { // Arrange var settingsMoq = new Mock <ISejilSettings>(); var provider = new SejilSqlProvider(settingsMoq.Object); // Act var sql = provider.GetPagedLogEntriesSql(2, 100, null, new LogQueryFilter { LevelFilter = levelFilter, ExceptionsOnly = exceptionsOnly }); // Assert Assert.Equal(expectedSql, GetInnerPredicate(sql)); }
public void GetPagedLogEntriesSql_returns_correct_sql_for_events_with_specified_dateFilter(string dateFilter, string expectedSql) { // Arrange var settingsMoq = new Mock <ISejilSettings>(); var provider = new SejilSqlProvider(settingsMoq.Object); // Act var sql = provider.GetPagedLogEntriesSql(2, 100, null, new LogQueryFilter { DateFilter = dateFilter }); // Assert Assert.Equal(expectedSql, GetInnerPredicate_ts(sql)); }
public void GetPagedLogEntriesSql_returns_correct_sql_for_events_with_specified_query(string query, string expectedSql, params string[] nonPropertyColumns) { // Arrange var settingsMoq = new Mock <ISejilSettings>(); settingsMoq.SetupGet(p => p.NonPropertyColumns).Returns(nonPropertyColumns); var provider = new SejilSqlProvider(settingsMoq.Object); // Act var sql = provider.GetPagedLogEntriesSql(2, 100, null, new LogQueryFilter { QueryText = query }); // Assert Assert.Equal(expectedSql, GetInnerPredicate(sql)); }
public void GetPagedLogEntriesSql_returns_correct_sql_for_events_with_specified_dateRangeFilter() { // Arrange var d1 = new DateTime(2017, 8, 1); var d2 = new DateTime(2017, 8, 10); var settingsMoq = new Mock <ISejilSettings>(); var provider = new SejilSqlProvider(settingsMoq.Object); // Act var sql = provider.GetPagedLogEntriesSql(2, 100, null, new LogQueryFilter { DateRangeFilter = new List <DateTime> { d1, d2 } }); // Assert Assert.Equal("timestamp >= '2017-08-01' and timestamp < '2017-08-10'", GetInnerPredicate_ts(sql)); }
public void GetPagedLogEntriesSql_ignores_timestamp_arg_when_null() { // Arrange DateTime?timestamp = null; var provider = new SejilSqlProvider(Mock.Of <ISejilSettings>()); // Act var sql = provider.GetPagedLogEntriesSql(2, 100, timestamp, null); // Assert Assert.Equal( @"SELECT l.*, p.* from ( SELECT * FROM log ORDER BY timestamp DESC LIMIT 100 OFFSET 100 ) l LEFT JOIN log_property p ON l.id = p.logId ORDER BY l.timestamp DESC, p.name", sql); }
public void GetPagedLogEntriesSql_returns_correct_sql_for_events_before_specified_timestamp() { // Arrange var timestamp = new DateTime(2017, 8, 3, 14, 56, 33, 876); var provider = new SejilSqlProvider(Mock.Of <ISejilSettings>()); // Act var sql = provider.GetPagedLogEntriesSql(2, 100, timestamp, null); // Assert Assert.Equal( @"SELECT l.*, p.* from ( SELECT * FROM log WHERE (timestamp < '2017-08-03 18:56:33.876') ORDER BY timestamp DESC LIMIT 100 ) l LEFT JOIN log_property p ON l.timestamp = p.timestamp AND l.id = p.logId ORDER BY l.timestamp DESC, p.name", sql); }
public void GetPagedLogEntriesSql_returns_correct_sql_for_page() { // Arrange var page = 2; var pageSize = 100; var provider = new SejilSqlProvider(Mock.Of <ISejilSettings>()); // Act var sql = provider.GetPagedLogEntriesSql(page, pageSize, null, null); // Assert Assert.Equal( $@"SELECT l.*, p.* from ( SELECT * FROM log ORDER BY timestamp DESC LIMIT {pageSize} OFFSET {(page - 1) * pageSize} ) l LEFT JOIN log_property p ON l.id = p.logId ORDER BY l.timestamp DESC, p.name", sql); }