public virtual (string, IEnumerable <(string, object)> parameter) BuildQuery(Query query, IValidColumns validColumns, string tableName)
        {
            var queryData        = new QueryData(query, validColumns, new ClauseFactory(validColumns), tableName);
            var whereGenerator   = new WhereGenerator(queryData);
            var groupByGenerator = new GroupByGenerator(queryData);
            var orderByGenerator = new OrderByGenerator(queryData);
            var parameter        = whereGenerator.GetParameters();

            return(
                new SqlQueryGenerator(
                    new SelectGenerator(queryData),
                    whereGenerator,
                    groupByGenerator,
                    orderByGenerator
                    ).ToString()
                , parameter);
        }
Ejemplo n.º 2
0
        public void GenerateGroupByWithSingleColumn()
        {
            var validFields = new[]
            {
                "Distinct_Values_Column",
            };


            var queryData = Builder.BuildQueryData(fields: validFields, groupBy: validFields, distinct: true);

            var sut               = new GroupByGenerator(queryData);
            var response          = sut.ToString();
            var formattedResponse = SqlFormattingManager.DefaultFormat(response);

            var expectedResponse = SqlFormattingManager.DefaultFormat("GROUP BY [Distinct_Values_Column_Cleaned]");

            Assert.Equal(expectedResponse, formattedResponse);
        }
Ejemplo n.º 3
0
        public void GenerateGroupByWithManyColumnsRespectsColumnOrder()
        {
            var fields = new[]
            {
                "Distinct_Values_Column",
                "Another_Values_Column"
            };

            var groupBy = new[]
            {
                "Another_Values_Column",
                "Distinct_Values_Column"
            };

            var queryData = Builder.BuildQueryData(fields, groupBy: groupBy, distinct: true);

            var sut               = new GroupByGenerator(queryData);
            var response          = sut.ToString();
            var formattedResponse = SqlFormattingManager.DefaultFormat(response);

            var expectedResponse = SqlFormattingManager.DefaultFormat("GROUP BY [Another_Values_Column_Cleaned], [Distinct_Values_Column_Cleaned]");

            Assert.Equal(expectedResponse, formattedResponse);
        }