From 6b1c8690f0f7b06e059ce62d104d16fd2ca39592 Mon Sep 17 00:00:00 2001 From: khdevnet Date: Tue, 15 Aug 2023 11:09:40 +0200 Subject: [PATCH] [main] Update configurations Branch: [main] --- src/LightBDD.ScenarioSync.Cli/Program.cs | 36 +++---------------- src/LightBDD.ScenarioSync.Cli/Startup.cs | 1 + .../App/Commands/InitAppCommand.cs | 26 ++++++++++++++ .../App/Config/AppConfig.cs | 2 +- .../App/Config/Config.cs | 3 -- .../Cli/App_command_line_tests.cs | 24 +++---------- 6 files changed, 36 insertions(+), 56 deletions(-) create mode 100644 src/LightBDD.ScenarioSync.Core/App/Commands/InitAppCommand.cs delete mode 100644 src/LightBDD.ScenarioSync.Core/App/Config/Config.cs diff --git a/src/LightBDD.ScenarioSync.Cli/Program.cs b/src/LightBDD.ScenarioSync.Cli/Program.cs index 1540d64..7911f99 100644 --- a/src/LightBDD.ScenarioSync.Cli/Program.cs +++ b/src/LightBDD.ScenarioSync.Cli/Program.cs @@ -14,7 +14,7 @@ public static void Main(string[] args) { var rootCommand = new RootCommand("A cli tool for automatically associate automated tests with test cases."); - Command initCommand = CreateInitSubCommand("init", $"This command will create a ScenarioSync configuration file {AppConfig.FileName}"); + Command initCommand = CreateSubCommand("init", $"This command will create a ScenarioSync configuration file {AppConfig.FilePath}"); Command pushCommand = CreateSubCommand("push", "Import scenarios to Azure Devops Test Suite."); Command cleanCommand = CreateSubCommand("clean", "Clean imported scenarios in Azure Devops."); @@ -24,41 +24,13 @@ public static void Main(string[] args) rootCommand.Invoke(args); } - private static Command CreateInitSubCommand(string subCommand, string description) - { - var config = new Option("--config", () => AppConfig.FilePath, description: "ScenarioSync config file path") { IsRequired = false }; - var initCommand = new Command(subCommand, description) - { - config - }; - - initCommand.Handler = CommandHandler.Create((string config) => - { - new AppConfig(config) - .CreateConfig( - new AppArguments( - "https://dev.azure.com/organization-name/project-name", - "personal token with permissions TestManagement write&read, WorkItems write&read", - 1, - "./Reports/FeaturesReport.xml") - ); - }); - - return initCommand; - } - private static Command CreateSubCommand(string subCommand, string description) where TCommand : IAppCommand { - var config = new Option("--config", () => AppConfig.FilePath, description: "ScenarioSync config file path") { IsRequired = false }; - - var syncCommand = new Command(subCommand, description) - { - config - }; + var syncCommand = new Command(subCommand, description); - syncCommand.Handler = CommandHandler.Create((string config) => + syncCommand.Handler = CommandHandler.Create(() => { - AppArguments arguments = new AppConfig(config).ReadConfig(); + AppArguments arguments = new AppConfig().ReadConfig(); Task syncTask = RunSyncCommand(arguments); syncTask.GetAwaiter().GetResult(); diff --git a/src/LightBDD.ScenarioSync.Cli/Startup.cs b/src/LightBDD.ScenarioSync.Cli/Startup.cs index 6675555..2f09bb1 100644 --- a/src/LightBDD.ScenarioSync.Cli/Startup.cs +++ b/src/LightBDD.ScenarioSync.Cli/Startup.cs @@ -10,6 +10,7 @@ public class Startup { public void ConfigureServices(IServiceCollection serviceCollections) { + serviceCollections.AddScoped(); serviceCollections.AddScoped(); serviceCollections.AddScoped(); SourceDependencyContainer.RegisterServices(serviceCollections); diff --git a/src/LightBDD.ScenarioSync.Core/App/Commands/InitAppCommand.cs b/src/LightBDD.ScenarioSync.Core/App/Commands/InitAppCommand.cs new file mode 100644 index 0000000..ebc64cb --- /dev/null +++ b/src/LightBDD.ScenarioSync.Core/App/Commands/InitAppCommand.cs @@ -0,0 +1,26 @@ +using LightBDD.ScenarioSync.Core.App.Config; + +namespace LightBDD.ScenarioSync.Core.App.Commands; + +public class InitAppCommand : IAppCommand +{ + private readonly AppConfig _appConfig; + + public InitAppCommand(AppConfig appConfig) + { + _appConfig = appConfig; + } + + public Task RunAsync(AppArguments arguments) + { + _appConfig.CreateConfig( + new AppArguments( + "https://dev.azure.com/organization-name/project-name", + "personal token with permissions TestManagement write&read, WorkItems write&read", + 1, + "./Reports/FeaturesReport.xml") + ); + + return Task.CompletedTask; + } +} \ No newline at end of file diff --git a/src/LightBDD.ScenarioSync.Core/App/Config/AppConfig.cs b/src/LightBDD.ScenarioSync.Core/App/Config/AppConfig.cs index 99678f6..7bba164 100644 --- a/src/LightBDD.ScenarioSync.Core/App/Config/AppConfig.cs +++ b/src/LightBDD.ScenarioSync.Core/App/Config/AppConfig.cs @@ -8,7 +8,7 @@ public class AppConfig public static string FilePath = $".{Path.DirectorySeparatorChar}{FileName}"; public const string FileName = "scenariosync.json.user"; - public AppConfig(string configPath) + public AppConfig(string configPath = null) { _configPath = string.IsNullOrEmpty(configPath) ? FilePath : configPath; } diff --git a/src/LightBDD.ScenarioSync.Core/App/Config/Config.cs b/src/LightBDD.ScenarioSync.Core/App/Config/Config.cs deleted file mode 100644 index 40a48f8..0000000 --- a/src/LightBDD.ScenarioSync.Core/App/Config/Config.cs +++ /dev/null @@ -1,3 +0,0 @@ -namespace LightBDD.ScenarioSync.Core.App.Config; - -public record Config(ArgumentsOptions Arguments); \ No newline at end of file diff --git a/test/LightBDD.ScenarioSync.IntegrationTest/Cli/App_command_line_tests.cs b/test/LightBDD.ScenarioSync.IntegrationTest/Cli/App_command_line_tests.cs index a0f8ebe..eb2a4db 100644 --- a/test/LightBDD.ScenarioSync.IntegrationTest/Cli/App_command_line_tests.cs +++ b/test/LightBDD.ScenarioSync.IntegrationTest/Cli/App_command_line_tests.cs @@ -7,38 +7,23 @@ namespace LightBDD.ScenarioSync.IntegrationTest.Cli; public class App_command_line_tests { - private static char PathSep = Path.DirectorySeparatorChar; - [Fact] public void Run_init_command() { var args = new[] { - "init", - "--config", Path.Combine($"..{PathSep}..{PathSep}..{PathSep}..{PathSep}", AppConfig.FileName) + "init" }; Program.Main(args); } - [Fact] - public void Run_push_no_arguments_command() - { - var args = new[] - { - "push" - }; - - Program.Main(args); - } - [Fact] public void Run_push_command() { var args = new[] { - "push", - "--config", Path.Combine($"..{PathSep}..{PathSep}..{PathSep}..{PathSep}", AppConfig.FileName) + "push" }; Program.Main(args); @@ -49,10 +34,9 @@ public void Run_clean_command() { var args = new[] { - "clean", - "--config", Path.Combine($"..{PathSep}..{PathSep}..{PathSep}..{PathSep}", AppConfig.FileName) + "clean" }; - + Program.Main(args); } } \ No newline at end of file