Exemplo n.º 1
0
        public async void RunMainTask_NoProvider()
        {
            var config = new Dictionary <string, string>();

            var task = new BuildTask(_projectService.Object, _externalServiceService.Object, _externalServiceTypeService.Object, _providerService.Object, _pluginManager.Object, _logger.Object);

            task.SetConfig(config, "working");
            task.Provider = "NotExistBuildProvider";

            var result = await task.RunMainTask(new Dictionary <string, string>());

            Assert.False(result.IsSuccess);
            Assert.Equal("Build provider \"NotExistBuildProvider\" could not be found.", result.ErrorMessage);
        }
Exemplo n.º 2
0
        public async void RunMainTask_AdditionalConfigSecured()
        {
            _pluginManager.Setup(p => p.InvokeTaskProvider(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync((string pluginDll, string pluginArgs, string secretPluginArgs) => new Dictionary <string, object>
            {
                { "outputArtifact", "c:\\test" }
            });
            _pluginManager.Setup(p => p.GetPlugins(It.IsAny <string>())).Returns(new List <PluginItem>
            {
                new PluginItem("FakeBuildProvider", "path/to/FakeBuildProvider.dll", new string[] { "GitHub" })
            });
            _externalServiceService.Setup(p => p.GetExternalServiceByName(It.IsAny <string>())).ReturnsAsync((string name) => new ExternalServiceDto
            {
                Name   = name,
                Config = new Dictionary <string, string>
                {
                    { "AuthToken", "123" }
                }
            });

            var config = new Dictionary <string, string>
            {
                { "GitHubExternalService", "github-test" }
            };

            var task = new BuildTask(_projectService.Object, _externalServiceService.Object, _externalServiceTypeService.Object, _providerService.Object, _pluginManager.Object, _logger.Object);

            task.SetConfig(config, "working");
            task.Provider          = "FakeBuildProvider";
            task.AdditionalConfigs = new Dictionary <string, string>
            {
                { "ConnectionString", "Server=localhost;Database=TestProject;User ID=sa;Password=samprod;" }
            };

            var result = await task.RunMainTask(new Dictionary <string, string>());

            Assert.True(result.IsSuccess);
            Assert.Equal("c:\\test", result.ReturnValue);
            Assert.Equal("The build artifact is located at c:\\test", result.TaskRemarks);

            Assert.Equal(2, task.AdditionalConfigs.Count);
            Assert.Equal(2, task.SecuredAdditionalConfigs.Count);
            Assert.Equal("***", task.SecuredAdditionalConfigs["AuthToken"]);
            Assert.Equal("***", task.SecuredAdditionalConfigs["ConnectionString"]);
            Assert.Equal("123", task.AdditionalConfigs["AuthToken"]);
            Assert.Equal("Server=localhost;Database=TestProject;User ID=sa;Password=samprod;", task.AdditionalConfigs["ConnectionString"]);
        }
Exemplo n.º 3
0
        public async void RunMainTask_Failed()
        {
            _pluginManager.Setup(p => p.InvokeTaskProvider(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync((string pluginDll, string pluginArgs, string secretPluginArgs) => new Dictionary <string, object>
            {
                { "errorMessage", "error-message" }
            });

            var config = new Dictionary <string, string>();

            var task = new BuildTask(_projectService.Object, _externalServiceService.Object, _externalServiceTypeService.Object, _providerService.Object, _pluginManager.Object, _logger.Object);

            task.SetConfig(config, "working");
            task.Provider = "FakeBuildProvider";


            var result = await task.RunMainTask(new Dictionary <string, string>());

            Assert.False(result.IsSuccess);
            Assert.Equal("error-message", result.ErrorMessage);
        }
Exemplo n.º 4
0
        public async void RunMainTask_Success()
        {
            _pluginManager.Setup(p => p.InvokeTaskProvider(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync((string pluginDll, string pluginArgs, string secretPluginArgs) => new Dictionary <string, object>
            {
                { "outputArtifact", "c:\\test" }
            });

            var config = new Dictionary <string, string>();

            var task = new BuildTask(_projectService.Object, _externalServiceService.Object, _externalServiceTypeService.Object, _providerService.Object, _pluginManager.Object, _logger.Object);

            task.SetConfig(config, "working");
            task.Provider = "FakeBuildProvider";

            var result = await task.RunMainTask(new Dictionary <string, string>());

            Assert.True(result.IsSuccess);
            Assert.Equal("c:\\test", result.ReturnValue);
            Assert.Equal("The build artifact is located at c:\\test", result.TaskRemarks);
        }