diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 8c02049a..dd2c5124 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -38,8 +38,9 @@ steps: # Build tests and run tests for net452 and netcoreapp2.1 (with coverage) - script: | - dotnet test ./test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj --configuration Debug --framework net452 - dotnet test ./test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj --configuration Debug --framework netcoreapp2.1 --logger trx /p:CollectCoverage=true /p:CoverletOutputFormat=opencover + dotnet build ./test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj --configuration Debug + dotnet test ./test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj --no-build --configuration Debug --framework net452 + dotnet test ./test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj --no-build --configuration Debug --framework netcoreapp2.1 --logger trx /p:CollectCoverage=true /p:CoverletOutputFormat=opencover displayName: 'Build tests and run tests for net452 and netcoreapp2.1 (with coverage)' # End SonarScanner diff --git a/src/System.Linq.Dynamic.Core/DefaultQueryableAnalyzer.cs b/src/System.Linq.Dynamic.Core/DefaultQueryableAnalyzer.cs index 522392c8..a9136777 100644 --- a/src/System.Linq.Dynamic.Core/DefaultQueryableAnalyzer.cs +++ b/src/System.Linq.Dynamic.Core/DefaultQueryableAnalyzer.cs @@ -15,7 +15,8 @@ public bool SupportsLinqToObjects(IQueryable query, IQueryProvider provider = nu Check.NotNull(query, nameof(query)); provider = provider ?? query.Provider; - Type baseType = provider.GetType().GetTypeInfo().BaseType; + Type providerType = provider.GetType(); + Type baseType = providerType.GetTypeInfo().BaseType; #if NET35 bool isLinqToObjects = baseType.FullName.Contains("EnumerableQuery"); #else @@ -24,13 +25,18 @@ public bool SupportsLinqToObjects(IQueryable query, IQueryProvider provider = nu if (!isLinqToObjects) { // Support for https://github.com/StefH/QueryInterceptor.Core, version 1.0.1 and up - if (baseType.Name == "QueryTranslatorProvider") + if (providerType.Name.StartsWith("QueryTranslatorProvider")) { try { - PropertyInfo property = baseType.GetProperty("OriginalProvider"); - IQueryProvider originalProvider = property.GetValue(provider, null) as IQueryProvider; - return originalProvider != null && SupportsLinqToObjects(query, originalProvider); + PropertyInfo property = providerType.GetProperty("OriginalProvider"); + if (property != null) + { + IQueryProvider originalProvider = property.GetValue(provider, null) as IQueryProvider; + return originalProvider != null && SupportsLinqToObjects(query, originalProvider); + } + + return SupportsLinqToObjects(query); } catch { @@ -39,7 +45,7 @@ public bool SupportsLinqToObjects(IQueryable query, IQueryProvider provider = nu } // Support for https://github.com/scottksmith95/LINQKit ExpandableQuery - if (provider.GetType().GetTypeInfo().Name.StartsWith("ExpandableQuery")) + if (providerType.Name.StartsWith("ExpandableQuery")) { try { diff --git a/src/System.Linq.Dynamic.Core/DynamicQueryableExtensions.cs b/src/System.Linq.Dynamic.Core/DynamicQueryableExtensions.cs index a7f359af..6e5b21ea 100644 --- a/src/System.Linq.Dynamic.Core/DynamicQueryableExtensions.cs +++ b/src/System.Linq.Dynamic.Core/DynamicQueryableExtensions.cs @@ -140,9 +140,10 @@ public static bool Any([NotNull] this IQueryable source) /// /// true if the source sequence contains any elements; otherwise, false. [PublicAPI] - public static bool Any([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string predicate, params object[] args) + public static bool Any([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] string predicate, params object[] args) { Check.NotNull(source, nameof(source)); + Check.NotNull(config, nameof(config)); Check.NotEmpty(predicate, nameof(predicate)); bool createParameterCtor = SupportsLinqToObjects(config, source); @@ -154,7 +155,7 @@ public static bool Any([NotNull] this IQueryable source, [CanBeNull] ParsingConf /// public static bool Any([NotNull] this IQueryable source, [NotNull] string predicate, params object[] args) { - return Any(source, null, predicate, args); + return Any(source, ParsingConfig.Default, predicate, args); } /// @@ -236,9 +237,10 @@ public static int Count([NotNull] this IQueryable source) /// /// The number of elements in the specified sequence that satisfies a condition. [PublicAPI] - public static int Count([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string predicate, params object[] args) + public static int Count([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] string predicate, params object[] args) { Check.NotNull(source, nameof(source)); + Check.NotNull(config, nameof(config)); Check.NotEmpty(predicate, nameof(predicate)); bool createParameterCtor = SupportsLinqToObjects(config, source); @@ -250,7 +252,7 @@ public static int Count([NotNull] this IQueryable source, [CanBeNull] ParsingCon /// public static int Count([NotNull] this IQueryable source, [NotNull] string predicate, params object[] args) { - return Count(source, null, predicate, args); + return Count(source, ParsingConfig.Default, predicate, args); } /// @@ -362,12 +364,13 @@ public static dynamic First([NotNull] this IQueryable source) /// The first element in source that passes the test in predicate. [PublicAPI] #if NET35 - public static object First([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string predicate, params object[] args) + public static object First([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] string predicate, params object[] args) #else - public static dynamic First([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string predicate, params object[] args) + public static dynamic First([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] string predicate, params object[] args) #endif { Check.NotNull(source, nameof(source)); + Check.NotNull(config, nameof(config)); Check.NotEmpty(predicate, nameof(predicate)); bool createParameterCtor = SupportsLinqToObjects(config, source); @@ -383,7 +386,7 @@ public static object First([NotNull] this IQueryable source, [NotNull] string pr public static dynamic First([NotNull] this IQueryable source, [NotNull] string predicate, params object[] args) #endif { - return First(source, null, predicate, args); + return First(source, ParsingConfig.Default, predicate, args); } /// @@ -432,12 +435,13 @@ public static dynamic FirstOrDefault([NotNull] this IQueryable source) /// 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. [PublicAPI] #if NET35 - public static object FirstOrDefault([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string predicate, params object[] args) + public static object FirstOrDefault([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] string predicate, params object[] args) #else - public static dynamic FirstOrDefault([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string predicate, params object[] args) + public static dynamic FirstOrDefault([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] string predicate, params object[] args) #endif { Check.NotNull(source, nameof(source)); + Check.NotNull(config, nameof(config)); Check.NotEmpty(predicate, nameof(predicate)); bool createParameterCtor = SupportsLinqToObjects(config, source); @@ -453,7 +457,7 @@ public static object FirstOrDefault([NotNull] this IQueryable source, [NotNull] public static dynamic FirstOrDefault([NotNull] this IQueryable source, [NotNull] string predicate, params object[] args) #endif { - return FirstOrDefault(source, null, predicate, args); + return FirstOrDefault(source, ParsingConfig.Default, predicate, args); } /// @@ -493,9 +497,10 @@ public static dynamic FirstOrDefault([NotNull] this IQueryable source, [NotNull] /// /// [PublicAPI] - public static IQueryable GroupBy([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string keySelector, [NotNull] string resultSelector, object[] args) + public static IQueryable GroupBy([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] string keySelector, [NotNull] string resultSelector, object[] args) { Check.NotNull(source, nameof(source)); + Check.NotNull(config, nameof(config)); Check.NotEmpty(keySelector, nameof(keySelector)); Check.NotEmpty(resultSelector, nameof(resultSelector)); @@ -515,7 +520,7 @@ public static IQueryable GroupBy([NotNull] this IQueryable source, [CanBeNull] P [PublicAPI] public static IQueryable GroupBy([NotNull] this IQueryable source, [NotNull] string keySelector, [NotNull] string resultSelector, object[] args) { - return GroupBy(source, null, keySelector, resultSelector, args); + return GroupBy(source, ParsingConfig.Default, keySelector, resultSelector, args); } /// @@ -533,19 +538,15 @@ public static IQueryable GroupBy([NotNull] this IQueryable source, [NotNull] str /// var groupResult2 = queryable.GroupBy("new (NumberPropertyAsKey, StringPropertyAsKey)", "new (StringProperty1, StringProperty2)"); /// /// - public static IQueryable GroupBy([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string keySelector, [NotNull] string resultSelector) + public static IQueryable GroupBy([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] string keySelector, [NotNull] string resultSelector) { - Check.NotNull(source, nameof(source)); - Check.NotEmpty(keySelector, nameof(keySelector)); - Check.NotEmpty(resultSelector, nameof(resultSelector)); - return GroupBy(source, config, keySelector, resultSelector, null); } /// public static IQueryable GroupBy([NotNull] this IQueryable source, [NotNull] string keySelector, [NotNull] string resultSelector) { - return GroupBy(source, null, keySelector, resultSelector); + return GroupBy(source, ParsingConfig.Default, keySelector, resultSelector); } /// @@ -564,9 +565,10 @@ public static IQueryable GroupBy([NotNull] this IQueryable source, [NotNull] str /// /// [PublicAPI] - public static IQueryable GroupBy([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string keySelector, [CanBeNull] params object[] args) + public static IQueryable GroupBy([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] string keySelector, [CanBeNull] params object[] args) { Check.NotNull(source, nameof(source)); + Check.NotNull(config, nameof(config)); Check.NotEmpty(keySelector, nameof(keySelector)); bool createParameterCtor = config?.EvaluateGroupByAtDatabase ?? SupportsLinqToObjects(config, source); @@ -583,7 +585,7 @@ public static IQueryable GroupBy([NotNull] this IQueryable source, [CanBeNull] P [PublicAPI] public static IQueryable GroupBy([NotNull] this IQueryable source, [NotNull] string keySelector, [CanBeNull] params object[] args) { - return GroupBy(source, (ParsingConfig)null, keySelector, args); + return GroupBy(source, ParsingConfig.Default, keySelector, args); } #endregion GroupBy @@ -597,9 +599,10 @@ public static IQueryable GroupBy([NotNull] this IQueryable source, [NotNull] str /// The . /// expressions to specify the keys for each element. /// A of type where each element represents a projection over a group, its key, and its subgroups. - public static IEnumerable GroupByMany([NotNull] this IEnumerable source, [CanBeNull] ParsingConfig config, params string[] keySelectors) + public static IEnumerable GroupByMany([NotNull] this IEnumerable source, [NotNull] ParsingConfig config, params string[] keySelectors) { Check.NotNull(source, nameof(source)); + Check.NotNull(config, nameof(config)); Check.HasNoNulls(keySelectors, nameof(keySelectors)); var selectors = new List>(keySelectors.Length); @@ -617,7 +620,7 @@ public static IEnumerable GroupByMany([NotNull] this IEnu /// public static IEnumerable GroupByMany([NotNull] this IEnumerable source, params string[] keySelectors) { - return GroupByMany(source, null, keySelectors); + return GroupByMany(source, ParsingConfig.Default, keySelectors); } /// @@ -636,9 +639,12 @@ public static IEnumerable GroupByMany([NotNull] this IEnu return GroupByManyInternal(source, keySelectors, 0); } - static IEnumerable GroupByManyInternal(IEnumerable source, Func[] keySelectors, int currentSelector) + private static IEnumerable GroupByManyInternal(IEnumerable source, Func[] keySelectors, int currentSelector) { - if (currentSelector >= keySelectors.Length) return null; + if (currentSelector >= keySelectors.Length) + { + return null; + } var selector = keySelectors[currentSelector]; @@ -667,9 +673,10 @@ static IEnumerable GroupByManyInternal(IEnumerableA dynamic function to create a result element from an element from the first sequence and a collection of matching elements from the second sequence. /// 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 a grouped join on two sequences. - public static IQueryable GroupJoin([NotNull] this IQueryable outer, [CanBeNull] ParsingConfig config, [NotNull] IEnumerable inner, [NotNull] string outerKeySelector, [NotNull] string innerKeySelector, [NotNull] string resultSelector, params object[] args) + public static IQueryable GroupJoin([NotNull] this IQueryable outer, [NotNull] ParsingConfig config, [NotNull] IEnumerable inner, [NotNull] string outerKeySelector, [NotNull] string innerKeySelector, [NotNull] string resultSelector, params object[] args) { Check.NotNull(outer, nameof(outer)); + Check.NotNull(config, nameof(config)); Check.NotNull(inner, nameof(inner)); Check.NotEmpty(outerKeySelector, nameof(outerKeySelector)); Check.NotEmpty(innerKeySelector, nameof(innerKeySelector)); @@ -705,7 +712,7 @@ public static IQueryable GroupJoin([NotNull] this IQueryable outer, [CanBeNull] /// public static IQueryable GroupJoin([NotNull] this IQueryable outer, [NotNull] IEnumerable inner, [NotNull] string outerKeySelector, [NotNull] string innerKeySelector, [NotNull] string resultSelector, params object[] args) { - return GroupJoin(outer, null, inner, outerKeySelector, innerKeySelector, resultSelector, args); + return GroupJoin(outer, ParsingConfig.Default, inner, outerKeySelector, innerKeySelector, resultSelector, args); } #endregion @@ -721,11 +728,12 @@ public static IQueryable GroupJoin([NotNull] this IQueryable outer, [NotNull] IE /// 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 obtained by performing an inner join on two sequences. - public static IQueryable Join([NotNull] this IQueryable outer, [CanBeNull] ParsingConfig config, [NotNull] IEnumerable inner, [NotNull] string outerKeySelector, [NotNull] string innerKeySelector, [NotNull] string resultSelector, params object[] args) + public static IQueryable Join([NotNull] this IQueryable outer, [NotNull] ParsingConfig config, [NotNull] IEnumerable inner, [NotNull] string outerKeySelector, [NotNull] string innerKeySelector, [NotNull] string resultSelector, params object[] args) { //http://stackoverflow.com/questions/389094/how-to-create-a-dynamic-linq-join-extension-method Check.NotNull(outer, nameof(outer)); + Check.NotNull(config, nameof(config)); Check.NotNull(inner, nameof(inner)); Check.NotEmpty(outerKeySelector, nameof(outerKeySelector)); Check.NotEmpty(innerKeySelector, nameof(innerKeySelector)); @@ -764,7 +772,7 @@ public static IQueryable Join([NotNull] this IQueryable outer, [CanBeNull] Parsi /// public static IQueryable Join([NotNull] this IQueryable outer, [NotNull] IEnumerable inner, [NotNull] string outerKeySelector, [NotNull] string innerKeySelector, [NotNull] string resultSelector, params object[] args) { - return Join(outer, null, inner, outerKeySelector, innerKeySelector, resultSelector, args); + return Join(outer, ParsingConfig.Default, inner, outerKeySelector, innerKeySelector, resultSelector, args); } /// @@ -780,7 +788,7 @@ public static IQueryable Join([NotNull] this IQueryable outer, [NotNull] IEnumer /// 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([NotNull] this IQueryable outer, [CanBeNull] ParsingConfig config, [NotNull] IEnumerable inner, [NotNull] string outerKeySelector, [NotNull] string innerKeySelector, string resultSelector, params object[] args) + public static IQueryable Join([NotNull] this IQueryable outer, [NotNull] ParsingConfig config, [NotNull] IEnumerable inner, [NotNull] string outerKeySelector, [NotNull] string innerKeySelector, string resultSelector, params object[] args) { return (IQueryable)Join(outer, config, (IEnumerable)inner, outerKeySelector, innerKeySelector, resultSelector, args); } @@ -788,7 +796,7 @@ public static IQueryable Join([NotNull] this IQueryable public static IQueryable Join([NotNull] this IQueryable outer, [NotNull] IEnumerable inner, [NotNull] string outerKeySelector, [NotNull] string innerKeySelector, string resultSelector, params object[] args) { - return Join(outer, null, inner, outerKeySelector, innerKeySelector, resultSelector, args); + return Join(outer, ParsingConfig.Default, inner, outerKeySelector, innerKeySelector, resultSelector, args); } #endregion Join @@ -821,12 +829,13 @@ public static dynamic Last([NotNull] this IQueryable source) /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. /// The first element in source that passes the test in predicate. #if NET35 - public static object Last([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string predicate, params object[] args) + public static object Last([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] string predicate, params object[] args) #else - public static dynamic Last([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string predicate, params object[] args) + public static dynamic Last([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] string predicate, params object[] args) #endif { Check.NotNull(source, nameof(source)); + Check.NotNull(config, nameof(config)); Check.NotEmpty(predicate, nameof(predicate)); bool createParameterCtor = SupportsLinqToObjects(config, source); @@ -842,7 +851,7 @@ public static object Last([NotNull] this IQueryable source, [NotNull] string pre public static dynamic Last([NotNull] this IQueryable source, [NotNull] string predicate, params object[] args) #endif { - return Last(source, null, predicate, args); + return Last(source, ParsingConfig.Default, predicate, args); } @@ -892,12 +901,13 @@ public static dynamic LastOrDefault([NotNull] this IQueryable source) /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. /// The first element in source that passes the test in predicate. #if NET35 - public static object LastOrDefault([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string predicate, params object[] args) + public static object LastOrDefault([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] string predicate, params object[] args) #else - public static dynamic LastOrDefault([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string predicate, params object[] args) + public static dynamic LastOrDefault([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] string predicate, params object[] args) #endif { Check.NotNull(source, nameof(source)); + Check.NotNull(config, nameof(config)); Check.NotEmpty(predicate, nameof(predicate)); bool createParameterCtor = SupportsLinqToObjects(config, source); @@ -913,7 +923,7 @@ public static object LastOrDefault([NotNull] this IQueryable source, [NotNull] s public static dynamic LastOrDefault([NotNull] this IQueryable source, [NotNull] string predicate, params object[] args) #endif { - return LastOrDefault(source, null, predicate, args); + return LastOrDefault(source, ParsingConfig.Default, predicate, args); } /// @@ -952,7 +962,7 @@ public static dynamic LastOrDefault([NotNull] this IQueryable source, [NotNull] /// ]]> /// /// - public static IOrderedQueryable OrderBy([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string ordering, params object[] args) + public static IOrderedQueryable OrderBy([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] string ordering, params object[] args) { return (IOrderedQueryable)OrderBy((IQueryable)source, config, ordering, args); } @@ -960,7 +970,7 @@ public static IOrderedQueryable OrderBy([NotNull] this IQuerya /// public static IOrderedQueryable OrderBy([NotNull] this IQueryable source, [NotNull] string ordering, params object[] args) { - return OrderBy(source, null, ordering, args); + return OrderBy(source, ParsingConfig.Default, ordering, args); } /// @@ -978,9 +988,10 @@ public static IOrderedQueryable OrderBy([NotNull] this IQuerya /// var resultMultiple = queryable.OrderBy("NumberProperty, StringProperty DESC"); /// /// - public static IOrderedQueryable OrderBy([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string ordering, params object[] args) + public static IOrderedQueryable OrderBy([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] string ordering, params object[] args) { Check.NotNull(source, nameof(source)); + Check.NotNull(config, nameof(config)); Check.NotEmpty(ordering, nameof(ordering)); ParameterExpression[] parameters = { ParameterExpressionHelper.CreateParameterExpression(source.ElementType, string.Empty) }; @@ -1004,7 +1015,7 @@ public static IOrderedQueryable OrderBy([NotNull] this IQueryable source, [CanBe /// public static IOrderedQueryable OrderBy([NotNull] this IQueryable source, [NotNull] string ordering, params object[] args) { - return OrderBy(source, null, ordering, args); + return OrderBy(source, ParsingConfig.Default, ordering, args); } #endregion OrderBy @@ -1126,9 +1137,10 @@ public static IQueryable Reverse([NotNull] this IQueryable source) /// var dynamicObject = queryable.Select("new (StringProperty1, StringProperty2 as OtherStringPropertyName)"); /// /// - public static IQueryable Select([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string selector, params object[] args) + public static IQueryable Select([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] string selector, params object[] args) { Check.NotNull(source, nameof(source)); + Check.NotNull(config, nameof(config)); Check.NotEmpty(selector, nameof(selector)); bool createParameterCtor = config?.EvaluateGroupByAtDatabase ?? SupportsLinqToObjects(config, source); @@ -1146,7 +1158,7 @@ public static IQueryable Select([NotNull] this IQueryable source, [CanBeNull] Pa /// public static IQueryable Select([NotNull] this IQueryable source, [NotNull] string selector, params object[] args) { - return Select(source, (ParsingConfig)null, selector, args); + return Select(source, ParsingConfig.Default, selector, args); } /// @@ -1166,9 +1178,10 @@ public static IQueryable Select([NotNull] this IQueryable source, [NotNull] stri /// ]]> /// /// - public static IQueryable Select([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string selector, params object[] args) + public static IQueryable Select([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] string selector, params object[] args) { Check.NotNull(source, nameof(source)); + Check.NotNull(config, nameof(config)); Check.NotEmpty(selector, nameof(selector)); bool createParameterCtor = config?.EvaluateGroupByAtDatabase ?? SupportsLinqToObjects(config, source); @@ -1185,7 +1198,7 @@ public static IQueryable Select([NotNull] this IQueryable sour /// public static IQueryable Select([NotNull] this IQueryable source, [NotNull] string selector, params object[] args) { - return Select(source, null, selector, args); + return Select(source, ParsingConfig.Default, selector, args); } /// @@ -1203,9 +1216,10 @@ public static IQueryable Select([NotNull] this IQueryable sour /// var users = queryable.Select(typeof(User), "new (Username, Pwd as Password)"); /// /// - public static IQueryable Select([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] Type resultType, [NotNull] string selector, params object[] args) + public static IQueryable Select([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] Type resultType, [NotNull] string selector, params object[] args) { Check.NotNull(source, nameof(source)); + Check.NotNull(config, nameof(config)); Check.NotNull(resultType, nameof(resultType)); Check.NotEmpty(selector, nameof(selector)); @@ -1223,7 +1237,7 @@ public static IQueryable Select([NotNull] this IQueryable source, [CanBeNull] Pa /// public static IQueryable Select([NotNull] this IQueryable source, [NotNull] Type resultType, [NotNull] string selector, params object[] args) { - return Select(source, null, resultType, selector, args); + return Select(source, ParsingConfig.Default, resultType, selector, args); } #endregion Select @@ -1242,18 +1256,15 @@ public static IQueryable Select([NotNull] this IQueryable source, [NotNull] Type /// var roles = users.SelectMany("Roles"); /// /// - public static IQueryable SelectMany([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string selector, params object[] args) + public static IQueryable SelectMany([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] string selector, params object[] args) { - Check.NotNull(source, nameof(source)); - Check.NotEmpty(selector, nameof(selector)); - return SelectManyInternal(source, config, null, selector, args); } /// public static IQueryable SelectMany([NotNull] this IQueryable source, [NotNull] string selector, params object[] args) { - return SelectMany(source, (ParsingConfig)null, selector, args); + return SelectMany(source, ParsingConfig.Default, selector, args); } /// @@ -1270,9 +1281,10 @@ public static IQueryable SelectMany([NotNull] this IQueryable source, [NotNull] /// var permissions = users.SelectMany(typeof(Permission), "Roles.SelectMany(Permissions)"); /// /// - public static IQueryable SelectMany([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] Type resultType, [NotNull] string selector, params object[] args) + public static IQueryable SelectMany([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] Type resultType, [NotNull] string selector, params object[] args) { Check.NotNull(source, nameof(source)); + Check.NotNull(config, nameof(config)); Check.NotNull(resultType, nameof(resultType)); Check.NotEmpty(selector, nameof(selector)); @@ -1282,7 +1294,7 @@ public static IQueryable SelectMany([NotNull] this IQueryable source, [CanBeNull /// public static IQueryable SelectMany([NotNull] this IQueryable source, [NotNull] Type resultType, [NotNull] string selector, params object[] args) { - return SelectMany(source, null, resultType, selector, args); + return SelectMany(source, ParsingConfig.Default, resultType, selector, args); } private static IQueryable SelectManyInternal(IQueryable source, ParsingConfig config, Type resultType, string selector, params object[] args) @@ -1339,9 +1351,10 @@ private static IQueryable SelectManyInternal(IQueryable source, ParsingConfig co /// ]]> /// /// - public static IQueryable SelectMany([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string selector, params object[] args) + public static IQueryable SelectMany([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] string selector, params object[] args) { Check.NotNull(source, nameof(source)); + Check.NotNull(config, nameof(config)); Check.NotEmpty(selector, nameof(selector)); bool createParameterCtor = config?.EvaluateGroupByAtDatabase ?? SupportsLinqToObjects(config, source); @@ -1365,7 +1378,7 @@ public static IQueryable SelectMany([NotNull] this IQueryable /// public static IQueryable SelectMany([NotNull] this IQueryable source, [NotNull] string selector, params object[] args) { - return SelectMany(source, null, selector, args); + return SelectMany(source, ParsingConfig.Default, selector, args); } /// @@ -1392,7 +1405,7 @@ public static IQueryable SelectMany([NotNull] this IQueryable /// ]]> /// /// - public static IQueryable SelectMany([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string collectionSelector, [NotNull] string resultSelector, [CanBeNull] object[] collectionSelectorArgs = null, [CanBeNull] params object[] resultSelectorArgs) + public static IQueryable SelectMany([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] string collectionSelector, [NotNull] string resultSelector, [CanBeNull] object[] collectionSelectorArgs = null, [CanBeNull] params object[] resultSelectorArgs) { return SelectMany(source, collectionSelector, resultSelector, "x", "y", collectionSelectorArgs, resultSelectorArgs); } @@ -1400,7 +1413,7 @@ public static IQueryable SelectMany([NotNull] this IQueryable source, [CanBeNull /// public static IQueryable SelectMany([NotNull] this IQueryable source, [NotNull] string collectionSelector, [NotNull] string resultSelector, [CanBeNull] object[] collectionSelectorArgs = null, [CanBeNull] params object[] resultSelectorArgs) { - return SelectMany(source, null, collectionSelector, resultSelector, "x", "y", collectionSelectorArgs, resultSelectorArgs); + return SelectMany(source, ParsingConfig.Default, collectionSelector, resultSelector, "x", "y", collectionSelectorArgs, resultSelectorArgs); } /// @@ -1429,9 +1442,10 @@ public static IQueryable SelectMany([NotNull] this IQueryable source, [NotNull] /// ]]> /// /// - public static IQueryable SelectMany([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string collectionSelector, [NotNull] string resultSelector, [NotNull] string collectionParameterName, [NotNull] string resultParameterName, [CanBeNull] object[] collectionSelectorArgs = null, [CanBeNull] params object[] resultSelectorArgs) + public static IQueryable SelectMany([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] string collectionSelector, [NotNull] string resultSelector, [NotNull] string collectionParameterName, [NotNull] string resultParameterName, [CanBeNull] object[] collectionSelectorArgs = null, [CanBeNull] params object[] resultSelectorArgs) { Check.NotNull(source, nameof(source)); + Check.NotNull(config, nameof(config)); Check.NotEmpty(collectionSelector, nameof(collectionSelector)); Check.NotEmpty(collectionParameterName, nameof(collectionParameterName)); Check.NotEmpty(resultSelector, nameof(resultSelector)); @@ -1467,7 +1481,7 @@ public static IQueryable SelectMany([NotNull] this IQueryable source, [CanBeNull /// public static IQueryable SelectMany([NotNull] this IQueryable source, [NotNull] string collectionSelector, [NotNull] string resultSelector, [NotNull] string collectionParameterName, [NotNull] string resultParameterName, [CanBeNull] object[] collectionSelectorArgs = null, [CanBeNull] params object[] resultSelectorArgs) { - return SelectMany(source, null, collectionSelector, resultSelector, collectionParameterName, resultParameterName, collectionSelectorArgs, resultSelectorArgs); + return SelectMany(source, ParsingConfig.Default, collectionSelector, resultSelector, collectionParameterName, resultParameterName, collectionSelectorArgs, resultSelectorArgs); } #endregion SelectMany @@ -1503,12 +1517,13 @@ public static dynamic Single([NotNull] this IQueryable source) /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. /// The first element in source that passes the test in predicate. #if NET35 - public static object Single([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string predicate, params object[] args) + public static object Single([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] string predicate, params object[] args) #else - public static dynamic Single([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string predicate, params object[] args) + public static dynamic Single([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] string predicate, params object[] args) #endif { Check.NotNull(source, nameof(source)); + Check.NotNull(config, nameof(config)); Check.NotEmpty(predicate, nameof(predicate)); bool createParameterCtor = SupportsLinqToObjects(config, source); @@ -1524,7 +1539,7 @@ public static object Single([NotNull] this IQueryable source, [NotNull] string p public static dynamic Single([NotNull] this IQueryable source, [NotNull] string predicate, params object[] args) #endif { - return Single(source, null, predicate, args); + return Single(source, ParsingConfig.Default, predicate, args); } /// @@ -1575,12 +1590,13 @@ public static dynamic SingleOrDefault([NotNull] this IQueryable source) /// An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings. /// The first element in source that passes the test in predicate. #if NET35 - public static object SingleOrDefault([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string predicate, params object[] args) + public static object SingleOrDefault([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] string predicate, params object[] args) #else - public static dynamic SingleOrDefault([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string predicate, params object[] args) + public static dynamic SingleOrDefault([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] string predicate, params object[] args) #endif { Check.NotNull(source, nameof(source)); + Check.NotNull(config, nameof(config)); Check.NotEmpty(predicate, nameof(predicate)); bool createParameterCtor = SupportsLinqToObjects(config, source); @@ -1596,7 +1612,7 @@ public static object SingleOrDefault([NotNull] this IQueryable source, [NotNull] public static dynamic SingleOrDefault([NotNull] this IQueryable source, [NotNull] string predicate, params object[] args) #endif { - return SingleOrDefault(source, null, predicate, args); + return SingleOrDefault(source, ParsingConfig.Default, predicate, args); } /// @@ -1613,6 +1629,8 @@ public static dynamic SingleOrDefault([NotNull] this IQueryable source, [NotNull #endif { Check.NotNull(source, nameof(source)); + Check.NotNull(lambda, nameof(lambda)); + return Execute(_singleDefaultPredicate, source, lambda); } #endregion Single/SingleOrDefault @@ -1665,9 +1683,10 @@ public static IQueryable Skip([NotNull] this IQueryable source, int count) /// /// /// An that contains elements from source starting at the first element in the linear series that does not pass the test specified by predicate. - public static IQueryable SkipWhile([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string predicate, [CanBeNull] params object[] args) + public static IQueryable SkipWhile([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] string predicate, [CanBeNull] params object[] args) { Check.NotNull(source, nameof(source)); + Check.NotNull(config, nameof(config)); Check.NotNull(predicate, nameof(predicate)); bool createParameterCtor = SupportsLinqToObjects(config, source); @@ -1679,7 +1698,7 @@ public static IQueryable SkipWhile([NotNull] this IQueryable source, [CanBeNull] /// public static IQueryable SkipWhile([NotNull] this IQueryable source, [NotNull] string predicate, [CanBeNull] params object[] args) { - return SkipWhile(source, null, predicate, args); + return SkipWhile(source, ParsingConfig.Default, predicate, args); } #endregion SkipWhile @@ -1742,9 +1761,10 @@ public static IQueryable Take([NotNull] this IQueryable source, int count) /// /// /// An that contains elements from the input sequence occurring before the element at which the test specified by predicate no longer passes. - public static IQueryable TakeWhile([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string predicate, [CanBeNull] params object[] args) + public static IQueryable TakeWhile([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] string predicate, [CanBeNull] params object[] args) { Check.NotNull(source, nameof(source)); + Check.NotNull(config, nameof(config)); Check.NotNull(predicate, nameof(predicate)); bool createParameterCtor = SupportsLinqToObjects(config, source); @@ -1756,7 +1776,7 @@ public static IQueryable TakeWhile([NotNull] this IQueryable source, [CanBeNull] /// public static IQueryable TakeWhile([NotNull] this IQueryable source, [NotNull] string predicate, [CanBeNull] params object[] args) { - return TakeWhile(source, null, predicate, args); + return TakeWhile(source, ParsingConfig.Default, predicate, args); } #endregion TakeWhile @@ -1781,7 +1801,7 @@ public static IQueryable TakeWhile([NotNull] this IQueryable source, [NotNull] s /// ]]> /// /// - public static IOrderedQueryable ThenBy([NotNull] this IOrderedQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string ordering, params object[] args) + public static IOrderedQueryable ThenBy([NotNull] this IOrderedQueryable source, [NotNull] ParsingConfig config, [NotNull] string ordering, params object[] args) { return (IOrderedQueryable)ThenBy((IOrderedQueryable)source, config, ordering, args); } @@ -1789,7 +1809,7 @@ public static IOrderedQueryable ThenBy([NotNull] this IOrdered /// public static IOrderedQueryable ThenBy([NotNull] this IOrderedQueryable source, [NotNull] string ordering, params object[] args) { - return ThenBy(source, null, ordering, args); + return ThenBy(source, ParsingConfig.Default, ordering, args); } /// /// Performs a subsequent ordering of the elements in a sequence in ascending order according to a key. @@ -1807,9 +1827,10 @@ public static IOrderedQueryable ThenBy([NotNull] this IOrdered /// var resultMultiple = result.OrderBy("NumberProperty, StringProperty DESC"); /// /// - public static IOrderedQueryable ThenBy([NotNull] this IOrderedQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string ordering, params object[] args) + public static IOrderedQueryable ThenBy([NotNull] this IOrderedQueryable source, [NotNull] ParsingConfig config, [NotNull] string ordering, params object[] args) { Check.NotNull(source, nameof(source)); + Check.NotNull(config, nameof(config)); Check.NotEmpty(ordering, nameof(ordering)); ParameterExpression[] parameters = { ParameterExpressionHelper.CreateParameterExpression(source.ElementType, string.Empty) }; @@ -1833,7 +1854,7 @@ public static IOrderedQueryable ThenBy([NotNull] this IOrderedQueryable source, /// public static IOrderedQueryable ThenBy([NotNull] this IOrderedQueryable source, [NotNull] string ordering, params object[] args) { - return ThenBy(source, null, ordering, args); + return ThenBy(source, ParsingConfig.Default, ordering, args); } #endregion OrderBy @@ -1857,18 +1878,15 @@ public static IOrderedQueryable ThenBy([NotNull] this IOrderedQueryable source, /// var result5 = queryable.Where("StringProperty = @0", "abc"); /// /// - public static IQueryable Where([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string predicate, params object[] args) + public static IQueryable Where([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] string predicate, params object[] args) { - Check.NotNull(source, nameof(source)); - Check.NotEmpty(predicate, nameof(predicate)); - return (IQueryable)Where((IQueryable)source, config, predicate, args); } /// public static IQueryable Where([NotNull] this IQueryable source, [NotNull] string predicate, params object[] args) { - return Where(source, null, predicate, args); + return Where(source, ParsingConfig.Default, predicate, args); } /// @@ -1888,9 +1906,10 @@ public static IQueryable Where([NotNull] this IQueryable /// - public static IQueryable Where([NotNull] this IQueryable source, [CanBeNull] ParsingConfig config, [NotNull] string predicate, params object[] args) + public static IQueryable Where([NotNull] this IQueryable source, [NotNull] ParsingConfig config, [NotNull] string predicate, params object[] args) { Check.NotNull(source, nameof(source)); + Check.NotNull(config, nameof(config)); Check.NotEmpty(predicate, nameof(predicate)); bool createParameterCtor = SupportsLinqToObjects(config, source); @@ -1903,7 +1922,7 @@ public static IQueryable Where([NotNull] this IQueryable source, [CanBeNull] Par /// public static IQueryable Where([NotNull] this IQueryable source, [NotNull] string predicate, params object[] args) { - return Where(source, null, predicate, args); + return Where(source, ParsingConfig.Default, predicate, args); } /// @@ -1926,7 +1945,7 @@ public static IQueryable Where([NotNull] this IQueryable source, [NotNull] Lambd private static bool SupportsLinqToObjects(ParsingConfig config, IQueryable query) { - return (config ?? ParsingConfig.Default).QueryableAnalyzer.SupportsLinqToObjects(query); + return config.QueryableAnalyzer.SupportsLinqToObjects(query); } private static void CheckOuterAndInnerTypes(ParsingConfig config, bool createParameterCtor, Type outerType, Type innerType, string outerKeySelector, string innerKeySelector, ref LambdaExpression outerSelectorLambda, ref LambdaExpression innerSelectorLambda, params object[] args) diff --git a/test/System.Linq.Dynamic.Core.Tests/DynamicExpressionParserTests.cs b/test/System.Linq.Dynamic.Core.Tests/DynamicExpressionParserTests.cs index 64a970d9..52bb3f6d 100644 --- a/test/System.Linq.Dynamic.Core.Tests/DynamicExpressionParserTests.cs +++ b/test/System.Linq.Dynamic.Core.Tests/DynamicExpressionParserTests.cs @@ -129,7 +129,9 @@ public void DynamicExpressionParser_ParseLambda_UseParameterizedNamesInDynamicQu // Assert dynamic constantExpression = ((MemberExpression)(expression.Body as BinaryExpression).Right).Expression as ConstantExpression; dynamic wrappedObj = constantExpression.Value; - string value = wrappedObj.Value; + + var propertyInfo = wrappedObj.GetType().GetProperty("Value", BindingFlags.Instance | BindingFlags.Public); + string value = propertyInfo.GetValue(wrappedObj) as string; Check.That(value).IsEqualTo("x"); } diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Count.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Count.cs index 18a07fa9..f8a817ad 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Count.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Count.cs @@ -11,8 +11,8 @@ public void Entities_Count_Predicate() const string search = "a"; //Arrange - var blog1 = new Blog { Name = "blog a", BlogId = 1000 }; - var blog2 = new Blog { Name = "blog b", BlogId = 3000 }; + var blog1 = new Blog { Name = "blog a", BlogId = 1000, Created = DateTime.Now }; + var blog2 = new Blog { Name = "blog b", BlogId = 3000, Created = DateTime.Now }; _context.Blogs.Add(blog1); _context.Blogs.Add(blog2); _context.SaveChanges(); diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.CountAsync.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.CountAsync.cs index dff176e6..1d055b5f 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.CountAsync.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.CountAsync.cs @@ -20,8 +20,8 @@ public async Task Entities_CountAsync_Predicate_Args() const string search = "a"; //Arrange - var blog1 = new Blog { Name = "blog a", BlogId = 1000 }; - var blog2 = new Blog { Name = "blog b", BlogId = 3000 }; + var blog1 = new Blog { Name = "blog a", BlogId = 1000, Created = DateTime.Now }; + var blog2 = new Blog { Name = "blog b", BlogId = 3000, Created = DateTime.Now }; _context.Blogs.Add(blog1); _context.Blogs.Add(blog2); _context.SaveChanges(); diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Select.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Select.cs index e443f858..ac45d263 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Select.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Select.cs @@ -1,7 +1,7 @@ using System.Collections; using System.Linq.Dynamic.Core.Exceptions; using System.Linq.Dynamic.Core.Tests.Helpers.Entities; -using MongoDB.Bson; +using Newtonsoft.Json; #if EFCORE using Microsoft.EntityFrameworkCore; #else @@ -16,9 +16,9 @@ public partial class EntitiesTests : IDisposable [Fact] public void Entities_Select_SingleColumn_NullCoalescing() { - //Arrange - var blog1 = new Blog { BlogId = 1000, Name = "Blog1", NullableInt = null }; - var blog2 = new Blog { BlogId = 2000, Name = "Blog2", NullableInt = 5 }; + //A rrange + var blog1 = new Blog { BlogId = 1000, Name = "Blog1", Created = DateTime.Now, NullableInt = null }; + var blog2 = new Blog { BlogId = 2000, Name = "Blog2", Created = DateTime.Now, NullableInt = 5 }; _context.Blogs.Add(blog1); _context.Blogs.Add(blog2); _context.SaveChanges(); @@ -26,11 +26,11 @@ public void Entities_Select_SingleColumn_NullCoalescing() var expected1 = _context.Blogs.Select(x => (int?)(x.NullableInt ?? 10)).ToArray(); var expected2 = _context.Blogs.Select(x => (int?)(x.NullableInt ?? 9 + x.BlogId)).ToArray(); - //Act + // Act var test1 = _context.Blogs.Select("NullableInt ?? 10").ToArray(); var test2 = _context.Blogs.Select("NullableInt ?? 9 + BlogId").ToArray(); - //Assert + // Assert Assert.Equal(expected1, test1); Assert.Equal(expected2, test2); } @@ -56,16 +56,16 @@ public void Entities_Select_EmptyObject() ParsingConfig config = ParsingConfig.Default; config.EvaluateGroupByAtDatabase = true; - //Arrange + // Arrange PopulateTestData(5, 0); var expected = _context.Blogs.Select(x => new {}).ToList(); - //Act + // Act var test = _context.Blogs.GroupBy(config, "BlogId", "new()").Select("new()").ToList(); - //Assert - Assert.Equal(expected.ToJson(), test.ToJson()); + // Assert + Assert.Equal(JsonConvert.SerializeObject(expected), JsonConvert.SerializeObject(test)); } [Fact] diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.cs index 379935cf..6e25c199 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.cs @@ -52,7 +52,7 @@ private void PopulateTestData(int blogCount = 25, int postCount = 10) { for (int i = 0; i < blogCount; i++) { - var blog = new Blog { Name = "Blog" + (i + 1), BlogId = 1000 + i }; + var blog = new Blog { Name = "Blog" + (i + 1), BlogId = 1000 + i, Created = DateTime.Now.AddDays(-Rnd.Next(0, 100)) }; _context.Blogs.Add(blog); diff --git a/test/System.Linq.Dynamic.Core.Tests/ExpressionTests.cs b/test/System.Linq.Dynamic.Core.Tests/ExpressionTests.cs index 255f8135..ba94a7a9 100644 --- a/test/System.Linq.Dynamic.Core.Tests/ExpressionTests.cs +++ b/test/System.Linq.Dynamic.Core.Tests/ExpressionTests.cs @@ -8,7 +8,6 @@ using Newtonsoft.Json.Linq; using Xunit; using NFluent; -using MongoDB.Bson; namespace System.Linq.Dynamic.Core.Tests { @@ -44,7 +43,7 @@ public class TestObjectIdClass { public int Id { get; set; } - public ObjectId ObjectId { get; set; } + public long ObjectId { get; set; } } [Fact] @@ -996,50 +995,50 @@ public void ExpressionTests_Indexer_Issue57() Assert.Equal(expected, result); } - [Fact] - public void ExpressionTests_IComparable_GreaterThan() - { - // Assign - const string id = "111111111111111111111111"; - var queryable = new[] { new TestObjectIdClass { Id = 1, ObjectId = ObjectId.Parse(id) }, new TestObjectIdClass { Id = 2, ObjectId = ObjectId.Parse("221111111111111111111111") } }.AsQueryable(); - - // Act - var result = queryable.Where(x => x.ObjectId > ObjectId.Parse(id)).ToArray(); - var dynamicResult = queryable.Where("it.ObjectId > @0", ObjectId.Parse(id)).ToArray(); + // [Fact] + // public void ExpressionTests_IComparable_GreaterThan() + // { + // // Assign + // const string id = "111111111111111111111111"; + // var queryable = new[] { new TestObjectIdClass { Id = 1, ObjectId = id }, new TestObjectIdClass { Id = 2, ObjectId = "221111111111111111111111" } }.AsQueryable(); - // Assert - Check.That(dynamicResult).ContainsExactly(result); - } + // // Act + // var result = queryable.Where(x => x.ObjectId > id).ToArray(); + // var dynamicResult = queryable.Where("it.ObjectId > @0", id).ToArray(); - [Fact] - public void ExpressionTests_IEquatable_Equal() - { - // Assign - const string id = "111111111111111111111111"; - var queryable = new[] { new TestObjectIdClass { Id = 1, ObjectId = ObjectId.Parse(id) }, new TestObjectIdClass { Id = 2, ObjectId = ObjectId.Parse("221111111111111111111111") } }.AsQueryable(); + // // Assert + // Check.That(dynamicResult).ContainsExactly(result); + // } - // Act - var result = queryable.First(x => x.ObjectId == ObjectId.Parse(id)); - var dynamicResult = queryable.First("it.ObjectId == @0", ObjectId.Parse(id)); + // [Fact] + // public void ExpressionTests_IEquatable_Equal() + // { + // // Assign + // const string id = "111111111111111111111111"; + // var queryable = new[] { new TestObjectIdClass { Id = 1, ObjectId = id }, new TestObjectIdClass { Id = 2, ObjectId = ObjectId.Parse("221111111111111111111111") } }.AsQueryable(); - // Assert - Check.That(dynamicResult.Id).Equals(result.Id); - } + // // Act + // var result = queryable.First(x => x.ObjectId == ObjectId.Parse(id)); + // var dynamicResult = queryable.First("it.ObjectId == @0", ObjectId.Parse(id)); - [Fact] - public void ExpressionTests_IEquatable_NotEqual() - { - // Assign - const string id = "111111111111111111111111"; - var queryable = new[] { new TestObjectIdClass { Id = 1, ObjectId = ObjectId.Parse(id) }, new TestObjectIdClass { Id = 2, ObjectId = ObjectId.Parse("221111111111111111111111") } }.AsQueryable(); + // // Assert + // Check.That(dynamicResult.Id).Equals(result.Id); + // } - // Act - var result = queryable.First(x => x.ObjectId != ObjectId.Parse(id)); - var dynamicResult = queryable.First("it.ObjectId != @0", ObjectId.Parse(id)); - - // Assert - Check.That(dynamicResult.Id).Equals(result.Id); - } + // [Fact] + // public void ExpressionTests_IEquatable_NotEqual() + // { + // // Assign + // const string id = "111111111111111111111111"; + // var queryable = new[] { new TestObjectIdClass { Id = 1, ObjectId = ObjectId.Parse(id) }, new TestObjectIdClass { Id = 2, ObjectId = ObjectId.Parse("221111111111111111111111") } }.AsQueryable(); + + // // Act + // var result = queryable.First(x => x.ObjectId != ObjectId.Parse(id)); + // var dynamicResult = queryable.First("it.ObjectId != @0", ObjectId.Parse(id)); + + // // Assert + // Check.That(dynamicResult.Id).Equals(result.Id); + // } [Fact] public void ExpressionTests_LogicalAndOr() diff --git a/test/System.Linq.Dynamic.Core.Tests/QueryableTests.Cast.cs b/test/System.Linq.Dynamic.Core.Tests/QueryableTests.Cast.cs index 0f7467b3..aaec6ee1 100644 --- a/test/System.Linq.Dynamic.Core.Tests/QueryableTests.Cast.cs +++ b/test/System.Linq.Dynamic.Core.Tests/QueryableTests.Cast.cs @@ -14,26 +14,33 @@ public void Cast_Explicit() { { "Id", new JValue(9) }, { "Name", new JValue("Test 9") }, - { "Items", new JArray(new JValue(1), new JValue("two")) } + { "Items", new JArray(new JValue(1), new JValue("one")) } }; var test2 = new JObject { { "Id", new JValue(10) }, { "Name", new JValue("Test 10") }, - { "Items", new JArray(new JValue(1), new JValue("two")) } + { "Items", new JArray(new JValue(2), new JValue("two")) } }; var queryable = new[] { test1, test2 }.AsQueryable(); // Act - var result = queryable.Select(x => new { Id = (int)x["Id"], Name = (string)x["Name"] }).OrderBy(x => x.Id).ToArray(); + var result = queryable.Select(x => new { Id = (int)x["Id"], Name = (string)x["Name"], Item0 = (int) x["Items"].Values().ToArray()[0], Item1 = (string)x["Items"].Values().ToArray()[1] }).OrderBy(x => x.Id).ToArray(); var resultDynamic = queryable.Select("new (int(Id) as Id, string(Name) as Name, int(Items[0]) as Item0, string(Items[1]) as Item1)").OrderBy("Id").ToDynamicArray(); // Assert Check.That(resultDynamic.Count()).Equals(result.Count()); Check.That(resultDynamic[0].Id).Equals(result[0].Id); Check.That(resultDynamic[0].Name).Equals(result[0].Name); + Check.That(resultDynamic[0].Item0).Equals(result[0].Item0); + Check.That(resultDynamic[0].Item1).Equals(result[0].Item1); + + Check.That(resultDynamic[1].Id).Equals(result[1].Id); + Check.That(resultDynamic[1].Name).Equals(result[1].Name); + Check.That(resultDynamic[1].Item0).Equals(result[1].Item0); + Check.That(resultDynamic[1].Item1).Equals(result[1].Item1); } } } diff --git a/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj b/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj index f60a8266..22101e05 100644 --- a/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj +++ b/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj @@ -5,8 +5,7 @@ System.Linq.Dynamic.Core.Tests full True - System.Linq.Dynamic.Core.snk - False + ../../src/System.Linq.Dynamic.Core/System.Linq.Dynamic.Core.snk {912FBF24-3CAE-4A50-B5EA-E525B9FAEC80} @@ -21,20 +20,19 @@ runtime; build; native; contentfiles; analyzers - - + all runtime; build; native; contentfiles; analyzers - + all runtime; build; native; contentfiles; analyzers - - + + diff --git a/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.snk b/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.snk deleted file mode 100644 index 28cd4489..00000000 Binary files a/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.snk and /dev/null differ