Skip to content

Commit

Permalink
[main] Update configurations
Browse files Browse the repository at this point in the history
Branch: [main]
  • Loading branch information
antshc committed Aug 15, 2023
1 parent 4f80c52 commit 6b1c869
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 56 deletions.
36 changes: 4 additions & 32 deletions src/LightBDD.ScenarioSync.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<InitAppCommand>("init", $"This command will create a ScenarioSync configuration file {AppConfig.FilePath}");
Command pushCommand = CreateSubCommand<PushAppCommand>("push", "Import scenarios to Azure Devops Test Suite.");
Command cleanCommand = CreateSubCommand<CleanAppCommand>("clean", "Clean imported scenarios in Azure Devops.");

Expand All @@ -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<string>("--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<TCommand>(string subCommand, string description) where TCommand : IAppCommand
{
var config = new Option<string>("--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<TCommand>(arguments);

syncTask.GetAwaiter().GetResult();
Expand Down
1 change: 1 addition & 0 deletions src/LightBDD.ScenarioSync.Cli/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class Startup
{
public void ConfigureServices(IServiceCollection serviceCollections)
{
serviceCollections.AddScoped<InitAppCommand>();
serviceCollections.AddScoped<PushAppCommand>();
serviceCollections.AddScoped<CleanAppCommand>();
SourceDependencyContainer.RegisterServices(serviceCollections);
Expand Down
26 changes: 26 additions & 0 deletions src/LightBDD.ScenarioSync.Core/App/Commands/InitAppCommand.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 1 addition & 1 deletion src/LightBDD.ScenarioSync.Core/App/Config/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 0 additions & 3 deletions src/LightBDD.ScenarioSync.Core/App/Config/Config.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}

0 comments on commit 6b1c869

Please sign in to comment.