public void Reading_Export_Instructions_Returns_A_ExportDefinition_With_A_Custom_CallingConvention() { using (var testEnv = new TestEnvironment()) { var testCode = @"using System.Runtime.InteropServices; namespace Test { class TestClassA { [NXPorts.Attributes.Export(callingConvention:CallingConvention.FastCall)] public static void DoShizzle() { System.Console.WriteLine(""asdsad""); } } }"; if (!testEnv.CreateTestDLL("test", new[] { testCode })) { Assert.Fail("Test compile failed."); } using (var testExportAttributedAssembly = new ExportAttributedAssembly("./test.dll")) { Assert.IsTrue(testExportAttributedAssembly.ExportDefinitions.Count == 1); Assert.AreEqual(System.Runtime.InteropServices.CallingConvention.FastCall, testExportAttributedAssembly.ExportDefinitions.First().CallingConvention); } } }
public void Reading_Export_Instructions_Returns_A_Custom_Aliased_ExportDefinition() { using (var testEnv = new TestEnvironment()) { var testCode = @"namespace Test { class TestClassA { [NXPorts.Attributes.Export(alias:""Aids"")] public static void DoShizzle() { System.Console.WriteLine(""asdsad""); } } }"; if (!testEnv.CreateTestDLL("test", new[] { testCode })) { Assert.Fail("Test compile failed."); } using (var testExportAttributedAssembly = new ExportAttributedAssembly("./test.dll")) { Assert.IsTrue(testExportAttributedAssembly.ExportDefinitions.Count == 1); Assert.AreEqual("Aids", testExportAttributedAssembly.ExportDefinitions.First().Alias); } } }
public void ProducesAssemblyWithoutAnyReferenceToNXPortAttributes() { using (var testEnv = new TestEnvironment()) { var testCode = @"namespace Test { public class TestClassA { [NXPorts.Attributes.DllExport] public static void DoSomething() { } } }"; if (!testEnv.CreateTestDLL("test", new[] { testCode })) { Assert.Fail("Test compile failed."); } using (var testExportAttributedAssembly = new ExportAttributedAssembly("./test.dll")) { var writer = new AssemblyExportWriterTask(); writer.BuildEngine = BuildEngine.Create(); writer.Write(testExportAttributedAssembly, "./testOut.dll"); } using (var resultModule = ModuleDefMD.Load("./testOut.dll")) { var simpleNameOfAttributeAssembly = typeof(NXPorts.Attributes.DllExportAttribute).Assembly.GetName().Name; Assert.AreEqual( null, resultModule.GetAssemblyRef(simpleNameOfAttributeAssembly), $"Assembly was left with a reference to assembly '{simpleNameOfAttributeAssembly}'." ); } } }
public void ProducesAssemblyWithoutExportAttributes() { using (var testEnv = new TestEnvironment()) { var testCode = @"namespace Test { public class TestClassA { [NXPorts.Attributes.DllExport] public static void DoSomething() { } } }"; if (!testEnv.CreateTestDLL("test", new[] { testCode })) { Assert.Fail("Test compile failed."); } using (var testExportAttributedAssembly = new ExportAttributedAssembly("./test.dll")) { var writer = new AssemblyExportWriterTask(); writer.BuildEngine = BuildEngine.Create(); writer.Write(testExportAttributedAssembly, "./test.dll"); } using (var resultModule = ModuleDefMD.Load("./test.dll")) { var methodsWithOffendingAttribute = from t in resultModule.Types from m in t.Methods from ca in m.CustomAttributes where ca.TypeFullName == typeof(Attributes.DllExportAttribute).FullName select m; Assert.AreEqual(0, methodsWithOffendingAttribute.Count(), $"Assembly was left with one ore more {nameof(Attributes.DllExportAttribute)} occurences."); } } }
public void ProducesAssemblyWithOneWorkingExport() { using (var testEnv = new TestEnvironment()) { var testCode = @"namespace Test { public class TestClassA { [NXPorts.Attributes.DllExport] public static string DoSomething() { return ""TestReturnValue""; } } }"; if (!testEnv.CreateTestDLL("test", new[] { testCode })) { Assert.Fail("Test compile failed."); } using (var testExportAttributedAssembly = new ExportAttributedAssembly("./test.dll")) { var writer = new AssemblyExportWriterTask(); writer.BuildEngine = BuildEngine.Create(); writer.Write(testExportAttributedAssembly, "./test.dll"); } Assert.That.RunsWithoutError <DoSomethingDelegate>( "./test.dll", "DoSomething", d => { Assert.AreEqual("TestReturnValue", d()); } ); } }
public void Parsing_Without_Attributed_Assemblies_Produces_0_ExportDefinitions() { using (var testEnv = new TestEnvironment()) { var testCode = @"namespace Test { class TestClassA { public static void DoShizzle() { System.Console.WriteLine(""Test""); } } }"; if (!testEnv.CreateTestDLL("test", new[] { testCode })) { Assert.Fail("Test compile failed."); } using (var testExportAttributedAssembly = new ExportAttributedAssembly("./test.dll")) { Assert.IsTrue(testExportAttributedAssembly.ExportDefinitions.Count == 0); } } }