Skip to content

Commit

Permalink
Adjust help text, LICENSE and NOTICE, move to nuget packages and clea…
Browse files Browse the repository at this point in the history
…nup old stuff.
  • Loading branch information
EraYaN committed Jun 8, 2020
1 parent 430e7b0 commit 60ed340
Show file tree
Hide file tree
Showing 15 changed files with 647 additions and 39 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ MigrationBackup/

# MacOS
.DS_Store
packed/
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 CompatibilityChecker.Libary.Tests/TestAssemblyAnalysis.cs
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());
}
}
}
Loading

0 comments on commit 60ed340

Please sign in to comment.