Beispiel #1
0
        public void AddProjectToSolutionPostActionFindsOneProjectToAdd()
        {
            IPostAction postAction = new MockPostAction()
            {
                ActionId = AddProjectsToSolutionPostAction.ActionProcessorId,
                Args     = new Dictionary <string, string>()
                {
                    { "primaryOutputIndexes", "0" }
                }
            };

            ICreationResult creationResult = new MockCreationResult()
            {
                PrimaryOutputs = new List <ICreationPath>()
                {
                    new MockCreationPath()
                    {
                        Path = "outputProj1.csproj"
                    }
                }
            };

            Assert.True(AddProjectsToSolutionPostAction.TryGetProjectFilesToAdd(EngineEnvironmentSettings, postAction, creationResult, string.Empty, out IReadOnlyList <string> foundProjectFiles));
            Assert.Equal(1, foundProjectFiles.Count);
            Assert.Equal(creationResult.PrimaryOutputs[0].Path, foundProjectFiles[0]);
        }
Beispiel #2
0
        public void AddProjectToSolutionPostActionDoesntFindProjectOutOfRange()
        {
            IPostAction postAction = new MockPostAction()
            {
                ActionId = AddProjectsToSolutionPostAction.ActionProcessorId,
                Args     = new Dictionary <string, string>()
                {
                    { "primaryOutputIndexes", "1" }
                }
            };

            ICreationResult creationResult = new MockCreationResult()
            {
                PrimaryOutputs = new List <ICreationPath>()
                {
                    new MockCreationPath()
                    {
                        Path = "outputProj1.csproj"
                    },
                }
            };

            Assert.False(AddProjectsToSolutionPostAction.TryGetProjectFilesToAdd(EngineEnvironmentSettings, postAction, creationResult, string.Empty, out IReadOnlyList <string> foundProjectFiles));
            Assert.Null(foundProjectFiles);
        }
        public void AddProjectToSolutionPostActionFindsMultipleProjectsToAdd()
        {
            string      outputBasePath = FileSystemHelpers.GetNewVirtualizedPath(_engineEnvironmentSettings);
            IPostAction postAction     = new MockPostAction()
            {
                ActionId = AddProjectsToSolutionPostAction.ActionProcessorId,
                Args     = new Dictionary <string, string>()
                {
                    { "primaryOutputIndexes", "0; 2" }
                }
            };

            ICreationResult creationResult = new MockCreationResult(
                primaryOutputs: new[]
            {
                new MockCreationPath(Path.GetFullPath("outputProj1.csproj")),
                new MockCreationPath(Path.GetFullPath("dontFindMe.csproj")),
                new MockCreationPath(Path.GetFullPath("outputProj2.csproj"))
            });

            Assert.True(AddProjectsToSolutionPostAction.TryGetProjectFilesToAdd(postAction, creationResult, outputBasePath, out IReadOnlyList <string>?foundProjectFiles));
            Assert.Equal(2, foundProjectFiles?.Count);
            Assert.Contains(creationResult.PrimaryOutputs[0].Path, foundProjectFiles?.ToList());
            Assert.Contains(creationResult.PrimaryOutputs[2].Path, foundProjectFiles?.ToList());

            Assert.DoesNotContain(creationResult.PrimaryOutputs[1].Path, foundProjectFiles?.ToList());
        }
