diff --git a/appveyor.yml b/appveyor.yml index b21afa23..c5efbec4 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -19,11 +19,15 @@ install: environment: PATH: $(PATH);$(PROGRAMFILES)\dotnet\ + + # https://www.appveyor.com/docs/build-configuration/#secure-variables + # However, secure variables are not decoded during Pull Request builds which prevents someone from submitting PR with malicious build script displaying those variables. In more controlled environment through with a trusted team and private GitHub repositories there is an option on General tab of project settings to allow secure variables for PRs. COVERALLS_REPO_TOKEN: secure: tsTABRbCmdWFLT194XNIrpurerOfjN6cEoxt2RaSUfLmUIgra/+CwuqVkv0sPRop SONAR_TOKEN: secure: guog1+ttdnlD8sVgvizlewksm3qbO7dy2oZUcR8WhurWYvdOByinxXo732hmSaMT + before_build: # Remove UAP10 and netstandard20 from csproj #- cmd: copy /Y src\System.Linq.Dynamic.Core\System.Linq.Dynamic.Core.AppVeyor.csproj src\System.Linq.Dynamic.Core\System.Linq.Dynamic.Core.csproj @@ -39,7 +43,7 @@ before_build: build_script: # Begin SonarScanner -- dotnet sonarscanner begin /k:"system.linq.dynamic.core" /d:sonar.organization="stefh-github" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.login="%SONAR_TOKEN%" /v:"%APPVEYOR_BUILD_NUMBER%" /d:sonar.cs.opencover.reportsPaths="%CD%\coverage.xml" +- ps: if (-Not $env:APPVEYOR_PULL_REQUEST_NUMBER) { & "dotnet sonarscanner begin /k:\"system.linq.dynamic.core\" /d:sonar.organization=\"stefh-github\" /d:sonar.host.url=\"https://sonarcloud.io\" /d:sonar.login=\"%SONAR_TOKEN%\" /v:\"%APPVEYOR_BUILD_NUMBER%\" /d:sonar.cs.opencover.reportsPaths=\"%CD%\coverage.xml\"" } # Build Code - dotnet build src\EntityFramework.DynamicLinq\EntityFramework.DynamicLinq.csproj -c %CONFIGURATION% @@ -59,7 +63,7 @@ test_script: - cmd: '"OpenCover\tools\OpenCover.Console.exe" -target:dotnet.exe -targetargs:"test test\System.Linq.Dynamic.Core.Tests\System.Linq.Dynamic.Core.Tests.csproj --configuration %CONFIGURATION% --framework netcoreapp1.1 --no-build" -output:coverage.xml -register:user -filter:"+[Microsoft.EntityFrameworkCore.DynamicLinq]* +[System.Linq.Dynamic.Core]* -[*Tests*]*" -nodefaultfilters -returntargetcode -oldstyle' - codecov -f "coverage.xml" - coveralls.net\tools\csmacnz.Coveralls.exe --opencover -i .\coverage.xml -- dotnet sonarscanner end /d:sonar.login="%SONAR_TOKEN%" +- ps: if (-Not $env:APPVEYOR_PULL_REQUEST_NUMBER) { & "dotnet sonarscanner end /d:sonar.login=\"%SONAR_TOKEN%\"" } # Run tests for EntityFramework.DynamicLinq - dotnet test -c %CONFIGURATION% --no-build test\EntityFramework.DynamicLinq.Tests\EntityFramework.DynamicLinq.Tests.csproj diff --git a/src-console/System.Linq.Dynamic.Core.ConsoleTestApp.net40/ConsoleApp_net40_sqlite_original.csproj b/src-console/System.Linq.Dynamic.Core.ConsoleTestApp.net40/ConsoleApp_net40_sqlite_original.csproj index c4b12873..459c5903 100644 --- a/src-console/System.Linq.Dynamic.Core.ConsoleTestApp.net40/ConsoleApp_net40_sqlite_original.csproj +++ b/src-console/System.Linq.Dynamic.Core.ConsoleTestApp.net40/ConsoleApp_net40_sqlite_original.csproj @@ -97,6 +97,12 @@ Helpers\TestEnum.cs + + Helpers\Models\UserProfileDetails.cs + + + Helpers\Models\UserState.cs + diff --git a/src/System.Linq.Dynamic.Core/DynamicExpressionParser.cs b/src/System.Linq.Dynamic.Core/DynamicExpressionParser.cs index 50ac719d..327901df 100644 --- a/src/System.Linq.Dynamic.Core/DynamicExpressionParser.cs +++ b/src/System.Linq.Dynamic.Core/DynamicExpressionParser.cs @@ -173,7 +173,7 @@ public static LambdaExpression ParseLambda([NotNull] Type itType, [CanBeNull] Ty [PublicAPI] public static LambdaExpression ParseLambda([CanBeNull] ParsingConfig parsingConfig, [NotNull] Type itType, [CanBeNull] Type resultType, string expression, params object[] values) { - return ParseLambda(true, itType, resultType, expression, parsingConfig, values); + return ParseLambda(parsingConfig, true, itType, resultType, expression, values); } /// diff --git a/test/System.Linq.Dynamic.Core.Tests/DynamicExpressionParserTests.cs b/test/System.Linq.Dynamic.Core.Tests/DynamicExpressionParserTests.cs index da600982..93b3bd76 100644 --- a/test/System.Linq.Dynamic.Core.Tests/DynamicExpressionParserTests.cs +++ b/test/System.Linq.Dynamic.Core.Tests/DynamicExpressionParserTests.cs @@ -32,6 +32,11 @@ public class ComplexParseLambda3Result public int TotalIncome { get; set; } } + public class CustomClassWithStaticMethod + { + public static int GetAge(int x) => x; + } + private class TestCustomTypeProvider : AbstractDynamicLinqCustomTypeProvider, IDynamicLinkCustomTypeProvider { private HashSet _customTypes; @@ -44,6 +49,7 @@ public virtual HashSet GetCustomTypes() } _customTypes = new HashSet(FindTypesMarkedWithDynamicLinqTypeAttribute(new[] { GetType().GetTypeInfo().Assembly })); + _customTypes.Add(typeof(CustomClassWithStaticMethod)); return _customTypes; } } @@ -413,5 +419,26 @@ public void ParseLambda_IllegalMethodCall_ThrowsException() }) .Throws().WithMessage("Methods on type 'Stream' are not accessible"); } + + [Fact] + public void ParseLambda_CustomMethod() + { + // Assign + var config = new ParsingConfig + { + CustomTypeProvider = new TestCustomTypeProvider() + }; + + var context = new CustomClassWithStaticMethod(); + string expression = $"{nameof(CustomClassWithStaticMethod)}.{nameof(CustomClassWithStaticMethod.GetAge)}(10)"; + + // Act + var lambdaExpression = DynamicExpressionParser.ParseLambda(config, typeof(CustomClassWithStaticMethod), null, expression); + Delegate del = lambdaExpression.Compile(); + int result = (int)del.DynamicInvoke(context); + + // Assert + Check.That(result).IsEqualTo(10); + } } }