From b59bd3c7453217a5e5fe82455f2e1220c8238e9c Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Sat, 15 Jun 2024 16:59:34 +0200 Subject: [PATCH] remove ThenBy --- .../Config/NewtonsoftJsonParsingConfig.cs | 11 +- .../NewtonsoftJsonExtensions.cs | 134 +++++++++--------- .../Config/SystemTextJsonParsingConfig.cs | 8 +- .../SystemTextJsonExtensions.cs | 130 ++++++++--------- .../DynamicQueryableExtensions.cs | 20 +-- .../NewtonsoftJsonTests.cs | 34 +++-- .../SystemTextJsonTests.cs | 30 +++- 7 files changed, 207 insertions(+), 160 deletions(-) diff --git a/src/System.Linq.Dynamic.Core.NewtonsoftJson/Config/NewtonsoftJsonParsingConfig.cs b/src/System.Linq.Dynamic.Core.NewtonsoftJson/Config/NewtonsoftJsonParsingConfig.cs index 4b0156fd..fad7f9f1 100644 --- a/src/System.Linq.Dynamic.Core.NewtonsoftJson/Config/NewtonsoftJsonParsingConfig.cs +++ b/src/System.Linq.Dynamic.Core.NewtonsoftJson/Config/NewtonsoftJsonParsingConfig.cs @@ -2,9 +2,18 @@ namespace System.Linq.Dynamic.Core.NewtonsoftJson.Config; +/// +/// Configuration class for System.Linq.Dynamic.Core.NewtonsoftJson which implements the . +/// public class NewtonsoftJsonParsingConfig : ParsingConfig { - public static NewtonsoftJsonParsingConfig Default { get; } = new(); + /// + /// The default ParsingConfig for . + /// + public new static NewtonsoftJsonParsingConfig Default { get; } = new(); + /// + /// The default to use. + /// public DynamicJsonClassOptions? DynamicJsonClassOptions { get; set; } } \ No newline at end of file diff --git a/src/System.Linq.Dynamic.Core.NewtonsoftJson/NewtonsoftJsonExtensions.cs b/src/System.Linq.Dynamic.Core.NewtonsoftJson/NewtonsoftJsonExtensions.cs index 5b34c6c7..9ba04021 100644 --- a/src/System.Linq.Dynamic.Core.NewtonsoftJson/NewtonsoftJsonExtensions.cs +++ b/src/System.Linq.Dynamic.Core.NewtonsoftJson/NewtonsoftJsonExtensions.cs @@ -562,7 +562,7 @@ public static object Min(this JArray source, LambdaExpression lambda) /// A sequence of values to order. /// The . /// An expression string to indicate values to order by. - /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. + /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. /// A whose elements are sorted according to the specified . public static JArray OrderBy(this JArray source, NewtonsoftJsonParsingConfig config, string ordering, params object?[] args) { @@ -579,7 +579,7 @@ public static JArray OrderBy(this JArray source, NewtonsoftJsonParsingConfig con /// /// A sequence of values to order. /// An expression string to indicate values to order by. - /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. + /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. /// A whose elements are sorted according to the specified . public static JArray OrderBy(this JArray source, string ordering, params object?[] args) { @@ -593,7 +593,7 @@ public static JArray OrderBy(this JArray source, string ordering, params object? /// The . /// An expression string to indicate values to order by. /// The comparer to use. - /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. + /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. /// A whose elements are sorted according to the specified . public static JArray OrderBy(this JArray source, NewtonsoftJsonParsingConfig config, string ordering, IComparer comparer, params object?[] args) { @@ -607,7 +607,7 @@ public static JArray OrderBy(this JArray source, NewtonsoftJsonParsingConfig con /// A sequence of values to order. /// An expression string to indicate values to order by. /// The comparer to use. - /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. + /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. /// A whose elements are sorted according to the specified . public static JArray OrderBy(this JArray source, string ordering, IComparer comparer, params object?[] args) { @@ -654,7 +654,7 @@ public static PagedResult PageResult(this JArray source, int page, int pageSize, /// /// A sequence of values to project. /// A projection string expression to apply to each element. - /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. + /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. /// An whose elements are the result of invoking a projection string on each element of source. public static JArray Select(this JArray source, string selector, params object?[] args) { @@ -667,7 +667,7 @@ public static JArray Select(this JArray source, string selector, params object?[ /// A sequence of values to project. /// The . /// A projection string expression to apply to each element. - /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. + /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. /// An whose elements are the result of invoking a projection string on each element of source. public static JArray Select(this JArray source, NewtonsoftJsonParsingConfig config, string selector, params object?[] args) { @@ -874,67 +874,67 @@ public static JArray TakeWhile(this JArray source, string predicate, params obje } #endregion TakeWhile - #region ThenBy - /// - /// Performs a subsequent ordering of the elements in a sequence in ascending order according to a key. - /// - /// A sequence of values to order. - /// The . - /// An expression string to indicate values to order by. - /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. - /// A whose elements are sorted according to the specified . - public static JArray ThenBy(this JArray source, NewtonsoftJsonParsingConfig config, string ordering, params object?[] args) - { - Check.NotNull(source); - Check.NotNull(config); - - var queryable = ToQueryable(source, config).OrderBy("0"); // Workaround to get IOrderedQueryable - return ToJArray(() => queryable.ThenBy(ordering, args)); - } - - /// - /// Performs a subsequent ordering of the elements in a sequence in ascending order according to a key. - /// - /// A sequence of values to order. - /// The . - /// An expression string to indicate values to order by. - /// The comparer to use. - /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. - /// A whose elements are sorted according to the specified . - public static JArray ThenBy(this JArray source, NewtonsoftJsonParsingConfig config, string ordering, IComparer comparer, params object?[] args) - { - Check.NotNull(source); - Check.NotNull(config); - - var queryable = ToQueryable(source, config).OrderBy("0"); // Workaround to get IOrderedQueryable - return ToJArray(() => queryable.ThenBy(ordering, comparer, args)); - } - - /// - /// Performs a subsequent ordering of the elements in a sequence in ascending order according to a key. - /// - /// A sequence of values to order. - /// An expression string to indicate values to order by. - /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. - /// A whose elements are sorted according to the specified . - public static JArray ThenBy(this JArray source, string ordering, params object?[] args) - { - return ThenBy(source, NewtonsoftJsonParsingConfig.Default, ordering, args); - } - - /// - /// Performs a subsequent ordering of the elements in a sequence in ascending order according to a key. - /// - /// A sequence of values to order. - /// An expression string to indicate values to order by. - /// The comparer to use. - /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. - /// A whose elements are sorted according to the specified . - public static JArray ThenBy(this JArray source, string ordering, IComparer comparer, params object?[] args) - { - return ThenBy(source, NewtonsoftJsonParsingConfig.Default, ordering, comparer, args); - } - #endregion ThenBy + //#region ThenBy + ///// + ///// Performs a subsequent ordering of the elements in a sequence in ascending order according to a key. + ///// + ///// A sequence of values to order. + ///// The . + ///// An expression string to indicate values to order by. + ///// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. + ///// A whose elements are sorted according to the specified . + //public static JArray ThenBy(this JArray source, NewtonsoftJsonParsingConfig config, string ordering, params object?[] args) + //{ + // Check.NotNull(source); + // Check.NotNull(config); + + // var queryable = ToQueryable(source, config).OrderBy("0"); // Workaround to get IOrderedQueryable + // return ToJArray(() => queryable.ThenBy(ordering, args)); + //} + + ///// + ///// Performs a subsequent ordering of the elements in a sequence in ascending order according to a key. + ///// + ///// A sequence of values to order. + ///// The . + ///// An expression string to indicate values to order by. + ///// The comparer to use. + ///// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. + ///// A whose elements are sorted according to the specified . + //public static JArray ThenBy(this JArray source, NewtonsoftJsonParsingConfig config, string ordering, IComparer comparer, params object?[] args) + //{ + // Check.NotNull(source); + // Check.NotNull(config); + + // var queryable = ToQueryable(source, config).OrderBy("0"); // Workaround to get IOrderedQueryable + // return ToJArray(() => queryable.ThenBy(ordering, comparer, args)); + //} + + ///// + ///// Performs a subsequent ordering of the elements in a sequence in ascending order according to a key. + ///// + ///// A sequence of values to order. + ///// An expression string to indicate values to order by. + ///// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. + ///// A whose elements are sorted according to the specified . + //public static JArray ThenBy(this JArray source, string ordering, params object?[] args) + //{ + // return ThenBy(source, NewtonsoftJsonParsingConfig.Default, ordering, args); + //} + + ///// + ///// Performs a subsequent ordering of the elements in a sequence in ascending order according to a key. + ///// + ///// A sequence of values to order. + ///// An expression string to indicate values to order by. + ///// The comparer to use. + ///// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. + ///// A whose elements are sorted according to the specified . + //public static JArray ThenBy(this JArray source, string ordering, IComparer comparer, params object?[] args) + //{ + // return ThenBy(source, NewtonsoftJsonParsingConfig.Default, ordering, comparer, args); + //} + //#endregion ThenBy #region Where /// diff --git a/src/System.Linq.Dynamic.Core.SystemTextJson/Config/SystemTextJsonParsingConfig.cs b/src/System.Linq.Dynamic.Core.SystemTextJson/Config/SystemTextJsonParsingConfig.cs index d5ada435..eb42ff6d 100644 --- a/src/System.Linq.Dynamic.Core.SystemTextJson/Config/SystemTextJsonParsingConfig.cs +++ b/src/System.Linq.Dynamic.Core.SystemTextJson/Config/SystemTextJsonParsingConfig.cs @@ -1,6 +1,12 @@ namespace System.Linq.Dynamic.Core.SystemTextJson.Config; +/// +/// Configuration class for System.Linq.Dynamic.Core.SystemTextJson which implements the . +/// public class SystemTextJsonParsingConfig : ParsingConfig { - public static SystemTextJsonParsingConfig Default { get; } = new(); + /// + /// The default ParsingConfig for . + /// + public new static SystemTextJsonParsingConfig Default { get; } = new(); } \ No newline at end of file diff --git a/src/System.Linq.Dynamic.Core.SystemTextJson/SystemTextJsonExtensions.cs b/src/System.Linq.Dynamic.Core.SystemTextJson/SystemTextJsonExtensions.cs index 210f7fbd..4448798e 100644 --- a/src/System.Linq.Dynamic.Core.SystemTextJson/SystemTextJsonExtensions.cs +++ b/src/System.Linq.Dynamic.Core.SystemTextJson/SystemTextJsonExtensions.cs @@ -682,7 +682,7 @@ public static object Min(this JsonDocument source, LambdaExpression lambda) /// A sequence of values to order. /// The . /// An expression string to indicate values to order by. - /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. + /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. /// A whose elements are sorted according to the specified . public static JsonDocument OrderBy(this JsonDocument source, SystemTextJsonParsingConfig config, string ordering, params object?[] args) { @@ -699,7 +699,7 @@ public static JsonDocument OrderBy(this JsonDocument source, SystemTextJsonParsi /// /// A sequence of values to order. /// An expression string to indicate values to order by. - /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. + /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. /// A whose elements are sorted according to the specified . public static JsonDocument OrderBy(this JsonDocument source, string ordering, params object?[] args) { @@ -713,7 +713,7 @@ public static JsonDocument OrderBy(this JsonDocument source, string ordering, pa /// The . /// An expression string to indicate values to order by. /// The comparer to use. - /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. + /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. /// A whose elements are sorted according to the specified . public static JsonDocument OrderBy(this JsonDocument source, SystemTextJsonParsingConfig config, string ordering, IComparer comparer, params object?[] args) { @@ -727,7 +727,7 @@ public static JsonDocument OrderBy(this JsonDocument source, SystemTextJsonParsi /// A sequence of values to order. /// An expression string to indicate values to order by. /// The comparer to use. - /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. + /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. /// A whose elements are sorted according to the specified . public static JsonDocument OrderBy(this JsonDocument source, string ordering, IComparer comparer, params object?[] args) { @@ -1124,67 +1124,67 @@ public static JsonDocument TakeWhile(this JsonDocument source, string predicate, } #endregion TakeWhile - #region ThenBy - /// - /// Performs a subsequent ordering of the elements in a sequence in ascending order according to a key. - /// - /// A sequence of values to order. - /// The . - /// An expression string to indicate values to order by. - /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. - /// A whose elements are sorted according to the specified . - public static JsonDocument ThenBy(this JsonDocument source, SystemTextJsonParsingConfig config, string ordering, params object?[] args) - { - Check.NotNull(source); - Check.NotNull(config); - - var queryable = ToQueryable(source, config).OrderBy("0"); // Workaround to get IOrderedQueryable - return ToJsonDocumentArray(() => queryable.ThenBy(ordering, args)); - } - - /// - /// Performs a subsequent ordering of the elements in a sequence in ascending order according to a key. - /// - /// A sequence of values to order. - /// The . - /// An expression string to indicate values to order by. - /// The comparer to use. - /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. - /// A whose elements are sorted according to the specified . - public static JsonDocument ThenBy(this JsonDocument source, SystemTextJsonParsingConfig config, string ordering, IComparer comparer, params object?[] args) - { - Check.NotNull(source); - Check.NotNull(config); - - var queryable = ToQueryable(source, config).OrderBy("0"); // Workaround to get IOrderedQueryable; - return ToJsonDocumentArray(() => queryable.ThenBy(ordering, comparer, args)); - } - - /// - /// Performs a subsequent ordering of the elements in a sequence in ascending order according to a key. - /// - /// A sequence of values to order. - /// An expression string to indicate values to order by. - /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. - /// A whose elements are sorted according to the specified . - public static JsonDocument ThenBy(this JsonDocument source, string ordering, params object?[] args) - { - return ThenBy(source, SystemTextJsonParsingConfig.Default, ordering, args); - } - - /// - /// Performs a subsequent ordering of the elements in a sequence in ascending order according to a key. - /// - /// A sequence of values to order. - /// An expression string to indicate values to order by. - /// The comparer to use. - /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. - /// A whose elements are sorted according to the specified . - public static JsonDocument ThenBy(this JsonDocument source, string ordering, IComparer comparer, params object?[] args) - { - return ThenBy(source, SystemTextJsonParsingConfig.Default, ordering, comparer, args); - } - #endregion ThenBy + //#region ThenBy + ///// + ///// Performs a subsequent ordering of the elements in a sequence in ascending order according to a key. + ///// + ///// A sequence of values to order. + ///// The . + ///// An expression string to indicate values to order by. + ///// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. + ///// A whose elements are sorted according to the specified . + //public static JsonDocument ThenBy(this JsonDocument source, SystemTextJsonParsingConfig config, string ordering, params object?[] args) + //{ + // Check.NotNull(source); + // Check.NotNull(config); + + // var queryable = ToQueryable(source, config).OrderBy("0"); // Workaround to get IOrderedQueryable + // return ToJsonDocumentArray(() => queryable.ThenBy(ordering, args)); + //} + + ///// + ///// Performs a subsequent ordering of the elements in a sequence in ascending order according to a key. + ///// + ///// A sequence of values to order. + ///// The . + ///// An expression string to indicate values to order by. + ///// The comparer to use. + ///// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. + ///// A whose elements are sorted according to the specified . + //public static JsonDocument ThenBy(this JsonDocument source, SystemTextJsonParsingConfig config, string ordering, IComparer comparer, params object?[] args) + //{ + // Check.NotNull(source); + // Check.NotNull(config); + + // var queryable = ToQueryable(source, config).OrderBy("0"); // Workaround to get IOrderedQueryable; + // return ToJsonDocumentArray(() => queryable.ThenBy(ordering, comparer, args)); + //} + + ///// + ///// Performs a subsequent ordering of the elements in a sequence in ascending order according to a key. + ///// + ///// A sequence of values to order. + ///// An expression string to indicate values to order by. + ///// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. + ///// A whose elements are sorted according to the specified . + //public static JsonDocument ThenBy(this JsonDocument source, string ordering, params object?[] args) + //{ + // return ThenBy(source, SystemTextJsonParsingConfig.Default, ordering, args); + //} + + ///// + ///// Performs a subsequent ordering of the elements in a sequence in ascending order according to a key. + ///// + ///// A sequence of values to order. + ///// An expression string to indicate values to order by. + ///// The comparer to use. + ///// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. + ///// A whose elements are sorted according to the specified . + //public static JsonDocument ThenBy(this JsonDocument source, string ordering, IComparer comparer, params object?[] args) + //{ + // return ThenBy(source, SystemTextJsonParsingConfig.Default, ordering, comparer, args); + //} + //#endregion ThenBy #region Where /// diff --git a/src/System.Linq.Dynamic.Core/DynamicQueryableExtensions.cs b/src/System.Linq.Dynamic.Core/DynamicQueryableExtensions.cs index b25cb3bf..9accc7eb 100644 --- a/src/System.Linq.Dynamic.Core/DynamicQueryableExtensions.cs +++ b/src/System.Linq.Dynamic.Core/DynamicQueryableExtensions.cs @@ -646,7 +646,7 @@ public static dynamic FirstOrDefault(this IQueryable source, LambdaExpression la /// The . /// A string expression to specify the key for each element. /// A string expression to specify a result value from each group. - /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. + /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. /// A where each element represents a projection over a group and its key. /// /// @@ -669,7 +669,7 @@ public static IQueryable GroupBy(this IQueryable source, ParsingConfig config, s /// A string expression to specify the key for each element. /// A string expression to specify a result value from each group. /// The comparer to use. - /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. + /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. /// A where each element represents a projection over a group and its key. public static IQueryable GroupBy(this IQueryable source, ParsingConfig config, string keySelector, string resultSelector, IEqualityComparer? equalityComparer, object[]? args) { @@ -984,7 +984,7 @@ public static IQueryable GroupJoin(this IQueryable outer, IEnumerable inner, str /// A dynamic function to extract the join key from each element of the first sequence. /// A dynamic function to extract the join key from each element of the second sequence. /// A dynamic function to create a result element from two matching elements. - /// An object array that contains zero or more objects to insert into the predicates as parameters. Similar to the way String.Format formats strings. + /// An object array that contains zero or more objects to insert into the predicates as parameters. Similar to the way String.Format formats strings. /// An obtained by performing an inner join on two sequences. public static IQueryable Join(this IQueryable outer, ParsingConfig config, IEnumerable inner, string outerKeySelector, string innerKeySelector, string resultSelector, params object?[] args) { @@ -1043,7 +1043,7 @@ public static IQueryable Join(this IQueryable outer, IEnumerable inner, string o /// A dynamic function to extract the join key from each element of the first sequence. /// A dynamic function to extract the join key from each element of the second sequence. /// A dynamic function to create a result element from two matching elements. - /// An object array that contains zero or more objects to insert into the predicates as parameters. Similar to the way String.Format formats strings. + /// An object array that contains zero or more objects to insert into the predicates as parameters. Similar to the way String.Format formats strings. /// This overload only works on elements where both sequences and the resulting element match. /// An that has elements of type TResult obtained by performing an inner join on two sequences. public static IQueryable Join(this IQueryable outer, ParsingConfig config, IEnumerable inner, string outerKeySelector, string innerKeySelector, string resultSelector, params object?[] args) @@ -1532,7 +1532,7 @@ public static IOrderedQueryable OrderBy(this IQueryableA sequence of values to order. /// The . /// An expression string to indicate values to order by. - /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. + /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. /// A whose elements are sorted according to the specified . /// /// @@ -1558,7 +1558,7 @@ public static IOrderedQueryable OrderBy(this IQueryable source, ParsingConfig co /// The . /// An expression string to indicate values to order by. /// The comparer to use. - /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. + /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. /// A whose elements are sorted according to the specified . public static IOrderedQueryable OrderBy(this IQueryable source, ParsingConfig config, string ordering, IComparer comparer, params object?[] args) { @@ -1743,7 +1743,7 @@ public static IQueryable Reverse(this IQueryable source) /// A sequence of values to project. /// The . /// A projection string expression to apply to each element. - /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. + /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. /// An whose elements are the result of invoking a projection string on each element of source. /// /// @@ -1867,7 +1867,7 @@ public static IQueryable Select(this IQueryable source, Type resultType, string /// A sequence of values to project. /// The . /// A projection string expression to apply to each element. - /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. + /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. /// An whose elements are the result of invoking a one-to-many projection function on each element of the input sequence. /// /// @@ -2517,7 +2517,7 @@ public static IOrderedQueryable ThenBy(this IOrderedQueryable< /// A sequence of values to order. /// The . /// An expression string to indicate values to order by. - /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. + /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. /// A whose elements are sorted according to the specified . /// /// @@ -2539,7 +2539,7 @@ public static IOrderedQueryable ThenBy(this IOrderedQueryable source, ParsingCon /// The . /// An expression string to indicate values to order by. /// The comparer to use. - /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. + /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. /// A whose elements are sorted according to the specified . public static IOrderedQueryable ThenBy(this IOrderedQueryable source, ParsingConfig config, string ordering, IComparer comparer, params object?[] args) { diff --git a/test/System.Linq.Dynamic.Core.NewtonsoftJson.Tests/NewtonsoftJsonTests.cs b/test/System.Linq.Dynamic.Core.NewtonsoftJson.Tests/NewtonsoftJsonTests.cs index b1d3e3ef..c288fadb 100644 --- a/test/System.Linq.Dynamic.Core.NewtonsoftJson.Tests/NewtonsoftJsonTests.cs +++ b/test/System.Linq.Dynamic.Core.NewtonsoftJson.Tests/NewtonsoftJsonTests.cs @@ -173,24 +173,40 @@ public void Min() [Fact] public void OrderBy() { - // Act 1 + // Act var result = _source.OrderBy("Age").Select("Name"); - // Assert 1 + // Assert var array = result.Select(x => x.Value()); array.Should().BeEquivalentTo("John", "Doe"); + } - // Act 1 - var resultAsc = _source.OrderBy("Age", "Asc").Select("Name"); + [Fact] + public void OrderBy_Asc() + { + // Act + var resultAsc = _source.OrderBy("Age asc").Select("Name"); - // Assert 1 + // Assert var arrayAsc = resultAsc.Select(x => x.Value()); arrayAsc.Should().BeEquivalentTo("Doe", "John"); } [Fact] - public void OrderBy_ThenBy() + public void OrderBy_Desc() { + // Act + var resultAsc = _source.OrderBy("Age desc").Select("Name"); + + // Assert + var arrayAsc = resultAsc.Select(x => x.Value()); + arrayAsc.Should().BeEquivalentTo("John", "Doe"); + } + + [Fact] + public void OrderBy_Multiple() + { + // Arrange var json = """ [ @@ -200,7 +216,7 @@ public void OrderBy_ThenBy() }, { "Name": "Doe", - "Age": 40 + "Age": 30 }, { "Name": "Stef", @@ -211,11 +227,11 @@ public void OrderBy_ThenBy() var source = JArray.Parse(json); // Act - var result = source.OrderBy("Age").ThenBy("Name").Select("Name"); + var result = source.OrderBy("Age, Name").Select("Name"); // Assert var array = result.Select(x => x.Value()); - array.Should().BeEquivalentTo("Doe", "John", "Stef"); + array.Should().BeEquivalentTo("Stef", "John", "Doe"); } [Fact] diff --git a/test/System.Linq.Dynamic.Core.SystemTextJson.Tests/SystemTextJsonTests.cs b/test/System.Linq.Dynamic.Core.SystemTextJson.Tests/SystemTextJsonTests.cs index a5b0fe75..46b05c8c 100644 --- a/test/System.Linq.Dynamic.Core.SystemTextJson.Tests/SystemTextJsonTests.cs +++ b/test/System.Linq.Dynamic.Core.SystemTextJson.Tests/SystemTextJsonTests.cs @@ -185,15 +185,30 @@ public void Min() [Fact] public void OrderBy() { - // Act 1 + // Act var result = _source.OrderBy("Age").Select("Name"); - // Assert 1 + // Assert var array = result.RootElement.EnumerateArray().Select(x => x.GetString()); array.Should().BeEquivalentTo("John", "Doe"); + } + + [Fact] + public void OrderBy_Asc() + { + // Act + var resultAsc = _source.OrderBy("Age asc").Select("Name"); + // Assert + var arrayAsc = resultAsc.RootElement.EnumerateArray().Select(x => x.GetString()); + arrayAsc.Should().BeEquivalentTo("Doe", "John"); + } + + [Fact] + public void OrderBy_Desc() + { // Act 1 - var resultAsc = _source.OrderBy("Age", "Asc").Select("Name"); + var resultAsc = _source.OrderBy("Age desc").Select("Name"); // Assert 1 var arrayAsc = resultAsc.RootElement.EnumerateArray().Select(x => x.GetString()); @@ -201,8 +216,9 @@ public void OrderBy() } [Fact] - public void OrderBy_ThenBy() + public void OrderBy_Multiple() { + // Arrange var json = """ [ @@ -212,7 +228,7 @@ public void OrderBy_ThenBy() }, { "Name": "Doe", - "Age": 40 + "Age": 30 }, { "Name": "Stef", @@ -223,11 +239,11 @@ public void OrderBy_ThenBy() var source = JsonDocument.Parse(json); // Act - var result = source.OrderBy("Age").ThenBy("Name").Select("Name"); + var result = source.OrderBy("Age, Name").Select("Name"); // Assert var array = result.RootElement.EnumerateArray().Select(x => x.GetString()); - array.Should().BeEquivalentTo("Doe", "John", "Stef"); + array.Should().BeEquivalentTo("Stef", "John", "Doe"); } [Fact]