public async void RunMainTask_NoProvider()
        {
            var config = new Dictionary <string, string>();

            var task = new DeleteHostingTask(_projectService.Object, _externalServiceService.Object, _externalServiceTypeService.Object, _providerService.Object, _taskProviderManager.Object, _logger.Object);

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

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

            Assert.False(result.IsSuccess);
            Assert.Equal("Deploy provider \"NotExistHostingProvider\" could not be found.", result.ErrorMessage);
        }
        public async void RunMainTask_AdditionalConfigSecured()
        {
            _taskProviderManager.Setup(p => p.InvokeTaskProvider(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync((string taskProviderDll, string taskProviderArgs, string secretProviderArgs) => new Dictionary <string, object>
            {
                { "deletedHostLocation", "https://test.azurewebsites.net" }
            });
            _taskProviderManager.Setup(p => p.GetTaskProviders(It.IsAny <string>())).Returns(new List <TaskProviderItem>
            {
                new TaskProviderItem("FakeHostingProvider", "path/to/FakeHostingProvider.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 DeleteHostingTask(_projectService.Object, _externalServiceService.Object, _externalServiceTypeService.Object, _providerService.Object, _taskProviderManager.Object, _logger.Object);

            task.SetConfig(config, "working");
            task.Provider          = "FakeHostingProvider";
            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("https://test.azurewebsites.net", result.ReturnValue);
            Assert.Equal("The hosting url https://test.azurewebsites.net has been deleted", 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"]);
        }
        public async void RunMainTask_Failed()
        {
            _taskProviderManager.Setup(p => p.InvokeTaskProvider(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync((string taskProviderDll, string taskProviderArgs, string secretProviderArgs) => new Dictionary <string, object>
            {
                { "errorMessage", "error-message" }
            });

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

            var task = new DeleteHostingTask(_projectService.Object, _externalServiceService.Object, _externalServiceTypeService.Object, _providerService.Object, _taskProviderManager.Object, _logger.Object);

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

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

            Assert.False(result.IsSuccess);
            Assert.Equal("error-message", result.ErrorMessage);
        }
        public async void RunMainTask_Success()
        {
            _taskProviderManager.Setup(p => p.InvokeTaskProvider(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync((string taskProviderDll, string taskProviderArgs, string secretProviderArgs) => new Dictionary <string, object>
            {
                { "deletedHostLocation", "https://test.azurewebsites.net" }
            });

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

            var task = new DeleteHostingTask(_projectService.Object, _externalServiceService.Object, _externalServiceTypeService.Object, _providerService.Object, _taskProviderManager.Object, _logger.Object);

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

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

            Assert.True(result.IsSuccess);
            Assert.Equal("https://test.azurewebsites.net", result.ReturnValue);
            Assert.Equal("The hosting url https://test.azurewebsites.net has been deleted", result.TaskRemarks);
        }