Пример #1
0
        public void TestWithExpressions()
        {
            // Setup
            var statementBuilder = new SqlDbStatementBuilder();
            var queryBuilder     = new QueryBuilder <TestWithExpressionsClass>();

            var where = QueryGroup.Parse(new
            {
                Field1 = "Test"
            });
            var orderBy = OrderField.Parse(new
            {
                Field1 = Order.Ascending
            });

            // Act
            var actual   = statementBuilder.CreateBatchQuery(queryBuilder, where, 0, 10, orderBy);
            var expected = $"" +
                           $"WITH CTE AS " +
                           $"( " +
                           $"SELECT ROW_NUMBER() OVER ( ORDER BY [Field1] ASC ) AS [RowNumber], [Field1], [Field2] " +
                           $"FROM [TestWithExpressionsClass] " +
                           $"WHERE ([Field1] = @Field1) " +
                           $") " +
                           $"SELECT [Field1], [Field2] " +
                           $"FROM CTE " +
                           $"WHERE ([RowNumber] BETWEEN 1 AND 10) " +
                           $"ORDER BY [Field1] ASC ;";

            // Assert
            Assert.AreEqual(expected, actual);
        }
Пример #2
0
        public void TestWithMultipleOrderedColumnsAndWithoutAttributes()
        {
            // Setup
            var statementBuilder = new SqlDbStatementBuilder();
            var queryBuilder     = new QueryBuilder <TestWithMultipleOrderedColumnsAndWithoutAttributesClass>();
            var orderBy          = OrderField.Parse(new
            {
                Field1 = Order.Descending,
                Field2 = Order.Ascending
            });

            // Act
            var actual   = statementBuilder.CreateBatchQuery(queryBuilder, null, 0, 10, orderBy);
            var expected = $"" +
                           $"WITH CTE AS " +
                           $"( " +
                           $"SELECT ROW_NUMBER() OVER ( ORDER BY [Field1] DESC, [Field2] ASC ) AS [RowNumber], [Field1], [Field2] " +
                           $"FROM [TestWithMultipleOrderedColumnsAndWithoutAttributesClass] " +
                           $") " +
                           $"SELECT [Field1], [Field2] " +
                           $"FROM CTE " +
                           $"WHERE ([RowNumber] BETWEEN 1 AND 10) " +
                           $"ORDER BY [Field1] DESC, [Field2] ASC ;";

            // Assert
            Assert.AreEqual(expected, actual);
        }
Пример #3
0
        public void TestWithFieldMappingsAndWithIgnoredBathQueryAndQueryCommand()
        {
            // Setup
            var statementBuilder = new SqlDbStatementBuilder();
            var queryBuilder     = new QueryBuilder <TestWithFieldMappingsAndWithIgnoredBathQueryAndQueryCommandClass>();
            var orderBy          = OrderField.Parse(new
            {
                Field1 = Order.Ascending
            });

            // Act
            var actual   = statementBuilder.CreateBatchQuery(queryBuilder, null, 0, 10, orderBy);
            var expected = $"" +
                           $"WITH CTE AS " +
                           $"( " +
                           $"SELECT ROW_NUMBER() OVER ( ORDER BY [Field1] ASC ) AS [RowNumber], [Field1], [Field3] " +
                           $"FROM [ClassName] " +
                           $") " +
                           $"SELECT [Field1], [Field3] " +
                           $"FROM CTE " +
                           $"WHERE ([RowNumber] BETWEEN 1 AND 10) " +
                           $"ORDER BY [Field1] ASC ;";

            // Assert
            Assert.AreEqual(expected, actual);
        }
Пример #4
0
        public void ThrowExceptionIfAllFieldsWereIgnored()
        {
            // Setup
            var statementBuilder = new SqlDbStatementBuilder();
            var queryBuilder     = new QueryBuilder <ThrowExceptionIfAllFieldsWereIgnoredClass>();
            var queryGroup       = (QueryGroup)null;

            // Act/Assert
            Assert.Throws <InvalidOperationException>(() => statementBuilder.CreateBatchQuery(queryBuilder, queryGroup, 0, 10, null));
        }
Пример #5
0
        public void ThrowExceptionIfThereAreNoQueryableFields()
        {
            // Setup
            var statementBuilder = new SqlDbStatementBuilder();
            var queryBuilder     = new QueryBuilder <ThrowExceptionIfThereAreNoQueryableFieldsClass>();
            var queryGroup       = (QueryGroup)null;

            // Act/Assert
            statementBuilder.CreateBatchQuery(queryBuilder, queryGroup, 0, 10, null);
        }