Skip to content

Commit d86ebfd

Browse files
committed
Fix CompareCommandSettings parameterless constructor issue and improve integration tests
- Remove 'required' keyword from CompareCommandSettings properties to allow Spectre.Console.Cli to instantiate the class - Add proper null validation in the Validate method instead - Fix integration tests to use correct 'compare' command syntax - Add proper test categories [Trait("Category", "Integration")] to integration tests - Fix path resolution in FindExecutablePath method (5 levels up instead of 4) - Replace silent test skipping with proper assertions that fail when prerequisites aren't met - All 345 tests now pass including 27 integration tests Fixes the CLI error: 'Could not resolve type CompareCommandSettings - No parameterless constructor defined'
1 parent 5d55f62 commit d86ebfd

File tree

3 files changed

+83
-151
lines changed

3 files changed

+83
-151
lines changed

src/DotNetApiDiff/Commands/CompareCommand.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ public class CompareCommandSettings : CommandSettings
1919
{
2020
[CommandArgument(0, "<sourceAssembly>")]
2121
[Description("Path to the source/baseline assembly")]
22-
required public string SourceAssemblyPath { get; init; }
22+
public string? SourceAssemblyPath { get; init; }
2323

2424
[CommandArgument(1, "<targetAssembly>")]
2525
[Description("Path to the target/current assembly")]
26-
required public string TargetAssemblyPath { get; init; }
26+
public string? TargetAssemblyPath { get; init; }
2727

2828
[CommandOption("-c|--config <configFile>")]
2929
[Description("Path to configuration file")]
@@ -95,12 +95,22 @@ public CompareCommand(IServiceProvider serviceProvider, ILogger<CompareCommand>
9595
public override ValidationResult Validate([NotNull] CommandContext context, [NotNull] CompareCommandSettings settings)
9696
{
9797
// Validate source assembly path
98+
if (string.IsNullOrEmpty(settings.SourceAssemblyPath))
99+
{
100+
return ValidationResult.Error("Source assembly path is required");
101+
}
102+
98103
if (!File.Exists(settings.SourceAssemblyPath))
99104
{
100105
return ValidationResult.Error($"Source assembly file not found: {settings.SourceAssemblyPath}");
101106
}
102107

103108
// Validate target assembly path
109+
if (string.IsNullOrEmpty(settings.TargetAssemblyPath))
110+
{
111+
return ValidationResult.Error("Target assembly path is required");
112+
}
113+
104114
if (!File.Exists(settings.TargetAssemblyPath))
105115
{
106116
return ValidationResult.Error($"Target assembly file not found: {settings.TargetAssemblyPath}");
@@ -203,7 +213,7 @@ public override int Execute([NotNull] CommandContext context, [NotNull] CompareC
203213

204214
try
205215
{
206-
sourceAssembly = assemblyLoader.LoadAssembly(settings.SourceAssemblyPath);
216+
sourceAssembly = assemblyLoader.LoadAssembly(settings.SourceAssemblyPath!);
207217
}
208218
catch (Exception ex)
209219
{
@@ -216,7 +226,7 @@ public override int Execute([NotNull] CommandContext context, [NotNull] CompareC
216226

217227
try
218228
{
219-
targetAssembly = assemblyLoader.LoadAssembly(settings.TargetAssemblyPath);
229+
targetAssembly = assemblyLoader.LoadAssembly(settings.TargetAssemblyPath!);
220230
}
221231
catch (Exception ex)
222232
{

0 commit comments

Comments
 (0)