Skip to content

Commit dab5582

Browse files
VS-156: Support Strong Named 2.28 Driver (#84)
1 parent bb4601a commit dab5582

File tree

8 files changed

+66
-24
lines changed

8 files changed

+66
-24
lines changed

MongoDB.Analyzer.sln

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{2D18C947
1515
EndProject
1616
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "MongoDB.Analyzer.Tests.Common", "tests\MongoDB.Analyzer.Tests.Common\MongoDB.Analyzer.Tests.Common.shproj", "{4F59BE68-9AB5-4DCC-8049-04AD7BB36AB6}"
1717
EndProject
18-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MongoDB.Analyzer.Tests.Common.ClassLibrary", "tests\MongoDB.Analyzer.Tests.Common.ClassLibrary\MongoDB.Analyzer.Tests.Common.ClassLibrary.csproj", "{41218684-A8E3-41AC-8F85-58B9B2F43B09}"
19-
EndProject
2018
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "MongoDB.Analyzer.Tests.Common.TestCases", "tests\MongoDB.Analyzer.Tests.Common.TestCases\MongoDB.Analyzer.Tests.Common.TestCases.shproj", "{1845551F-DEFF-4082-B2DB-3548A44F83AF}"
2119
EndProject
2220
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MongoDB.Analyzer.Helpers", "src\MongoDB.Analyzer.Helpers\MongoDB.Analyzer.Helpers.csproj", "{C9D49CAA-3F1F-4969-BDC1-0D17F9DB2B65}"
@@ -26,32 +24,56 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
2624
.editorconfig = .editorconfig
2725
EndProjectSection
2826
EndProject
27+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.Analyzer.Tests.Common.ClassLibrary", "tests\MongoDB.Analyzer.Tests.Common.ClassLibrary\MongoDB.Analyzer.Tests.Common.ClassLibrary.csproj", "{8335EFD4-C859-4E7B-B7D5-C57FC443700C}"
28+
EndProject
2929
Global
3030
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3131
Debug|Any CPU = Debug|Any CPU
3232
Release|Any CPU = Release|Any CPU
33+
DRIVER_2_27_OR_LOWER|Any CPU = DRIVER_2_27_OR_LOWER|Any CPU
34+
DRIVER_2_28_OR_GREATER|Any CPU = DRIVER_2_28_OR_GREATER|Any CPU
3335
EndGlobalSection
3436
GlobalSection(ProjectConfigurationPlatforms) = postSolution
3537
{F65EE23C-7B5B-4B8B-B9A7-386D08BDD3F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
3638
{F65EE23C-7B5B-4B8B-B9A7-386D08BDD3F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
3739
{F65EE23C-7B5B-4B8B-B9A7-386D08BDD3F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
3840
{F65EE23C-7B5B-4B8B-B9A7-386D08BDD3F5}.Release|Any CPU.Build.0 = Release|Any CPU
41+
{F65EE23C-7B5B-4B8B-B9A7-386D08BDD3F5}.DRIVER_2_27_OR_LOWER|Any CPU.ActiveCfg = Debug|Any CPU
42+
{F65EE23C-7B5B-4B8B-B9A7-386D08BDD3F5}.DRIVER_2_27_OR_LOWER|Any CPU.Build.0 = Debug|Any CPU
43+
{F65EE23C-7B5B-4B8B-B9A7-386D08BDD3F5}.DRIVER_2_28_OR_GREATER|Any CPU.ActiveCfg = Debug|Any CPU
44+
{F65EE23C-7B5B-4B8B-B9A7-386D08BDD3F5}.DRIVER_2_28_OR_GREATER|Any CPU.Build.0 = Debug|Any CPU
3945
{612B7D09-FEF8-4C12-B31A-04B02EC1F297}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
4046
{612B7D09-FEF8-4C12-B31A-04B02EC1F297}.Debug|Any CPU.Build.0 = Debug|Any CPU
4147
{612B7D09-FEF8-4C12-B31A-04B02EC1F297}.Release|Any CPU.ActiveCfg = Release|Any CPU
4248
{612B7D09-FEF8-4C12-B31A-04B02EC1F297}.Release|Any CPU.Build.0 = Release|Any CPU
49+
{612B7D09-FEF8-4C12-B31A-04B02EC1F297}.DRIVER_2_27_OR_LOWER|Any CPU.ActiveCfg = Debug|Any CPU
50+
{612B7D09-FEF8-4C12-B31A-04B02EC1F297}.DRIVER_2_27_OR_LOWER|Any CPU.Build.0 = Debug|Any CPU
51+
{612B7D09-FEF8-4C12-B31A-04B02EC1F297}.DRIVER_2_28_OR_GREATER|Any CPU.ActiveCfg = Debug|Any CPU
52+
{612B7D09-FEF8-4C12-B31A-04B02EC1F297}.DRIVER_2_28_OR_GREATER|Any CPU.Build.0 = Debug|Any CPU
4353
{ACB908A0-7F5C-44DA-B9D2-CCFBCAEADD1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
4454
{ACB908A0-7F5C-44DA-B9D2-CCFBCAEADD1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
4555
{ACB908A0-7F5C-44DA-B9D2-CCFBCAEADD1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
4656
{ACB908A0-7F5C-44DA-B9D2-CCFBCAEADD1D}.Release|Any CPU.Build.0 = Release|Any CPU
47-
{41218684-A8E3-41AC-8F85-58B9B2F43B09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
48-
{41218684-A8E3-41AC-8F85-58B9B2F43B09}.Debug|Any CPU.Build.0 = Debug|Any CPU
49-
{41218684-A8E3-41AC-8F85-58B9B2F43B09}.Release|Any CPU.ActiveCfg = Release|Any CPU
50-
{41218684-A8E3-41AC-8F85-58B9B2F43B09}.Release|Any CPU.Build.0 = Release|Any CPU
57+
{ACB908A0-7F5C-44DA-B9D2-CCFBCAEADD1D}.DRIVER_2_27_OR_LOWER|Any CPU.ActiveCfg = Debug|Any CPU
58+
{ACB908A0-7F5C-44DA-B9D2-CCFBCAEADD1D}.DRIVER_2_27_OR_LOWER|Any CPU.Build.0 = Debug|Any CPU
59+
{ACB908A0-7F5C-44DA-B9D2-CCFBCAEADD1D}.DRIVER_2_28_OR_GREATER|Any CPU.ActiveCfg = Debug|Any CPU
60+
{ACB908A0-7F5C-44DA-B9D2-CCFBCAEADD1D}.DRIVER_2_28_OR_GREATER|Any CPU.Build.0 = Debug|Any CPU
5161
{C9D49CAA-3F1F-4969-BDC1-0D17F9DB2B65}.Debug|Any CPU.ActiveCfg = DRIVER_2_19|Any CPU
5262
{C9D49CAA-3F1F-4969-BDC1-0D17F9DB2B65}.Debug|Any CPU.Build.0 = DRIVER_2_19|Any CPU
5363
{C9D49CAA-3F1F-4969-BDC1-0D17F9DB2B65}.Release|Any CPU.ActiveCfg = DRIVER_2_19|Any CPU
5464
{C9D49CAA-3F1F-4969-BDC1-0D17F9DB2B65}.Release|Any CPU.Build.0 = DRIVER_2_19|Any CPU
65+
{C9D49CAA-3F1F-4969-BDC1-0D17F9DB2B65}.DRIVER_2_27_OR_LOWER|Any CPU.ActiveCfg = DRIVER_2_12|Any CPU
66+
{C9D49CAA-3F1F-4969-BDC1-0D17F9DB2B65}.DRIVER_2_27_OR_LOWER|Any CPU.Build.0 = DRIVER_2_12|Any CPU
67+
{C9D49CAA-3F1F-4969-BDC1-0D17F9DB2B65}.DRIVER_2_28_OR_GREATER|Any CPU.ActiveCfg = DRIVER_2_12|Any CPU
68+
{C9D49CAA-3F1F-4969-BDC1-0D17F9DB2B65}.DRIVER_2_28_OR_GREATER|Any CPU.Build.0 = DRIVER_2_12|Any CPU
69+
{8335EFD4-C859-4E7B-B7D5-C57FC443700C}.Debug|Any CPU.ActiveCfg = DRIVER_2_28_OR_GREATER|Any CPU
70+
{8335EFD4-C859-4E7B-B7D5-C57FC443700C}.Debug|Any CPU.Build.0 = DRIVER_2_28_OR_GREATER|Any CPU
71+
{8335EFD4-C859-4E7B-B7D5-C57FC443700C}.Release|Any CPU.ActiveCfg = DRIVER_2_27_OR_LOWER|Any CPU
72+
{8335EFD4-C859-4E7B-B7D5-C57FC443700C}.Release|Any CPU.Build.0 = DRIVER_2_27_OR_LOWER|Any CPU
73+
{8335EFD4-C859-4E7B-B7D5-C57FC443700C}.DRIVER_2_27_OR_LOWER|Any CPU.ActiveCfg = DRIVER_2_27_OR_LOWER|Any CPU
74+
{8335EFD4-C859-4E7B-B7D5-C57FC443700C}.DRIVER_2_27_OR_LOWER|Any CPU.Build.0 = DRIVER_2_27_OR_LOWER|Any CPU
75+
{8335EFD4-C859-4E7B-B7D5-C57FC443700C}.DRIVER_2_28_OR_GREATER|Any CPU.ActiveCfg = DRIVER_2_28_OR_GREATER|Any CPU
76+
{8335EFD4-C859-4E7B-B7D5-C57FC443700C}.DRIVER_2_28_OR_GREATER|Any CPU.Build.0 = DRIVER_2_28_OR_GREATER|Any CPU
5577
EndGlobalSection
5678
GlobalSection(SolutionProperties) = preSolution
5779
HideSolutionNode = FALSE
@@ -61,9 +83,9 @@ Global
6183
{612B7D09-FEF8-4C12-B31A-04B02EC1F297} = {3CBBF53B-DAE1-49C2-A97D-19FC6DAF8867}
6284
{ACB908A0-7F5C-44DA-B9D2-CCFBCAEADD1D} = {2D18C947-A75E-4330-A272-213658715E74}
6385
{4F59BE68-9AB5-4DCC-8049-04AD7BB36AB6} = {2D18C947-A75E-4330-A272-213658715E74}
64-
{41218684-A8E3-41AC-8F85-58B9B2F43B09} = {2D18C947-A75E-4330-A272-213658715E74}
6586
{1845551F-DEFF-4082-B2DB-3548A44F83AF} = {2D18C947-A75E-4330-A272-213658715E74}
6687
{C9D49CAA-3F1F-4969-BDC1-0D17F9DB2B65} = {3CBBF53B-DAE1-49C2-A97D-19FC6DAF8867}
88+
{8335EFD4-C859-4E7B-B7D5-C57FC443700C} = {2D18C947-A75E-4330-A272-213658715E74}
6789
EndGlobalSection
6890
GlobalSection(ExtensibilityGlobals) = postSolution
6991
SolutionGuid = {92FC99D4-1527-4D7F-AD28-B0949CD5BE72}

evergreen/run-tests.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ echo Testing with driver: "${DRIVER_VERSION}" "${TARGET_FRAMEWORK}"
66

77
dotnet clean "./MongoDB.Analyzer.sln"
88

9-
dotnet build "./tests/MongoDB.Analyzer.Tests.Common.ClassLibrary" -f netstandard2.0 -c Debug
9+
dotnet build "./tests/MongoDB.Analyzer.Tests.Common.ClassLibrary" -f netstandard2.0 -c DRIVER_2_27_OR_LOWER
10+
dotnet build "./tests/MongoDB.Analyzer.Tests.Common.ClassLibrary" -f netstandard2.0 -c DRIVER_2_28_OR_GREATER
1011

1112
dotnet test "./MongoDB.Analyzer.sln" -e DRIVER_VERSION="${DRIVER_VERSION}" --framework "${TARGET_FRAMEWORK}" -c Release --results-directory ./build/test-results --logger "junit;LogFileName=TEST-MongoDB.Analyzer.xml;FailureBodyFormat=Verbose"

src/MongoDB.Analyzer/Core/Utilities/AnalysisCodeGeneratorUtilities.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,19 @@ namespace MongoDB.Analyzer.Core.Utilities;
1818

1919
internal static class AnalysisCodeGeneratorUtilities
2020
{
21-
private const string AnalysisAssemblyName = "DynamicProxyGenAssembly2";
21+
private const string AnalysisAssemblyNameDriver_2_27_OrLower = "DynamicProxyGenAssembly2";
22+
private const string AnalysisAssemblyNameDriver_2_28_OrGreater = "MongoDB.Analyzer.MQLGenerator";
23+
private static readonly Version s_driverVersion_2_28 = new(2, 28);
24+
private static readonly ImmutableArray<byte> s_publicKey = new byte[160] { 0, 36, 0, 0, 4, 128, 0, 0, 148, 0, 0, 0, 6, 2, 0, 0, 0, 36, 0, 0, 82, 83, 65, 49, 0, 4, 0, 0, 1, 0, 1, 0, 53, 40, 127, 13, 56, 131, 192, 160, 117, 200, 142, 12, 218, 60, 233, 59, 98, 16, 3, 236, 189, 94, 146, 13, 74, 140, 114, 56, 86, 79, 77, 47, 79, 104, 17, 106, 202, 40, 201, 178, 19, 65, 220, 58, 135, 118, 121, 193, 69, 86, 25, 43, 43, 47, 95, 226, 193, 29, 98, 78, 8, 148, 211, 8, 255, 123, 148, 191, 111, 215, 42, 239, 27, 65, 1, 127, 254, 37, 114, 233, 144, 25, 209, 198, 25, 99, 230, 140, 208, 237, 103, 115, 74, 66, 203, 51, 59, 128, 142, 56, 103, 203, 230, 49, 147, 114, 20, 227, 46, 64, 159, 177, 250, 98, 253, 182, 157, 73, 76, 37, 48, 230, 74, 64, 228, 23, 214, 238 }.ToImmutableArray();
2225

2326
public static Type CompileAndGetGeneratorType(AnalysisType analysisType, MongoAnalysisContext context, ReferencesContainer referencesContainer, IEnumerable<SyntaxTree> syntaxTrees)
2427
{
28+
var assemblyName = referencesContainer.Version >= s_driverVersion_2_28 ? AnalysisAssemblyNameDriver_2_28_OrGreater : AnalysisAssemblyNameDriver_2_27_OrLower;
2529
var compilation = CSharpCompilation.Create(
26-
AnalysisAssemblyName,
30+
assemblyName,
2731
syntaxTrees,
2832
referencesContainer.References,
29-
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
33+
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, publicSign: true, cryptoPublicKey: s_publicKey));
3034

3135
using var memoryStream = new MemoryStream();
3236
var emitResult = compilation.Emit(memoryStream);

tests/MongoDB.Analyzer.Tests.Common.ClassLibrary/MongoDB.Analyzer.Tests.Common.ClassLibrary.csproj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<LangVersion>9</LangVersion>
6+
<Configurations>DRIVER_2_27_OR_LOWER;DRIVER_2_28_OR_GREATER</Configurations>
67
</PropertyGroup>
78

89
<Import Project="..\MongoDB.Analyzer.Tests.Common\MongoDB.Analyzer.Tests.Common.projitems" Label="Shared" />
910

1011
<ItemGroup>
11-
<PackageReference Include="MongoDB.Driver" Version="2.19.0">
12-
<ExcludeAssets>runtime</ExcludeAssets>
13-
</PackageReference>
12+
<PackageReference Include="MongoDB.Driver" Version="2.12.4" Condition="'$(Configuration)' == 'DRIVER_2_27_OR_LOWER'" />
13+
<PackageReference Include="MongoDB.Driver" Version="2.28.0" Condition="'$(Configuration)' == 'DRIVER_2_28_OR_GREATER'" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
1417
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.0" />
1518
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.0" />
1619
</ItemGroup>

tests/MongoDB.Analyzer.Tests.Common/DriverVersions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@ public static class DriverVersions
2828
public const string V2_22_OrLower = "(, 2.23.0)";
2929
public const string V2_23_OrGreater = "[2.23.0,)";
3030
public const string V2_19_to_2_20= "[2.19.0, 2.20.0)";
31+
public const string V2_27_OrLower = "(, 2.28.0)";
32+
public const string V2_28_OrGreater = "[2.28.0, )";
3133
}
3234
}

tests/MongoDB.Analyzer.Tests/Infrastructure/DiagnosticsAnalyzer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static async Task<ImmutableArray<Diagnostic>> Analyze(
3131
Common.LinqVersion linqVersion,
3232
Common.PocoAnalysisVerbosity jsonAnalyzerVerbosity)
3333
{
34-
PathUtilities.VerifyTestDataModelAssembly();
34+
var testDataModelAssembly = PathUtilities.GetTestDataModelAssemblyPath(driverVersion);
3535

3636
#if NET472
3737
var netReferences = ReferenceAssemblies.NetFramework.Net472.Default.AddAssemblies(ImmutableArray.Create("System.Drawing"));
@@ -46,15 +46,15 @@ public static async Task<ImmutableArray<Diagnostic>> Analyze(
4646

4747
var allReferences = netReferences
4848
.AddPackages(packages)
49-
.AddAssemblies(ImmutableArray.Create(PathUtilities.TestDataModelAssemblyPath))
49+
.AddAssemblies(ImmutableArray.Create(testDataModelAssembly))
5050
.WithNuGetConfigFilePath(PathUtilities.NugetConfigPath);
5151

5252
var metadataReferences = await allReferences.ResolveAsync(LanguageNames.CSharp, default);
5353

5454
var testCodeText = File.ReadAllText(testCodeFilename);
5555
var testCodeSyntaxTree = CSharpSyntaxTree.ParseText(testCodeText);
56-
var compilationOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary);
5756

57+
var compilationOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary);
5858
var compilation = CSharpCompilation.Create(
5959
"TestAssembly",
6060
new[] { testCodeSyntaxTree },

tests/MongoDB.Analyzer.Tests/Infrastructure/DriverVersionHelper.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ static DriverVersionHelper()
3434
// NuGetVersion.Parse("2.18.0"),
3535
// NuGetVersion.Parse("2.19.0"),
3636
// NuGetVersion.Parse("2.21.0"),
37-
// NuGetVersion.Parse("2.25.0")
38-
// }
37+
// NuGetVersion.Parse("2.25.0"),
38+
// NuGetVersion.Parse("2.27.0"),
39+
// NuGetVersion.Parse("2.28.0")
40+
// };
3941
}
4042

4143
public static NuGetVersion[] FilterVersionForRange(string versionRange)

tests/MongoDB.Analyzer.Tests/Infrastructure/PathUtilities.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
// limitations under the License.
1414

1515
using System.IO;
16+
using MongoDB.Analyzer.Tests.Common;
17+
using NuGet.Versioning;
1618

1719
namespace MongoDB.Analyzer.Tests.Infrastructure;
1820

@@ -23,7 +25,8 @@ internal static class PathUtilities
2325
private static readonly string s_projectParentFolderPrefix = Path.Combine("..", "..", "..", "..");
2426
private static readonly string s_testCasesPath = GetFullPathRelativeToParent(s_testCasesBaseFolder);
2527

26-
public static string TestDataModelAssemblyPath { get; } = GetFullPathRelativeToParent("MongoDB.Analyzer.Tests.Common.ClassLibrary", "bin", "Debug", "netstandard2.0", "MongoDB.Analyzer.Tests.Common.ClassLibrary");
28+
public static string TestDataModelAssemblyPathDriver_2_27_OrLower { get; } = GetFullPathRelativeToParent("MongoDB.Analyzer.Tests.Common.ClassLibrary", "bin", "DRIVER_2_27_OR_LOWER", "netstandard2.0", "MongoDB.Analyzer.Tests.Common.ClassLibrary");
29+
public static string TestDataModelAssemblyPathDriver_2_28_OrGreater { get; } = GetFullPathRelativeToParent("MongoDB.Analyzer.Tests.Common.ClassLibrary", "bin", "DRIVER_2_28_OR_GREATER", "netstandard2.0", "MongoDB.Analyzer.Tests.Common.ClassLibrary");
2730
public static string NugetConfigPath { get; } = GetFullPathRelativeToParent("..", "nuget.config");
2831

2932
public static string GetTestCaseFileFullPathFromName(string testCaseFullyQualifiedName)
@@ -37,15 +40,20 @@ public static string GetTestCaseFileFullPathFromName(string testCaseFullyQualifi
3740
return result;
3841
}
3942

40-
public static void VerifyTestDataModelAssembly()
43+
public static string GetTestDataModelAssemblyPath(string driverVersion)
4144
{
42-
var fileName = $"{TestDataModelAssemblyPath}.dll";
43-
if (!File.Exists(fileName))
45+
var testDataModelAssembly = IsDriverVersion_2_28_OrGreater(driverVersion) ? TestDataModelAssemblyPathDriver_2_28_OrGreater : TestDataModelAssemblyPathDriver_2_27_OrLower;
46+
47+
if (!File.Exists($"{testDataModelAssembly}.dll"))
4448
{
45-
throw new FileNotFoundException($"DataModel assembly {fileName} not found", fileName);
49+
throw new FileNotFoundException($"DataModel assembly {testDataModelAssembly} not found", testDataModelAssembly);
4650
}
51+
52+
return testDataModelAssembly;
4753
}
4854

4955
private static string GetFullPathRelativeToParent(params string[] pathComponents) =>
5056
Path.GetFullPath(Path.Combine(s_projectParentFolderPrefix, pathComponents.Length == 1 ? pathComponents[0] : Path.Combine(pathComponents)));
57+
58+
private static bool IsDriverVersion_2_28_OrGreater(string driverVersion) => VersionRange.Parse(DriverVersions.V2_28_OrGreater).Satisfies(NuGetVersion.Parse(driverVersion));
5159
}

0 commit comments

Comments
 (0)