Beispiel #4
0
        public void CanProcessFailedPostAction()
        {
            var engineEnvironmentSettings = _environmentSettingsHelper.CreateEnvironment(virtualize: true);
            var postActionProcessor       = new CaptureMePostAction(expectedResult: false);

            engineEnvironmentSettings.Components.AddComponent(typeof(IPostActionProcessor), postActionProcessor);
            var postAction = new MockPostAction();
            MockCreationResult creationResult = new MockCreationResult(new List <IPostAction>()
            {
                postAction
            });
            MockCreationEffects creationEffects = new MockCreationEffects();
            var templateCreationResult          = new TemplateCreationResult(
                CreationResultStatus.Success,
                "TestTemplate",
                null,
                creationResult,
                "TestPath",
                creationEffects);

            PostActionDispatcher dispatcher = new PostActionDispatcher(
                engineEnvironmentSettings,
                new NewCommandCallbacks(),
                () => string.Empty);

            var result = dispatcher.Process(templateCreationResult, isDryRun: false, AllowRunScripts.Prompt);

            Assert.Equal(PostActionExecutionStatus.Failure, result);
            Assert.Equal(engineEnvironmentSettings, postActionProcessor.Calls.Single().EngineEnvironmentSettings);
            Assert.Equal(postAction, postActionProcessor.Calls.Single().PostAction);
            Assert.Equal(creationEffects, postActionProcessor.Calls.Single().CreationEffects);
            Assert.Equal(creationResult, postActionProcessor.Calls.Single().CreationResult);
            Assert.Equal("TestPath", postActionProcessor.Calls.Single().OutputPath);
        }
        public void AddProjectToSolutionPostActionWithoutPrimaryOutputIndexesWithOutputBasePath()
        {
            string outputBasePath = FileSystemHelpers.GetNewVirtualizedPath(EngineEnvironmentSettings);

            IPostAction postAction = new MockPostAction()
            {
                ActionId = AddProjectsToSolutionPostAction.ActionProcessorId,
                Args     = new Dictionary <string, string>()
            };

            ICreationResult creationResult = new MockCreationResult()
            {
                PrimaryOutputs = new List <ICreationPath>()
                {
                    new MockCreationPath()
                    {
                        Path = "outputProj1.csproj"
                    },
                    new MockCreationPath()
                    {
                        Path = "outputProj2.csproj"
                    },
                }
            };
            string outputFileFullPath0 = Path.Combine(outputBasePath, creationResult.PrimaryOutputs[0].Path);
            string outputFileFullPath1 = Path.Combine(outputBasePath, creationResult.PrimaryOutputs[1].Path);

            Assert.True(AddProjectsToSolutionPostAction.TryGetProjectFilesToAdd(EngineEnvironmentSettings, postAction, creationResult, outputBasePath, out IReadOnlyList <string> foundProjectFiles));
            Assert.Equal(2, foundProjectFiles.Count);
            Assert.Contains(outputFileFullPath0, foundProjectFiles.ToList());
            Assert.Contains(outputFileFullPath1, foundProjectFiles.ToList());
        }
Beispiel #6
0
        public void CanProcessPostActionThrowingException()
        {
            var engineEnvironmentSettings = _environmentSettingsHelper.CreateEnvironment(virtualize: true);

            engineEnvironmentSettings.Components.AddComponent(typeof(IPostActionProcessor), new ThrowExceptionPostAction());
            var postAction = new MockPostAction();

            MockCreationResult creationResult = new MockCreationResult(new List <IPostAction>()
            {
                postAction
            });
            MockCreationEffects creationEffects = new MockCreationEffects();
            var templateCreationResult          = new TemplateCreationResult(
                CreationResultStatus.Success,
                "TestTemplate",
                null,
                creationResult,
                "TestPath",
                creationEffects);

            PostActionDispatcher dispatcher = new PostActionDispatcher(
                engineEnvironmentSettings,
                new NewCommandCallbacks(),
                () => string.Empty);

            var result = dispatcher.Process(templateCreationResult, isDryRun: false, AllowRunScripts.Yes);

            Assert.Equal(PostActionExecutionStatus.Failure, result);
        }
