From 00eb72528a2f8aa051afdeb7414b7eb36b59ff44 Mon Sep 17 00:00:00 2001 From: ivan-luxoft <75603957+ivan-luxoft@users.noreply.github.com> Date: Fri, 20 Sep 2024 11:19:11 +0300 Subject: [PATCH] add additional check for method/fetches in TestQueryable/ExpressionTreeModifier (#21) * add additional check for method/fetches in TestQueryable/ExpressionTreeModifier * up version --- .../Queryable/ExpressionTreeModifier.cs | 27 +++++++++++++------ src/__SolutionItems/CommonAssemblyInfo.cs | 6 ++--- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/Bss.Platform.NHibernate.UnitTesting/Queryable/ExpressionTreeModifier.cs b/src/Bss.Platform.NHibernate.UnitTesting/Queryable/ExpressionTreeModifier.cs index 9dda0f2..b5af6a2 100644 --- a/src/Bss.Platform.NHibernate.UnitTesting/Queryable/ExpressionTreeModifier.cs +++ b/src/Bss.Platform.NHibernate.UnitTesting/Queryable/ExpressionTreeModifier.cs @@ -27,15 +27,26 @@ protected override Expression VisitMethodCall(MethodCallExpression node) var fetchInput = AvoidFetch(node); return fetchInput.NodeType switch - { - ExpressionType.Constant => this.VisitConstant((ConstantExpression)fetchInput), - _ => fetchInput - }; + { + ExpressionType.Constant => this.VisitConstant((ConstantExpression)fetchInput), + _ => fetchInput + }; } - private static Expression AvoidFetch(MethodCallExpression node) => - IsFetchMethod(node.Method) ? AvoidFetch((node.Arguments[0] as MethodCallExpression)!) : node; + private static Expression AvoidFetch(MethodCallExpression node) + { + if (!IsFetchMethod(node.Method)) + { + return node; + } + + return node.Arguments[0] switch + { + ConstantExpression constantExpression => constantExpression, + MethodCallExpression methodCallExpression => AvoidFetch(methodCallExpression), + _ => throw new ArgumentOutOfRangeException($"Not handled case - first argument is '{node.Arguments[0].GetType().Name}'") + }; + } - private static bool IsFetchMethod(MethodInfo info) => - info.IsGenericMethod && VisitedMethods.Contains(info.GetGenericMethodDefinition()); + private static bool IsFetchMethod(MethodInfo info) => info.IsGenericMethod && VisitedMethods.Contains(info.GetGenericMethodDefinition()); } diff --git a/src/__SolutionItems/CommonAssemblyInfo.cs b/src/__SolutionItems/CommonAssemblyInfo.cs index b3992b9..358e294 100644 --- a/src/__SolutionItems/CommonAssemblyInfo.cs +++ b/src/__SolutionItems/CommonAssemblyInfo.cs @@ -4,9 +4,9 @@ [assembly: AssemblyCompany("Luxoft")] [assembly: AssemblyCopyright("Copyright © Luxoft 2024")] -[assembly: AssemblyVersion("1.5.5.0")] -[assembly: AssemblyFileVersion("1.5.5.0")] -[assembly: AssemblyInformationalVersion("1.5.5.0")] +[assembly: AssemblyVersion("1.5.6.0")] +[assembly: AssemblyFileVersion("1.5.6.0")] +[assembly: AssemblyInformationalVersion("1.5.6.0")] #if DEBUG [assembly: AssemblyConfiguration("Debug")]