Exemplo n.º 1
0
        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;"));
        }
Exemplo n.º 2
0
        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;"));
        }
Exemplo n.º 3
0
        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};"));
        }
Exemplo n.º 4
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");
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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");
        }