Beispiel #7
0
        public void CanContinueOnErrorWhenConfigured()
        {
            var engineEnvironmentSettings = _environmentSettingsHelper.CreateEnvironment(virtualize: true);

            var trueProcessorGuid  = Guid.NewGuid();
            var falseProcessorGuid = Guid.NewGuid();
            var trueProcessor      = new CaptureMePostAction(expectedResult: true, guid: trueProcessorGuid);
            var falseProcessor     = new CaptureMePostAction(expectedResult: false, guid: falseProcessorGuid);

            engineEnvironmentSettings.Components.AddComponent(typeof(IPostActionProcessor), trueProcessor);
            engineEnvironmentSettings.Components.AddComponent(typeof(IPostActionProcessor), falseProcessor);

            var postAction1 = new MockPostAction
            {
                ActionId        = falseProcessorGuid,
                ContinueOnError = true
            };
            var postAction2 = new MockPostAction
            {
                ActionId        = trueProcessorGuid,
                ContinueOnError = true
            };

            MockCreationResult creationResult = new MockCreationResult(new List <IPostAction>()
            {
                postAction1, postAction2
            });
            MockCreationEffects creationEffects = new MockCreationEffects();
            var templateCreationResult          = new TemplateCreationResult(
                CreationResultStatus.Success,
                "TestTemplate",
                null,
                creationResult,
                "TestPath",
                creationEffects);

            PostActionDispatcher dispatcher = new PostActionDispatcher(
                engineEnvironmentSettings,
                new NewCommandCallbacks(),
                () => string.Empty);

            var result = dispatcher.Process(templateCreationResult, isDryRun: false, AllowRunScripts.Yes);

            // in case continue on error is true, success status is returned on failure
            Assert.Equal(PostActionExecutionStatus.Success, result);

            //2 post actions were executed
            Assert.Equal(1, trueProcessor.Calls.Count);
            Assert.Equal(1, falseProcessor.Calls.Count);
            Assert.Equal(postAction1, falseProcessor.Calls[0].PostAction);
            Assert.Equal(postAction2, trueProcessor.Calls[0].PostAction);
        }
Beispiel #8
0
        public void CanProcessRunScriptPostActionAndSuccessPostAction_WhenRunScriptPrompt_No()
        {
            var engineEnvironmentSettings = _environmentSettingsHelper.CreateEnvironment(virtualize: true);
            var postActionProcessor       = new CaptureMePostAction(expectedResult: true);

            engineEnvironmentSettings.Components.AddComponent(typeof(IPostActionProcessor), postActionProcessor);

            engineEnvironmentSettings.Components.AddComponent(typeof(IPostActionProcessor), new ProcessStartPostActionProcessor());
            var postAction1 = new MockPostAction
            {
                ActionId = ProcessStartPostActionProcessor.ActionProcessorId,
                //the post action will fail, but that is OK for test purpose
                Args = new Dictionary <string, string>()
                {
                    { "executable", "do-not-exist" }
                },
                ContinueOnError = true
            };

            var postAction2 = new MockPostAction
            {
                ActionId        = Guid.Empty, //CaptureMePostAction
                ContinueOnError = true
            };

            MockCreationResult creationResult = new MockCreationResult(new List <IPostAction>()
            {
                postAction1, postAction2
            });
            MockCreationEffects creationEffects = new MockCreationEffects();
            var templateCreationResult          = new TemplateCreationResult(
                CreationResultStatus.Success,
                "TestTemplate",
                null,
                creationResult,
                Path.GetTempPath(),
                creationEffects);

            PostActionDispatcher dispatcher = new PostActionDispatcher(
                engineEnvironmentSettings,
                new NewCommandCallbacks(),
                () => "N"); // the user forbids to run post action

            var result = dispatcher.Process(templateCreationResult, isDryRun: false, AllowRunScripts.Prompt);

            Assert.Equal(PostActionExecutionStatus.Cancelled, result);
            Assert.NotEqual(PostActionExecutionStatus.Failure, result);
            Assert.Single(postActionProcessor.Calls);
            Assert.Equal(postAction2, postActionProcessor.Calls.Single().PostAction);
        }
        public void AddProjectToSolutionPostActionDoesntFindProjectOutOfRange()
        {
            IPostAction postAction = new MockPostAction()
            {
                ActionId = AddProjectsToSolutionPostAction.ActionProcessorId,
                Args     = new Dictionary <string, string>()
                {
                    { "primaryOutputIndexes", "1" }
                }
            };

            ICreationResult creationResult = new MockCreationResult(primaryOutputs: new[] { new MockCreationPath("outputProj1.csproj") });

            Assert.False(AddProjectsToSolutionPostAction.TryGetProjectFilesToAdd(postAction, creationResult, string.Empty, out IReadOnlyList <string>?foundProjectFiles));
            Assert.Null(foundProjectFiles);
        }
