コード例 #1
0
        public void MigratingScriptsWithMultipleCommandsCreatesExecTaskForEach(string scriptName)
        {
            var scriptMigrationRule = new MigrateScriptsRule();
            ProjectRootElement          mockProj            = ProjectRootElement.Create();
            ProjectPropertyGroupElement commonPropertyGroup = mockProj.AddPropertyGroup();

            var commands       = new[] { "fakecommand1", "fakecommand2", "mockcommand3" };
            var commandsInTask = commands.ToDictionary(c => c, c => false);

            var target = scriptMigrationRule.MigrateScriptSet(
                mockProj,
                commonPropertyGroup,
                commands,
                scriptName,
                IsMultiTFM);

            foreach (var task in target.Tasks)
            {
                var taskCommand = task.GetParameter("Command");
                var originalCommandCandidates = commands.Where(c => taskCommand.Contains(c));
                originalCommandCandidates.Count().Should().Be(1);

                var command = originalCommandCandidates.First();
                commandsInTask[command]
                .Should().Be(false, "Expected to find each element from commands Array once");

                commandsInTask[command] = true;
            }

            commandsInTask.All(commandInTask => commandInTask.Value)
            .Should()
            .BeTrue("Expected each element from commands array to be found in a task");
        }
コード例 #2
0
        public void MigratedScriptSetHasExecAndReplacesVariables(string scriptName)
        {
            var scriptMigrationRule = new MigrateScriptsRule();
            ProjectRootElement          mockProj            = ProjectRootElement.Create();
            ProjectPropertyGroupElement commonPropertyGroup = mockProj.AddPropertyGroup();

            var commands = new[] { "%compile:FullTargetFramework%", "%compile:Configuration%" };

            var target = scriptMigrationRule.MigrateScriptSet(
                mockProj,
                commonPropertyGroup,
                commands,
                scriptName,
                IsMultiTFM);

            target.Tasks.Count().Should().Be(commands.Length);

            foreach (var task in target.Tasks)
            {
                var taskCommand  = task.GetParameter("Command");
                var commandIndex = Array.IndexOf(commands, taskCommand);

                commandIndex.Should().Be(
                    -1,
                    "Expected command array elements to be replaced by appropriate msbuild properties");
            }
        }
コード例 #3
0
        public void Migrated_ScriptSet_has_two_MigratedScriptExtensionProperties_for_each_script(string scriptName)
        {
            var scriptMigrationRule     = new MigrateScriptsRule();
            ProjectRootElement mockProj = ProjectRootElement.Create();

            var commands      = new string[] { "compile:FullTargetFramework", "compile:Configuration" };
            var propertyGroup = mockProj.AddPropertyGroup();
            var target        = scriptMigrationRule.MigrateScriptSet(mockProj, propertyGroup, commands,
                                                                     scriptName);

            Console.WriteLine(string.Join(";", propertyGroup.Properties.Select(n => n.Name)));
            propertyGroup.Properties.Count().Should().Be(commands.Length * 2);

            var count = 0;

            foreach (var command in commands)
            {
                count += 1;
                var scriptExtensionProperties =
                    propertyGroup.Properties.Where(p => p.Name.Contains($"MigratedScriptExtension_{scriptName}_{count}")).ToArray();

                scriptExtensionProperties.All(p => p.Value == ".sh" || p.Value == ".cmd").Should().BeTrue();
                scriptExtensionProperties.Count().Should().Be(2);
            }
        }
コード例 #4
0
        public void Migrating_post_scripts_populates_AfterTargets_with_appropriate_target(string scriptName, string targetName)
        {
            var scriptMigrationRule     = new MigrateScriptsRule();
            ProjectRootElement mockProj = ProjectRootElement.Create();
            var commands = new[] { "fakecommand" };

            var target = scriptMigrationRule.MigrateScriptSet(mockProj, mockProj.AddPropertyGroup(), commands, scriptName);

            target.AfterTargets.Should().Be(targetName);
        }
コード例 #5
0
        public void Migrating_scripts_creates_target_with_IsCrossTargettingBuild_not_equal_true_Condition()
        {
            var scriptMigrationRule     = new MigrateScriptsRule();
            ProjectRootElement mockProj = ProjectRootElement.Create();

            var commands = new[] { "compile:FullTargetFramework", "compile:Configuration" };

            var target = scriptMigrationRule.MigrateScriptSet(mockProj, mockProj.AddPropertyGroup(), commands, "prepublish");

            target.Condition.Should().Be(" '$(IsCrossTargetingBuild)' != 'true' ");
        }
