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 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 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.");
                }
            }
        }
示例#4
0
        public void TraversalReferencesWork()
        {
            ProjectCreator projectB = ProjectCreator
                                      .Create(GetTempFileName())
                                      .Save();

            ProjectCreator projectA = ProjectCreator
                                      .Create(GetTempFileName())
                                      .ItemProjectReference(projectB)
                                      .Save();

            ProjectCreator dirsProj = ProjectCreator
                                      .Create(GetTempFileName())
                                      .Property("IsTraversal", "true")
                                      .ItemInclude("ProjectFile", projectA.FullPath)
                                      .Save();

            BuildEngine buildEngine = BuildEngine.Create();

            MSBuildProjectLoader loader = new MSBuildProjectLoader(null, MSBuildToolsVersion, buildEngine);

            ProjectCollection projectCollection = loader.LoadProjectsAndReferences(new[] { dirsProj.FullPath });

            projectCollection.LoadedProjects.Select(i => i.FullPath).ShouldBe(
                new[] { dirsProj.FullPath, projectA.FullPath, projectB.FullPath },
                ignoreOrder: true);
        }
示例#5
0
        public void InvalidProjectsLogGoodInfo()
        {
            ProjectCreator projectA = ProjectCreator
                                      .Create(GetTempFileName())
                                      .Import(@"$(Foo)\foo.props")
                                      .Save();

            ProjectCreator dirsProj = ProjectCreator
                                      .Create(GetTempFileName())
                                      .Property("IsTraversal", "true")
                                      .ItemInclude("ProjectFile", projectA.FullPath)
                                      .Save();

            BuildEngine buildEngine = BuildEngine.Create();

            MSBuildProjectLoader loader = new MSBuildProjectLoader(null, MSBuildToolsVersion, buildEngine);

            loader.LoadProjectsAndReferences(new[] { dirsProj.FullPath });

            BuildErrorEventArgs errorEventArgs = buildEngine.ErrorEvents.ShouldHaveSingleItem();

            errorEventArgs.Code.ShouldBe("MSB4019");
            errorEventArgs.ColumnNumber.ShouldBe(3);
            errorEventArgs.HelpKeyword.ShouldBe("MSBuild.ImportedProjectNotFound");
            errorEventArgs.LineNumber.ShouldBe(3);
            errorEventArgs.File.ShouldBe(projectA.FullPath);
        }
示例#6
0
        private BuildEngine GetBuildEngineWithEvents(Action <IBuildEngine> action)
        {
            BuildEngine buildEngine = BuildEngine.Create();

            action(buildEngine);

            return(buildEngine);
        }
示例#7
0
        public void RecursiveWildcards()
        {
            DirectoryInfo source = CreateFiles(
                "source",
                "foo.txt",
                "foo.exe",
                "foo.exe.config",
                "foo.dll",
                "foo.pdb",
                "foo.xml",
                "foo.cs",
                "foo.ini",
                "bar.dll",
                "bar.pdb",
                "bar.xml",
                "bar.cs",
                Path.Combine("baz", "baz.dll"));

            DirectoryInfo destination = new DirectoryInfo(Path.Combine(TestRootPath, "destination"));

            BuildEngine buildEngine = BuildEngine.Create();

            Robocopy copyArtifacts = new Robocopy
            {
                BuildEngine = buildEngine,
                Sources     = new ITaskItem[]
                {
                    new MockTaskItem(source.FullName)
                    {
                        ["DestinationFolder"] = destination.FullName,
                        ["FileMatch"]         = "*exe *dll *exe.config",
                    },
                },
                Sleep = duration => { },
            };

            copyArtifacts.Execute().ShouldBeTrue(buildEngine.GetConsoleLog());

            destination.GetFiles("*", SearchOption.AllDirectories)
            .Select(i => i.FullName)
            .ShouldBe(
                new[]
            {
                "bar.dll",
                "foo.dll",
                "foo.exe",
                "foo.exe.config",
                Path.Combine("baz", "baz.dll"),
            }.Select(i => Path.Combine(destination.FullName, i)),
                ignoreOrder: true);
        }
示例#8
0
        public void BuildFailsIfError()
        {
            ProjectCreator dirsProj = ProjectCreator
                                      .Create(GetTempFileName())
                                      .Property("IsTraversal", "true")
                                      .ItemInclude("ProjectFile", "does not exist")
                                      .Save();

            BuildEngine buildEngine = BuildEngine.Create();

            MSBuildProjectLoader loader = new MSBuildProjectLoader(null, MSBuildToolsVersion, buildEngine);

            loader.LoadProjectsAndReferences(new[] { dirsProj.FullPath });

            buildEngine.Errors.ShouldHaveSingleItem().ShouldStartWith("The project file could not be loaded. Could not find file ");
        }
示例#9
0
        public void ProjectReferencesWork()
        {
            ProjectCreator projectB = ProjectCreator
                                      .Create(GetTempFileName())
                                      .Save();

            ProjectCreator projectA = ProjectCreator
                                      .Create(GetTempFileName())
                                      .ItemProjectReference(projectB)
                                      .Save();

            BuildEngine buildEngine = BuildEngine.Create();

            MSBuildProjectLoader loader = new MSBuildProjectLoader(null, MSBuildToolsVersion, buildEngine);

            ProjectCollection projectCollection = loader.LoadProjectsAndReferences(new[] { projectA.FullPath });

            projectCollection.LoadedProjects.Select(i => i.FullPath).ShouldBe(new[] { projectA.FullPath, projectB.FullPath });
        }
示例#10
0
        public void NonRecursiveWildcards()
        {
            DirectoryInfo source = CreateFiles(
                "source",
                @"foo.txt",
                @"foo.ini",
                @"bar.txt",
                @"bar\bar.pdb",
                @"bar\bar.txt",
                @"bar.cs",
                @"baz\baz.dll",
                @"baz\baz.txt");

            DirectoryInfo destination = new DirectoryInfo(Path.Combine(TestRootPath, "destination"));

            BuildEngine buildEngine = BuildEngine.Create();

            Robocopy copyArtifacts = new Robocopy
            {
                BuildEngine = buildEngine,
                Sources     = new ITaskItem[]
                {
                    new MockTaskItem(source.FullName)
                    {
                        ["DestinationFolder"] = destination.FullName,
                        ["FileMatch"]         = "*txt",
                        [nameof(RobocopyMetadata.IsRecursive)] = "false"
                    }
                },
                Sleep = duration => { }
            };

            copyArtifacts.Execute().ShouldBeTrue(buildEngine.GetConsoleLog());

            destination.GetFiles("*", SearchOption.AllDirectories)
            .Select(i => i.FullName)
            .ShouldBe(new[]
            {
                "bar.txt",
                "foo.txt",
            }.Select(i => Path.Combine(destination.FullName, i)));
        }
示例#11
0
        public void GlobalPropertiesSetCorrectly()
        {
            Dictionary <string, string> expectedGlobalProperties = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
            {
                ["Property1"] = "1A836FEB3ABA43B183034DFDD5C4E375",
                ["Property2"] = "CEEC5C9FF0F344DAA32A0F545460EB2C"
            };

            ProjectCreator projectA = ProjectCreator
                                      .Create(GetTempFileName())
                                      .Save();

            BuildEngine buildEngine = BuildEngine.Create();

            MSBuildProjectLoader loader = new MSBuildProjectLoader(expectedGlobalProperties, MSBuildToolsVersion, buildEngine);

            ProjectCollection projectCollection = loader.LoadProjectsAndReferences(new[] { projectA.FullPath });

            projectCollection.GlobalProperties.ShouldBe(expectedGlobalProperties);
        }