示例#1
0
        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");
        }
示例#2
0
        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);
        }
示例#3
0
        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");
        }