forked from tunnelvisionlabs/dotnet-compatibility
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust help text, LICENSE and NOTICE, move to nuget packages and clea…
…nup old stuff.
- Loading branch information
Showing
15 changed files
with
647 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,4 @@ MigrationBackup/ | |
|
||
# MacOS | ||
.DS_Store | ||
packed/ |
24 changes: 24 additions & 0 deletions
24
CompatibilityChecker.Libary.Tests/CompatibilityChecker.Libary.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" /> | ||
<PackageReference Include="coverlet.collector" Version="1.3.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="System.Reflection.Emit" Version="4.7.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\CompatibilityChecker.Library\CompatibilityChecker.Library.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
109 changes: 109 additions & 0 deletions
109
CompatibilityChecker.Libary.Tests/TestAssemblyAnalysis.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
namespace CompatibilityCheckerTests | ||
{ | ||
using System.Collections.ObjectModel; | ||
using System.Reflection; | ||
using System.Reflection.Emit; | ||
using CompatibilityChecker.Library; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
[TestClass] | ||
public class TestAssemblyAnalysis | ||
{ | ||
[TestMethod] | ||
public void TestAssemblyNameMustNotBeChanged_Pass() | ||
{ | ||
AssemblyName referenceName = new AssemblyName("Test.Assembly"); | ||
AssemblyBuilder referenceAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(referenceName, AssemblyBuilderAccess.ReflectionOnly); | ||
referenceAssemblyBuilder.Save("Test.Assembly.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); | ||
|
||
AssemblyName newAssemblyName = new AssemblyName("Test.Assembly"); | ||
AssemblyBuilder newAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(newAssemblyName, AssemblyBuilderAccess.ReflectionOnly); | ||
newAssemblyBuilder.Save("Test.Assembly.V2.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); | ||
|
||
ReadOnlyCollection<Message> messages = TestUtility.AnalyzeAssemblies("Test.Assembly.dll", "Test.Assembly.V2.dll"); | ||
Assert.AreEqual(0, messages.Count); | ||
} | ||
|
||
[TestMethod] | ||
public void TestAssemblyNameMustNotBeChanged_Fail() | ||
{ | ||
AssemblyName referenceName = new AssemblyName("Test.Assembly"); | ||
AssemblyBuilder referenceAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(referenceName, AssemblyBuilderAccess.ReflectionOnly); | ||
referenceAssemblyBuilder.Save("Test.Assembly.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); | ||
|
||
AssemblyName newAssemblyName = new AssemblyName("Test.Assembly.V2"); | ||
AssemblyBuilder newAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(newAssemblyName, AssemblyBuilderAccess.ReflectionOnly); | ||
newAssemblyBuilder.Save("Test.Assembly.V2.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); | ||
|
||
ReadOnlyCollection<Message> messages = TestUtility.AnalyzeAssemblies("Test.Assembly.dll", "Test.Assembly.V2.dll"); | ||
Assert.AreEqual(1, messages.Count); | ||
Assert.AreEqual("Error AssemblyNameMustNotBeChanged: The simple name of an assembly cannot change for 'Test.Assembly'.", messages[0].ToString()); | ||
} | ||
|
||
[TestMethod] | ||
public void TestPublicKeyMustNotBeChanged_PassMissing() | ||
{ | ||
AssemblyName referenceName = new AssemblyName("Test.Assembly"); | ||
AssemblyBuilder referenceAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(referenceName, AssemblyBuilderAccess.ReflectionOnly); | ||
referenceAssemblyBuilder.Save("Test.Assembly.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); | ||
|
||
AssemblyName newAssemblyName = new AssemblyName("Test.Assembly"); | ||
AssemblyBuilder newAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(newAssemblyName, AssemblyBuilderAccess.ReflectionOnly); | ||
newAssemblyBuilder.Save("Test.Assembly.V2.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); | ||
|
||
ReadOnlyCollection<Message> messages = TestUtility.AnalyzeAssemblies("Test.Assembly.dll", "Test.Assembly.V2.dll"); | ||
Assert.AreEqual(0, messages.Count); | ||
} | ||
|
||
[TestMethod] | ||
public void TestPublicKeyMustNotBeChanged_PassUnchanged() | ||
{ | ||
AssemblyName referenceName = new AssemblyName("Test.Assembly"); | ||
referenceName.KeyPair = TestUtility.GenerateStrongNameKeyPair(); | ||
AssemblyBuilder referenceAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(referenceName, AssemblyBuilderAccess.ReflectionOnly); | ||
referenceAssemblyBuilder.Save("Test.Assembly.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); | ||
|
||
AssemblyName newAssemblyName = new AssemblyName("Test.Assembly"); | ||
newAssemblyName.KeyPair = referenceName.KeyPair; | ||
AssemblyBuilder newAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(newAssemblyName, AssemblyBuilderAccess.ReflectionOnly); | ||
newAssemblyBuilder.Save("Test.Assembly.V2.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); | ||
|
||
ReadOnlyCollection<Message> messages = TestUtility.AnalyzeAssemblies("Test.Assembly.dll", "Test.Assembly.V2.dll"); | ||
Assert.AreEqual(0, messages.Count); | ||
} | ||
|
||
[TestMethod] | ||
public void TestPublicKeyMustNotBeChanged_PassAdded() | ||
{ | ||
AssemblyName referenceName = new AssemblyName("Test.Assembly"); | ||
AssemblyBuilder referenceAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(referenceName, AssemblyBuilderAccess.ReflectionOnly); | ||
referenceAssemblyBuilder.Save("Test.Assembly.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); | ||
|
||
AssemblyName newAssemblyName = new AssemblyName("Test.Assembly"); | ||
newAssemblyName.KeyPair = TestUtility.GenerateStrongNameKeyPair(); | ||
AssemblyBuilder newAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(newAssemblyName, AssemblyBuilderAccess.ReflectionOnly); | ||
newAssemblyBuilder.Save("Test.Assembly.V2.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); | ||
|
||
ReadOnlyCollection<Message> messages = TestUtility.AnalyzeAssemblies("Test.Assembly.dll", "Test.Assembly.V2.dll"); | ||
Assert.AreEqual(0, messages.Count); | ||
} | ||
|
||
[TestMethod] | ||
public void TestPublicKeyMustNotBeChanged_Fail() | ||
{ | ||
AssemblyName referenceName = new AssemblyName("Test.Assembly"); | ||
referenceName.KeyPair = TestUtility.GenerateStrongNameKeyPair(); | ||
AssemblyBuilder referenceAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(referenceName, AssemblyBuilderAccess.ReflectionOnly); | ||
referenceAssemblyBuilder.Save("Test.Assembly.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); | ||
|
||
AssemblyName newAssemblyName = new AssemblyName("Test.Assembly"); | ||
newAssemblyName.KeyPair = TestUtility.GenerateStrongNameKeyPair(); | ||
AssemblyBuilder newAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(newAssemblyName, AssemblyBuilderAccess.ReflectionOnly); | ||
newAssemblyBuilder.Save("Test.Assembly.V2.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); | ||
|
||
ReadOnlyCollection<Message> messages = TestUtility.AnalyzeAssemblies("Test.Assembly.dll", "Test.Assembly.V2.dll"); | ||
Assert.AreEqual(1, messages.Count); | ||
Assert.AreEqual("Error PublicKeyMustNotBeChanged: The public key of a strong-named assembly 'Test.Assembly' cannot change.", messages[0].ToString()); | ||
} | ||
} | ||
} |
Oops, something went wrong.