Exemplo n.º 1
0
        public void BuildSortConditionsNoParameterTest()
        {
            // Act
            var result = _classUnderTest.BuildSortConditions <Alpha>(null);

            // Assert
            result.Should().HaveCount(0);
        }
Exemplo n.º 2
0
        public void AddSortConditionsToQueryInnerOrderByTest()
        {
            // Arrange
            var query         = "SELECT * FROM Alpha a JOIN (SELECT * FROM Omega ORDER BY Psi) o ON o.Psi = a.Gamma";
            var sortingEngine = new SortingQueryEngine();
            var mappings      = new Dictionary <string, List <Expression <Func <Alpha, object> > > >
            {
                { nameof(Omega.Psi), new List <Expression <Func <Alpha, object> > > {
                      a => a.Omega.Psi
                  } }
            };

            var queryParameters = new QueryParameters
            {
                SortingQueryProperties = new List <SortingQueryProperty>
                {
                    new SortingQueryProperty
                    {
                        PropertyName = nameof(Alpha.Beta),
                        SortOrder    = SortOrder.Descending
                    },
                    new SortingQueryProperty
                    {
                        PropertyName = nameof(Omega.Psi),
                        SortOrder    = SortOrder.Ascending
                    }
                }
            };

            var data = new WhereQuerySettings
            {
                PropertyMappings = new Dictionary <string, string>
                {
                    { ".", "a" },
                    { ".Omega.Psi", "o.Psi" }
                }
            };

            var orderByConditions = sortingEngine.BuildSortConditions(queryParameters, mappings);

            // Act
            var result = orderByConditions.Data.AddSortConditionsToQuery(query, data);

            // Assert
            result.Should().Be($"{query}{Environment.NewLine}ORDER BY{Environment.NewLine}a.Beta DESC, o.Psi ASC");
        }
Exemplo n.º 3
0
        public void CalculateSortConditionsTest()
        {
            // Arrange
            var sortingEngine = new SortingQueryEngine();
            var mappings      = new Dictionary <string, List <Expression <Func <Alpha, object> > > >
            {
                { nameof(Omega.Psi), new List <Expression <Func <Alpha, object> > > {
                      a => a.Omega.Psi
                  } }
            };

            var queryParameters = new QueryParameters
            {
                SortingQueryProperties = new List <SortingQueryProperty>
                {
                    new SortingQueryProperty
                    {
                        PropertyName = nameof(Alpha.Beta),
                        SortOrder    = SortOrder.Descending
                    },
                    new SortingQueryProperty
                    {
                        PropertyName = nameof(Omega.Psi),
                        SortOrder    = SortOrder.Ascending
                    }
                }
            };

            var data = new WhereQuerySettings
            {
                PropertyMappings = new Dictionary <string, string>
                {
                    { ".", "a" },
                    { ".Omega.Psi", "o.Psi" }
                }
            };

            var orderByConditions = sortingEngine.BuildSortConditions(queryParameters, mappings);

            // Act
            var result = orderByConditions.Data.CalculateSortConditions(data);

            // Assert
            result.Should().Be("a.Beta DESC, o.Psi ASC");
        }
Exemplo n.º 4
0
        public void AddSortConditionsToQueryNoConditionsTest()
        {
            // Arrange
            var query         = "SELECT * FROM Alpha a ORDER BY a.Gamma ASC";
            var sortingEngine = new SortingQueryEngine();

            var queryParameters = new QueryParameters
            {
                SortingQueryProperties = new List <SortingQueryProperty>()
            };

            var data = new WhereQuerySettings();

            var orderByConditions = sortingEngine.BuildSortConditions <Alpha>(queryParameters);

            // Act
            var result = orderByConditions.Data.AddSortConditionsToQuery(query, data);

            // Assert
            result.Should().Be(query);
        }