コード例 #1
0
        private void InstallTargetsFileAndAssert(string expectedContent, bool expectCopy)
        {
            var localLogger = new TestLogger();
            var installer   = new TargetsInstaller(localLogger);

            using (new AssertIgnoreScope())
            {
                installer.InstallLoaderTargets(this.WorkingDirectory);
            }

            var msBuildPathSettings = new MsBuildPathSettings();

            foreach (var destinationDir in msBuildPathSettings.GetImportBeforePaths())
            {
                var path = Path.Combine(destinationDir, FileConstants.ImportBeforeTargetsName);
                File.Exists(path).Should().BeTrue(".targets file not found at: " + path);
                File.ReadAllText(path).Should().Be(expectedContent,
                                                   ".targets does not have expected content at " + path);

                localLogger.DebugMessages.Any(m => m.Contains(destinationDir)).Should().BeTrue();
            }

            var targetsPath = Path.Combine(this.WorkingDirectory, "bin", "targets", FileConstants.IntegrationTargetsName);

            File.Exists(targetsPath).Should().BeTrue(".targets file not found at: " + targetsPath);

            if (expectCopy)
            {
                localLogger.DebugMessages.Should().HaveCount(msBuildPathSettings.GetImportBeforePaths().Count() + 1,
                                                             "All destinations should have been covered");
            }
        }
コード例 #2
0
        public void InstallTargetsFile_Overwrite()
        {
            // In case the dummy targets file somehow does not get deleted (e.g. when debugging), make sure its content valid XML
            var sourceTargetsContent1 = @"<Project ToolsVersion=""4.0"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" />";
            var sourceTargetsContent2 = @"<Project ToolsVersion=""12.0"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" />";

            CreateDummySourceTargetsFile(sourceTargetsContent1);

            var msBuildPathSettings = new MsBuildPathSettings();

            InstallTargetsFileAndAssert(sourceTargetsContent1, expectCopy: true);
            Assert.AreEqual(6, msBuildPathSettings.GetImportBeforePaths().Count(), "Expecting six destination directories");

            var path = Path.Combine(msBuildPathSettings.GetImportBeforePaths().First(), FileConstants.ImportBeforeTargetsName);

            File.Delete(path);

            CreateDummySourceTargetsFile(sourceTargetsContent2);
            InstallTargetsFileAndAssert(sourceTargetsContent2, expectCopy: true);
            InstallTargetsFileAndAssert(sourceTargetsContent2, expectCopy: true);
        }