コード例 #6
0
        public void Migrating_scripts_throws_on_invalid_ScriptSet()
        {
            var scriptMigrationRule     = new MigrateScriptsRule();
            ProjectRootElement mockProj = ProjectRootElement.Create();

            var commands = new string[] { "fakecommand" };

            Action action = () => scriptMigrationRule.MigrateScriptSet(mockProj, mockProj.AddPropertyGroup(), commands, "invalidScriptSet");

            action.ShouldThrow <MigrationException>()
            .WithMessage("MIGRATE1019::Unsupported Script Event Hook: invalidScriptSet is an unsupported script event hook for project migration");
        }
コード例 #7
0
        public void MigratingScriptsWithSingleTFMDoesNotCreateTargetWithIsCrossTargettingBuild()
        {
            var scriptMigrationRule     = new MigrateScriptsRule();
            ProjectRootElement mockProj = ProjectRootElement.Create();

            var commands = new[] { "compile:FullTargetFramework", "compile:Configuration" };

            var target = scriptMigrationRule.MigrateScriptSet(
                mockProj,
                commands,
                "prepublish",
                false);

            target.Condition.Should().BeEmpty();
        }
コード例 #8
0
        public void MigratingScriptsWithMultiTFMCreatesTargetWithIsCrossTargettingBuildNotEqualTrueCondition()
        {
            var scriptMigrationRule     = new MigrateScriptsRule();
            ProjectRootElement mockProj = ProjectRootElement.Create();

            var commands = new[] { "compile:FullTargetFramework", "compile:Configuration" };

            var target = scriptMigrationRule.MigrateScriptSet(
                mockProj,
                commands,
                "prepublish",
                IsMultiTFM);

            target.Condition.Should().Be(" '$(IsCrossTargetingBuild)' != 'true' ");
        }
コード例 #9
0
        public void MigratingPreScriptsPopulatesBeforeTargetsWithAppropriateTarget(
            string scriptName,
            string targetName)
        {
            var scriptMigrationRule     = new MigrateScriptsRule();
            ProjectRootElement mockProj = ProjectRootElement.Create();
            var commands = new string[] { "fakecommand" };

            var target = scriptMigrationRule.MigrateScriptSet(
                mockProj,
                mockProj.AddPropertyGroup(),
                commands,
                scriptName);

            target.BeforeTargets.Should().Be(targetName);
        }
コード例 #10
0
        public void MigratingPostScriptsPopulatesAfterTargetsWithAppropriateTarget(
            string scriptName,
            string targetName)
        {
            var scriptMigrationRule     = new MigrateScriptsRule();
            ProjectRootElement mockProj = ProjectRootElement.Create();
            var commands = new[] { "fakecommand" };

            var target = scriptMigrationRule.MigrateScriptSet(
                mockProj,
                commands,
                scriptName,
                IsMultiTFM);

            target.AfterTargets.Should().Be(targetName);
        }
コード例 #11
0
        public void PublishIISCommandDoesNotGetMigratedBecauseItIsNowInTheWebSDK()
        {
            var scriptMigrationRule     = new MigrateScriptsRule();
            ProjectRootElement mockProj = ProjectRootElement.Create();

            var commands = new[]
            {
                "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%"
            };

            var target = scriptMigrationRule.MigrateScriptSet(
                mockProj,
                mockProj.AddPropertyGroup(),
                commands,
                "postpublish");

            target.Tasks.Should().BeEmpty();
        }
コード例 #12
0
        public void MigratingScriptsReplacesRazorPrecompileWithProperty()
        {
            var scriptMigrationRule = new MigrateScriptsRule();
            ProjectRootElement          mockProj            = ProjectRootElement.Create();
            ProjectPropertyGroupElement commonPropertyGroup = mockProj.AddPropertyGroup();

            var commands = new string[] { "dotnet razor-precompile --configuration %publish:Configuration% --framework %publish:TargetFramework% --output-path %publish:OutputPath% %publish:ProjectPath%" };

            var target = scriptMigrationRule.MigrateScriptSet(
                mockProj,
                commonPropertyGroup,
                commands,
                "postpublish",
                IsMultiTFM);

            target.Tasks.Should().BeEmpty();
            commonPropertyGroup.Properties.Count().Should().Be(1);
            var propertyElement = commonPropertyGroup.Properties.First();

            propertyElement.Name.Should().Be("MvcRazorCompileOnPublish");
            propertyElement.Value.Should().Be("true");
        }