Beispiel #10
0
        public void CanProcessRunScriptPostAction_DryRun()
        {
            var engineEnvironmentSettings = _environmentSettingsHelper.CreateEnvironment(virtualize: true);

            engineEnvironmentSettings.Components.AddComponent(typeof(IPostActionProcessor), new ProcessStartPostActionProcessor());
            var postAction = new MockPostAction
            {
                ActionId = ProcessStartPostActionProcessor.ActionProcessorId,
                //the post action will fail, but that is OK for test purpose
                Args = new Dictionary <string, string>()
                {
                    { "executable", "do-not-exist" }
                }
            };

            MockCreationResult creationResult = new MockCreationResult(new List <IPostAction>()
            {
                postAction
            });
            MockCreationEffects creationEffects = new MockCreationEffects();
            var templateCreationResult          = new TemplateCreationResult(
                CreationResultStatus.Success,
                "TestTemplate",
                null,
                creationResult,
                Path.GetTempPath(),
                creationEffects);

            PostActionDispatcher dispatcher = new PostActionDispatcher(
                engineEnvironmentSettings,
                new NewCommandCallbacks(),
                () => "N"); // the user forbids to run post action

            //run script setting doesn't matter for dry run
            var result = dispatcher.Process(templateCreationResult, isDryRun: true, AllowRunScripts.Prompt);

            Assert.Equal(PostActionExecutionStatus.Success, result);
            result = dispatcher.Process(templateCreationResult, isDryRun: true, AllowRunScripts.Yes);
            Assert.Equal(PostActionExecutionStatus.Success, result);
            result = dispatcher.Process(templateCreationResult, isDryRun: true, AllowRunScripts.No);
            Assert.Equal(PostActionExecutionStatus.Success, result);
        }
Beispiel #11
0
        public void AddProjectToSolutionPostActionFindsMultipleProjectsToAdd()
        {
            IPostAction postAction = new MockPostAction()
            {
                ActionId = AddProjectsToSolutionPostAction.ActionProcessorId,
                Args     = new Dictionary <string, string>()
                {
                    { "primaryOutputIndexes", "0; 2" }
                }
            };

            ICreationResult creationResult = new MockCreationResult()
            {
                PrimaryOutputs = new List <ICreationPath>()
                {
                    new MockCreationPath()
                    {
                        Path = "outputProj1.csproj"
                    },
                    new MockCreationPath()
                    {
                        Path = "dontFindMe.csproj"
                    },
                    new MockCreationPath()
                    {
                        Path = "outputProj2.csproj"
                    },
                }
            };

            Assert.True(AddProjectsToSolutionPostAction.TryGetProjectFilesToAdd(_engineEnvironmentSettings, postAction, creationResult, string.Empty, out IReadOnlyList <string> foundProjectFiles));
            Assert.Equal(2, foundProjectFiles.Count);
            Assert.Contains(creationResult.PrimaryOutputs[0].Path, foundProjectFiles.ToList());
            Assert.Contains(creationResult.PrimaryOutputs[2].Path, foundProjectFiles.ToList());

            Assert.DoesNotContain(creationResult.PrimaryOutputs[1].Path, foundProjectFiles.ToList());
        }