Пример #1
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};"));
        }
Пример #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;"));
        }
Пример #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");
        }