Skip to content

Commit fa1b6f2

Browse files
OlegNadymovStefH
authored andcommitted
Fix for ParseLambda with itType and resultType: correct order of arguments (#193)
* Fix for ParseLambda with itType and resultType: correct order of arguments * Add references for missing classes * Fix for missing classes: UserState and UserProfileDetails * Small update on unit-test (no need to check for `DoesNotThrow`) * add comment to appveyor * Only run SonarScanner on master branch * APPVEYOR_REPO_BRANCH * APPVEYOR_PULL_REQUEST_NUMBER
1 parent f1cfbe2 commit fa1b6f2

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

appveyor.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@ install:
1919

2020
environment:
2121
PATH: $(PATH);$(PROGRAMFILES)\dotnet\
22+
23+
# https://www.appveyor.com/docs/build-configuration/#secure-variables
24+
# 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.
2225
COVERALLS_REPO_TOKEN:
2326
secure: tsTABRbCmdWFLT194XNIrpurerOfjN6cEoxt2RaSUfLmUIgra/+CwuqVkv0sPRop
2427
SONAR_TOKEN:
2528
secure: guog1+ttdnlD8sVgvizlewksm3qbO7dy2oZUcR8WhurWYvdOByinxXo732hmSaMT
2629

30+
2731
before_build:
2832
# Remove UAP10 and netstandard20 from csproj
2933
#- 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:
3943

4044
build_script:
4145
# Begin SonarScanner
42-
- 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"
46+
- 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\"" }
4347

4448
# Build Code
4549
- dotnet build src\EntityFramework.DynamicLinq\EntityFramework.DynamicLinq.csproj -c %CONFIGURATION%
@@ -59,7 +63,7 @@ test_script:
5963
- 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'
6064
- codecov -f "coverage.xml"
6165
- coveralls.net\tools\csmacnz.Coveralls.exe --opencover -i .\coverage.xml
62-
- dotnet sonarscanner end /d:sonar.login="%SONAR_TOKEN%"
66+
- ps: if (-Not $env:APPVEYOR_PULL_REQUEST_NUMBER) { & "dotnet sonarscanner end /d:sonar.login=\"%SONAR_TOKEN%\"" }
6367

6468
# Run tests for EntityFramework.DynamicLinq
6569
- dotnet test -c %CONFIGURATION% --no-build test\EntityFramework.DynamicLinq.Tests\EntityFramework.DynamicLinq.Tests.csproj

src-console/System.Linq.Dynamic.Core.ConsoleTestApp.net40/ConsoleApp_net40_sqlite_original.csproj

+6
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@
9797
<Compile Include="..\..\test\System.Linq.Dynamic.Core.Tests\Helpers\TestEnum.cs">
9898
<Link>Helpers\TestEnum.cs</Link>
9999
</Compile>
100+
<Compile Include="..\..\test\System.Linq.Dynamic.Core.Tests\Helpers\Models\UserProfileDetails.cs">
101+
<Link>Helpers\Models\UserProfileDetails.cs</Link>
102+
</Compile>
103+
<Compile Include="..\..\test\System.Linq.Dynamic.Core.Tests\Helpers\Models\UserState.cs">
104+
<Link>Helpers\Models\UserState.cs</Link>
105+
</Compile>
100106
<Compile Include="Program.cs" />
101107
<Compile Include="Properties\AssemblyInfo.cs" />
102108
</ItemGroup>

src/System.Linq.Dynamic.Core/DynamicExpressionParser.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public static LambdaExpression ParseLambda([NotNull] Type itType, [CanBeNull] Ty
173173
[PublicAPI]
174174
public static LambdaExpression ParseLambda([CanBeNull] ParsingConfig parsingConfig, [NotNull] Type itType, [CanBeNull] Type resultType, string expression, params object[] values)
175175
{
176-
return ParseLambda(true, itType, resultType, expression, parsingConfig, values);
176+
return ParseLambda(parsingConfig, true, itType, resultType, expression, values);
177177
}
178178

179179
/// <summary>

test/System.Linq.Dynamic.Core.Tests/DynamicExpressionParserTests.cs

+27
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public class ComplexParseLambda3Result
3232
public int TotalIncome { get; set; }
3333
}
3434

35+
public class CustomClassWithStaticMethod
36+
{
37+
public static int GetAge(int x) => x;
38+
}
39+
3540
private class TestCustomTypeProvider : AbstractDynamicLinqCustomTypeProvider, IDynamicLinkCustomTypeProvider
3641
{
3742
private HashSet<Type> _customTypes;
@@ -44,6 +49,7 @@ public virtual HashSet<Type> GetCustomTypes()
4449
}
4550

4651
_customTypes = new HashSet<Type>(FindTypesMarkedWithDynamicLinqTypeAttribute(new[] { GetType().GetTypeInfo().Assembly }));
52+
_customTypes.Add(typeof(CustomClassWithStaticMethod));
4753
return _customTypes;
4854
}
4955
}
@@ -413,5 +419,26 @@ public void ParseLambda_IllegalMethodCall_ThrowsException()
413419
})
414420
.Throws<ParseException>().WithMessage("Methods on type 'Stream' are not accessible");
415421
}
422+
423+
[Fact]
424+
public void ParseLambda_CustomMethod()
425+
{
426+
// Assign
427+
var config = new ParsingConfig
428+
{
429+
CustomTypeProvider = new TestCustomTypeProvider()
430+
};
431+
432+
var context = new CustomClassWithStaticMethod();
433+
string expression = $"{nameof(CustomClassWithStaticMethod)}.{nameof(CustomClassWithStaticMethod.GetAge)}(10)";
434+
435+
// Act
436+
var lambdaExpression = DynamicExpressionParser.ParseLambda(config, typeof(CustomClassWithStaticMethod), null, expression);
437+
Delegate del = lambdaExpression.Compile();
438+
int result = (int)del.DynamicInvoke(context);
439+
440+
// Assert
441+
Check.That(result).IsEqualTo(10);
442+
}
416443
}
417444
}

0 commit comments

Comments
 (0)