public void SpecificationWithPaging_AddsPaging() { var spec = new TestSpecification(); var baseQuery = $@"SELECT * FROM Table;"; spec.AddPaging(10, 3); var(query, _) = spec.Apply(baseQuery); Assert.Equal( Normalize(query), Normalize($"SELECT * FROM Table LIMIT 10 OFFSET 3;")); }
public void SpecificationWithOrderBy_DoesNothingOnEmptyColumnList(string mode) { var spec = new TestSpecification(); var baseQuery = $@"SELECT * FROM Table;"; spec.AddOrderBy(new[] { new OrderByColumn("gibberish1", mode), new OrderByColumn("gibberish2", mode) }); var(query, _) = spec.Apply(baseQuery); Assert.Equal( Normalize(query), Normalize($"SELECT * FROM Table;")); }
public void SpecificationWithOrderBy_RejectsNotSortableColumns(string mode) { var spec = new TestSpecification(); var baseQuery = $@"SELECT * FROM Table;"; spec.AddOrderBy(new[] { new OrderByColumn("Foo", mode), new OrderByColumn("Baz", mode) }); var(query, _) = spec.Apply(baseQuery); Assert.Equal( Normalize(query), Normalize($"SELECT * FROM Table ORDER BY Baz {mode};")); }
public void SpecificationWithCriteria_IncludesSearchableColumns() { var spec = new TestSpecification(); var baseQuery = $@"SELECT * FROM Table;"; spec.AddCriteria(new[] { new Criteria("Foo", "Table", "a"), new Criteria("Baz", "Table", "b") }); (var query, dynamic preparedStatementObject) = spec.Apply(baseQuery); Assert.Equal( Normalize(query), Normalize("SELECT * FROM Table WHERE Table.foo = @val0 AND Table.Baz = @val1;")); Assert.True(preparedStatementObject.val0 == "a"); Assert.True(preparedStatementObject.val1 == "b"); }
public void SpecificationWithCriteria_RejectsNotSearchableColumns() { var spec = new TestSpecification(); var baseQuery = $@"SELECT * FROM Table;"; spec.AddCriteria(new[] { new Criteria("Foo", "Table", "a"), new Criteria("Bar", "Table", "b") }); (var query, dynamic preparedStatementObject) = spec.Apply(baseQuery); Assert.Equal( Normalize(query), Normalize("SELECT * FROM Table WHERE Table.foo = @val0;")); Assert.True(preparedStatementObject.val0 == "a"); // Bar property should not exist Assert.ThrowsAny <Exception>(() => preparedStatementObject.val1); }
public void SpecificationWithAllFeatures_WorksCorrectly(string mode) { var spec = new TestSpecification(); var baseQuery = $@"SELECT * FROM Table;"; spec.AddCriteria(new[] { new Criteria("Foo", "Table", "a"), new Criteria("Baz", "Table", "b") }); spec.AddOrderBy(new[] { new OrderByColumn("Bar", mode), new OrderByColumn("Baz", mode) }); spec.AddPaging(10, 3); (var query, dynamic preparedStatementObject) = spec.Apply(baseQuery); Assert.Equal( Normalize(query), Normalize($@"SELECT * FROM Table WHERE Table.foo = @val0 AND Table.Baz = @val1 ORDER BY Bar {mode}, Baz {mode} LIMIT 10 OFFSET 3;")); Assert.True(preparedStatementObject.val0 == "a"); Assert.True(preparedStatementObject.val1 == "b"); }