diff --git a/src/System.Linq.Dynamic.Core.NewtonsoftJson/NewtonsoftJsonExtensions.cs b/src/System.Linq.Dynamic.Core.NewtonsoftJson/NewtonsoftJsonExtensions.cs index 9ba04021..5b1c69ac 100644 --- a/src/System.Linq.Dynamic.Core.NewtonsoftJson/NewtonsoftJsonExtensions.cs +++ b/src/System.Linq.Dynamic.Core.NewtonsoftJson/NewtonsoftJsonExtensions.cs @@ -105,20 +105,6 @@ public static bool Any(this JArray source, string predicate, params object?[] ar { return Any(source, NewtonsoftJsonParsingConfig.Default, predicate, args); } - - /// - /// Determines whether a sequence contains any elements. - /// - /// The source - /// A Lambda Expression. - /// true if the source sequence contains any elements; otherwise, false. - public static bool Any(this JArray source, LambdaExpression lambda) - { - Check.NotNull(source); - - var queryable = ToQueryable(source); - return queryable.Any(lambda); - } #endregion Any #region Average @@ -164,21 +150,6 @@ public static double Average(this JArray source, string predicate, params object { return Average(source, NewtonsoftJsonParsingConfig.Default, predicate, args); } - - /// - /// Computes the average of a sequence of numeric values. - /// - /// The source - /// A Lambda Expression. - /// The average of the values in the sequence. - public static double Average(this JArray source, LambdaExpression lambda) - { - Check.NotNull(source); - Check.NotNull(lambda); - - var queryable = ToQueryable(source); - return queryable.Average(lambda); - } #endregion Average #region Cast @@ -253,20 +224,6 @@ public static int Count(this JArray source, string predicate, params object?[] a { return Count(source, NewtonsoftJsonParsingConfig.Default, predicate, args); } - - /// - /// Returns the number of elements in a sequence. - /// - /// The that contains the elements to be counted. - /// A cached Lambda Expression. - /// The number of elements in the specified sequence that satisfies a condition. - public static int Count(this JArray source, LambdaExpression lambda) - { - Check.NotNull(source); - - var queryable = ToQueryable(source); - return queryable.Count(lambda); - } #endregion Count #region DefaultIfEmpty @@ -314,20 +271,6 @@ public static JToken First(this JArray source, string predicate, params object?[ { return First(source, NewtonsoftJsonParsingConfig.Default, predicate, args) ?? throw new InvalidOperationException(Res.SequenceContainsNoElements); } - - /// - /// Returns the first element of a sequence that satisfies a specified condition. - /// - /// The to return the first element of. - /// A cached Lambda Expression. - /// The first element in source that passes the test in predicate. - public static JToken First(this JArray source, LambdaExpression lambda) - { - Check.NotNull(source); - - var queryable = ToQueryable(source); - return ToJToken(queryable.First(lambda)) ?? throw new InvalidOperationException(Res.SequenceContainsNoElements); - } #endregion First #region FirstOrDefault @@ -359,20 +302,6 @@ public static JToken First(this JArray source, LambdaExpression lambda) { return FirstOrDefault(source, NewtonsoftJsonParsingConfig.Default, predicate, args); } - - /// - /// Returns the first element of a sequence that satisfies a specified condition or a default value if no such element is found. - /// - /// The to return the first element of. - /// A cached Lambda Expression. - /// default if source is empty or if no element passes the test specified by predicate; otherwise, the first element in source that passes the test specified by predicate. - public static JToken? FirstOrDefault(this JArray source, LambdaExpression lambda) - { - Check.NotNull(source); - - var queryable = ToQueryable(source); - return ToJToken(queryable.FirstOrDefault(lambda)); - } #endregion FirstOrDefault #region Last @@ -404,20 +333,6 @@ public static JToken Last(this JArray source, string predicate, params object?[] { return Last(source, NewtonsoftJsonParsingConfig.Default, predicate, args); } - - /// - /// Returns the last element of a sequence that satisfies a specified condition. - /// - /// The to return the last element of. - /// A cached Lambda Expression. - /// The first element in source that passes the test in predicate. - public static JToken Last(this JArray source, LambdaExpression lambda) - { - Check.NotNull(source); - - var queryable = ToQueryable(source); - return ToJToken(queryable.Last(lambda)) ?? throw new InvalidOperationException(Res.SequenceContainsNoElements); - } #endregion Last #region LastOrDefault @@ -449,20 +364,6 @@ public static JToken Last(this JArray source, LambdaExpression lambda) { return LastOrDefault(source, NewtonsoftJsonParsingConfig.Default, predicate, args); } - - /// - /// Returns the last element of a sequence that satisfies a specified condition, or a default value if the sequence contains no elements. - /// - /// The to return the last element of. - /// A cached Lambda Expression. - /// The first element in source that passes the test in predicate. - public static JToken? LastOrDefault(this JArray source, LambdaExpression lambda) - { - Check.NotNull(source); - - var queryable = ToQueryable(source); - return ToJToken(queryable.LastOrDefault(lambda)); - } #endregion LastOrDefault #region Max @@ -494,20 +395,6 @@ public static object Max(this JArray source, string predicate, params object?[] { return Max(source, NewtonsoftJsonParsingConfig.Default, predicate, args); } - - /// - /// Computes the max element of a sequence. - /// - /// A sequence of values to calculate find the max for. - /// A Lambda Expression. - /// The max element in the sequence. - public static object Max(this JArray source, LambdaExpression lambda) - { - Check.NotNull(source); - - var queryable = ToQueryable(source); - return queryable.Max(lambda); - } #endregion Max #region Min @@ -539,20 +426,6 @@ public static object Min(this JArray source, string predicate, params object?[] { return Min(source, NewtonsoftJsonParsingConfig.Default, predicate, args); } - - /// - /// Computes the min element of a sequence. - /// - /// A sequence of values to calculate find the min for. - /// A Lambda Expression. - /// The min element in the sequence. - public static object Min(this JArray source, LambdaExpression lambda) - { - Check.NotNull(source); - - var queryable = ToQueryable(source); - return queryable.Min(lambda); - } #endregion Min #region OrderBy @@ -749,19 +622,6 @@ public static JToken Single(this JArray source, string predicate, params object? { return Single(source, NewtonsoftJsonParsingConfig.Default, predicate, args); } - - /// - /// Returns the only element of a sequence that satisfies a specified condition, and throws an exception if there - /// is not exactly one element in the sequence. - /// - /// The to return the last element of. - /// A cached Lambda Expression. - /// The first element in source that passes the test in predicate. - public static JToken Single(this JArray source, LambdaExpression lambda) - { - var queryable = ToQueryable(source); - return ToJToken(queryable.Single(lambda)) ?? throw new InvalidOperationException(Res.SequenceContainsNoElements); - } #endregion Single #region SingleOrDefault @@ -795,21 +655,6 @@ public static JToken Single(this JArray source, LambdaExpression lambda) { return SingleOrDefault(source, NewtonsoftJsonParsingConfig.Default, predicate, args); } - - /// - /// Returns the only element of a sequence that satisfies a specified condition or a default value if the sequence - /// is empty; and throws an exception if there is not exactly one element in the sequence. - /// - /// The to return the last element of. - /// A cached Lambda Expression. - /// The first element in source that passes the test in predicate. - public static JToken? SingleOrDefault(this JArray source, LambdaExpression lambda) - { - Check.NotNull(source); - - var queryable = ToQueryable(source); - return ToJToken(queryable.SingleOrDefault(lambda)); - } #endregion SingleOrDefault #region SkipWhile @@ -874,68 +719,6 @@ 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 Where /// /// Filters a sequence of values based on a predicate. @@ -971,21 +754,6 @@ public static JArray Where(this JArray source, NewtonsoftJsonParsingConfig confi var queryable = ToQueryable(source, config); return ToJArray(() => queryable.Where(config, predicate, args)); } - - /// - /// Filters a sequence of values based on a predicate. - /// - /// A to filter. - /// A cached Lambda Expression. - /// A that contains elements from the input sequence that satisfy the condition specified by LambdaExpression. - public static JArray Where(this JArray source, LambdaExpression lambda) - { - Check.NotNull(source); - Check.NotNull(lambda); - - var queryable = ToQueryable(source); - return ToJArray(() => queryable.Where(lambda)); - } #endregion Where #region Private Methods diff --git a/src/System.Linq.Dynamic.Core.SystemTextJson/SystemTextJsonExtensions.cs b/src/System.Linq.Dynamic.Core.SystemTextJson/SystemTextJsonExtensions.cs index 4448798e..48ccc581 100644 --- a/src/System.Linq.Dynamic.Core.SystemTextJson/SystemTextJsonExtensions.cs +++ b/src/System.Linq.Dynamic.Core.SystemTextJson/SystemTextJsonExtensions.cs @@ -106,20 +106,6 @@ public static bool Any(this JsonDocument source, string predicate, params object { return Any(source, SystemTextJsonParsingConfig.Default, predicate, args); } - - /// - /// Determines whether a sequence contains any elements. - /// - /// The source - /// A Lambda Expression. - /// true if the source sequence contains any elements; otherwise, false. - public static bool Any(this JsonDocument source, LambdaExpression lambda) - { - Check.NotNull(source); - - var queryable = ToQueryable(source); - return queryable.Any(lambda); - } #endregion Any #region Average @@ -165,21 +151,6 @@ public static double Average(this JsonDocument source, string predicate, params { return Average(source, SystemTextJsonParsingConfig.Default, predicate, args); } - - /// - /// Computes the average of a sequence of numeric values. - /// - /// The source - /// A Lambda Expression. - /// The average of the values in the sequence. - public static double Average(this JsonDocument source, LambdaExpression lambda) - { - Check.NotNull(source); - Check.NotNull(lambda); - - var queryable = ToQueryable(source); - return queryable.Average(lambda); - } #endregion Average #region Cast @@ -267,20 +238,6 @@ public static int Count(this JsonDocument source, string predicate, params objec { return Count(source, SystemTextJsonParsingConfig.Default, predicate, args); } - - /// - /// Returns the number of elements in a sequence. - /// - /// The that contains the elements to be counted. - /// A cached Lambda Expression. - /// The number of elements in the specified sequence that satisfies a condition. - public static int Count(this JsonDocument source, LambdaExpression lambda) - { - Check.NotNull(source); - - var queryable = ToQueryable(source); - return queryable.Count(lambda); - } #endregion Count #region DefaultIfEmpty @@ -369,20 +326,6 @@ public static JsonElement First(this JsonDocument source, string predicate, para { return First(source, SystemTextJsonParsingConfig.Default, predicate, args); } - - /// - /// Returns the first element of a sequence that satisfies a specified condition. - /// - /// The to return the first element of. - /// A cached Lambda Expression. - /// The first element in source that passes the test in predicate. - public static JsonElement First(this JsonDocument source, LambdaExpression lambda) - { - Check.NotNull(source); - - var queryable = ToQueryable(source); - return ToJsonElement(queryable.First(lambda)) ?? throw new InvalidOperationException(Res.SequenceContainsNoElements); - } #endregion First #region FirstOrDefault @@ -427,20 +370,6 @@ public static JsonElement First(this JsonDocument source, LambdaExpression lambd { return FirstOrDefault(source, SystemTextJsonParsingConfig.Default, predicate, args); } - - /// - /// Returns the first element of a sequence that satisfies a specified condition or a default value if no such element is found. - /// - /// The to return the first element of. - /// A cached Lambda Expression. - /// default if source is empty or if no element passes the test specified by predicate; otherwise, the first element in source that passes the test specified by predicate. - public static JsonElement? FirstOrDefault(this JsonDocument source, LambdaExpression lambda) - { - Check.NotNull(source); - - var queryable = ToQueryable(source); - return ToJsonElement(queryable.FirstOrDefault(lambda)); - } #endregion FirstOrDefault #region Last @@ -485,20 +414,6 @@ public static JsonElement Last(this JsonDocument source, string predicate, param { return Last(source, SystemTextJsonParsingConfig.Default, predicate, args); } - - /// - /// Returns the last element of a sequence that satisfies a specified condition. - /// - /// The to return the last element of. - /// A cached Lambda Expression. - /// The first element in source that passes the test in predicate. - public static JsonElement Last(this JsonDocument source, LambdaExpression lambda) - { - Check.NotNull(source); - - var queryable = ToQueryable(source); - return ToJsonElement(queryable.Last(lambda)) ?? throw new InvalidOperationException(Res.SequenceContainsNoElements); - } #endregion Last #region LastOrDefault @@ -543,20 +458,6 @@ public static JsonElement Last(this JsonDocument source, LambdaExpression lambda { return LastOrDefault(source, SystemTextJsonParsingConfig.Default, predicate, args); } - - /// - /// Returns the last element of a sequence that satisfies a specified condition, or a default value if the sequence contains no elements. - /// - /// The to return the last element of. - /// A cached Lambda Expression. - /// The first element in source that passes the test in predicate. - public static JsonElement? LastOrDefault(this JsonDocument source, LambdaExpression lambda) - { - Check.NotNull(source); - - var queryable = ToQueryable(source); - return ToJsonElement(queryable.LastOrDefault(lambda)); - } #endregion LastOrDefault #region Max @@ -601,20 +502,6 @@ public static object Max(this JsonDocument source, string predicate, params obje { return Max(source, SystemTextJsonParsingConfig.Default, predicate, args); } - - /// - /// Computes the max element of a sequence. - /// - /// A sequence of values to calculate find the max for. - /// A Lambda Expression. - /// The max element in the sequence. - public static object Max(this JsonDocument source, LambdaExpression lambda) - { - Check.NotNull(source); - - var queryable = ToQueryable(source); - return queryable.Max(lambda); - } #endregion Max #region Min @@ -659,20 +546,6 @@ public static object Min(this JsonDocument source, string predicate, params obje { return Min(source, SystemTextJsonParsingConfig.Default, predicate, args); } - - /// - /// Computes the min element of a sequence. - /// - /// A sequence of values to calculate find the min for. - /// A Lambda Expression. - /// The min element in the sequence. - public static object Min(this JsonDocument source, LambdaExpression lambda) - { - Check.NotNull(source); - - var queryable = ToQueryable(source); - return queryable.Min(lambda); - } #endregion Min #region OrderBy @@ -893,19 +766,6 @@ public static JsonElement Single(this JsonDocument source, string predicate, par { return Single(source, SystemTextJsonParsingConfig.Default, predicate, args); } - - /// - /// Returns the only element of a sequence that satisfies a specified condition, and throws an exception if there - /// is not exactly one element in the sequence. - /// - /// The to return the last element of. - /// A cached Lambda Expression. - /// The first element in source that passes the test in predicate. - public static JsonElement Single(this JsonDocument source, LambdaExpression lambda) - { - var queryable = ToQueryable(source); - return ToJsonElement(queryable.Single(lambda)) ?? throw new InvalidOperationException(Res.SequenceContainsNoElements); - } #endregion Single #region SingleOrDefault @@ -954,21 +814,6 @@ public static JsonElement Single(this JsonDocument source, LambdaExpression lamb { return SingleOrDefault(source, SystemTextJsonParsingConfig.Default, predicate, args); } - - /// - /// Returns the only element of a sequence that satisfies a specified condition or a default value if the sequence - /// is empty; and throws an exception if there is not exactly one element in the sequence. - /// - /// The to return the last element of. - /// A cached Lambda Expression. - /// The first element in source that passes the test in predicate. - public static JsonElement? SingleOrDefault(this JsonDocument source, LambdaExpression lambda) - { - Check.NotNull(source); - - var queryable = ToQueryable(source); - return ToJsonElement(queryable.SingleOrDefault(lambda)); - } #endregion SingleOrDefault #region Skip @@ -1060,21 +905,6 @@ public static object Sum(this JsonDocument source, string predicate, params obje { return Sum(source, SystemTextJsonParsingConfig.Default, predicate, args); } - - /// - /// Computes the sum of a sequence of numeric values. - /// - /// A sequence of numeric values to calculate the sum of. - /// A Lambda Expression. - /// The sum of the values in the sequence. - public static object Sum(this JsonDocument source, LambdaExpression lambda) - { - Check.NotNull(source); - Check.NotNull(lambda); - - var queryable = ToQueryable(source); - return queryable.Sum(lambda); - } #endregion Sum #region Take @@ -1124,68 +954,6 @@ 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 Where /// /// Filters a sequence of values based on a predicate. @@ -1215,21 +983,6 @@ public static JsonDocument Where(this JsonDocument source, SystemTextJsonParsing var queryable = ToQueryable(source, config); return ToJsonDocumentArray(() => queryable.Where(config, predicate, args)); } - - /// - /// Filters a sequence of values based on a predicate. - /// - /// A to filter. - /// A cached Lambda Expression. - /// A that contains elements from the input sequence that satisfy the condition specified by LambdaExpression. - public static JsonDocument Where(this JsonDocument source, LambdaExpression lambda) - { - Check.NotNull(source); - Check.NotNull(lambda); - - var queryable = ToQueryable(source); - return ToJsonDocumentArray(() => queryable.Where(lambda)); - } #endregion Where #region Private Methods diff --git a/test/System.Linq.Dynamic.Core.NewtonsoftJson.Tests/NewtonsoftJsonTests.cs b/test/System.Linq.Dynamic.Core.NewtonsoftJson.Tests/NewtonsoftJsonTests.cs index c288fadb..debfb4b7 100644 --- a/test/System.Linq.Dynamic.Core.NewtonsoftJson.Tests/NewtonsoftJsonTests.cs +++ b/test/System.Linq.Dynamic.Core.NewtonsoftJson.Tests/NewtonsoftJsonTests.cs @@ -6,7 +6,7 @@ namespace System.Linq.Dynamic.Core.NewtonsoftJson.Tests; public class NewtonsoftJsonTests { - private const string ExampleJson = + private const string ExampleJsonObjectArray = """ [ { @@ -19,7 +19,16 @@ public class NewtonsoftJsonTests } ] """; - private readonly JArray _source = JArray.Parse(ExampleJson); + private readonly JArray _source = JArray.Parse(ExampleJsonObjectArray); + + private const string ExampleJsonIntArray = + """ + [ + 30, + 40 + ] + """; + private readonly JArray _sourceIntArray = JArray.Parse(ExampleJsonIntArray); [Fact] public void Aggregate() @@ -43,6 +52,16 @@ public void All() [Fact] public void Any() + { + // Act + var result = _source.Any(); + + // Assert + result.Should().BeTrue(); + } + + [Fact] + public void Any_Predicate() { // Act var result = _source.Any("Age > 20"); @@ -53,6 +72,16 @@ public void Any() [Fact] public void Average() + { + // Act + var result = _sourceIntArray.Average(); + + // Assert + result.Should().BeApproximately(35, 0.00001); + } + + [Fact] + public void Average_Predicate() { // Act var result = _source.Average("Age"); @@ -84,7 +113,7 @@ public void Cast() public void Count() { // Act 1 - var result1 = _source.Count(); + var result1 = _source.Count; // Assert 1 result1.Should().Be(2); @@ -143,7 +172,7 @@ public void FirstOrDefault() public void Last() { // Act + Assert - ((string?)_source.First("Age > 30")["Name"]).Should().Be("Doe"); + ((string?)_source.Last("Age > 30")["Name"]).Should().Be("Doe"); } [Fact] diff --git a/test/System.Linq.Dynamic.Core.SystemTextJson.Tests/System.Linq.Dynamic.Core.SystemTextJson.Tests.csproj b/test/System.Linq.Dynamic.Core.SystemTextJson.Tests/System.Linq.Dynamic.Core.SystemTextJson.Tests.csproj index d437f261..dd619154 100644 --- a/test/System.Linq.Dynamic.Core.SystemTextJson.Tests/System.Linq.Dynamic.Core.SystemTextJson.Tests.csproj +++ b/test/System.Linq.Dynamic.Core.SystemTextJson.Tests/System.Linq.Dynamic.Core.SystemTextJson.Tests.csproj @@ -12,7 +12,6 @@ - all diff --git a/test/System.Linq.Dynamic.Core.SystemTextJson.Tests/SystemTextJsonTests.cs b/test/System.Linq.Dynamic.Core.SystemTextJson.Tests/SystemTextJsonTests.cs index 46b05c8c..ca337755 100644 --- a/test/System.Linq.Dynamic.Core.SystemTextJson.Tests/SystemTextJsonTests.cs +++ b/test/System.Linq.Dynamic.Core.SystemTextJson.Tests/SystemTextJsonTests.cs @@ -6,7 +6,7 @@ namespace System.Linq.Dynamic.Core.SystemTextJson.Tests; public class SystemTextJsonTests { - private const string ExampleJson = + private const string ExampleJsonObjectArray = """ [ { @@ -19,7 +19,16 @@ public class SystemTextJsonTests } ] """; - private readonly JsonDocument _source = JsonDocument.Parse(ExampleJson); + private readonly JsonDocument _source = JsonDocument.Parse(ExampleJsonObjectArray); + + private const string ExampleJsonIntArray = + """ + [ + 30, + 40 + ] + """; + private readonly JsonDocument _sourceIntArray = JsonDocument.Parse(ExampleJsonIntArray); [Fact] public void Aggregate() @@ -43,6 +52,16 @@ public void All() [Fact] public void Any() + { + // Act + var result = _source.Any(); + + // Assert + result.Should().BeTrue(); + } + + [Fact] + public void Any_Predicate() { // Act var result = _source.Any("Age > 20"); @@ -53,6 +72,16 @@ public void Any() [Fact] public void Average() + { + // Act + var result = _sourceIntArray.Average(); + + // Assert + result.Should().BeApproximately(35, 0.00001); + } + + [Fact] + public void Average_Predicate() { // Act var result = _source.Average("Age");