Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<ItemGroup Label="Microsoft NuGet Packages (Source - All Frameworks)">
<PackageVersion Include="PowerShellStandard.Library" Version="5.1.1" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta6.25358.103" />
<PackageVersion Include="System.CommandLine" Version="2.0.0" />
</ItemGroup>

<ItemGroup Label="Microsoft NuGet Packages (Source)" Condition="'$(TargetFramework)' == 'netstandard2.1'">
Expand Down Expand Up @@ -36,7 +36,6 @@

<ItemGroup Label="External Testing Packages">
<PackageVersion Include="Bogus" Version="35.6.3" />
<PackageVersion Include="FluentAssertions" Version="[6.12.2]" />
<PackageVersion Include="Moq" Version="[4.20.72]" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// Licensed under the MIT License
// -------------------------------------------------------

using System.CommandLine;

namespace AutomationIoC.CommandLine.Application;

internal class AutomationConsoleApplication(
Expand All @@ -13,8 +11,8 @@ internal class AutomationConsoleApplication(
{
private readonly string[] arguments = arguments ?? Environment.GetCommandLineArgs();

public int Run() => new CommandLineConfiguration(rootCommand).Invoke(arguments);
public int Run() => rootCommand.Parse(arguments).Invoke();

public Task<int> RunAsync(CancellationToken cancellationToken = default) =>
new CommandLineConfiguration(rootCommand).InvokeAsync(arguments, cancellationToken);
rootCommand.Parse(arguments).InvokeAsync(cancellationToken: cancellationToken);
}
14 changes: 9 additions & 5 deletions src/CommandLine/test/AutomationCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ public void CreateCommand_ShouldCreateCommandWithAutomationContext()
actualConfigurationValue = testService.GetConfigurationValue(configurationKey);
});

new CommandLineConfiguration(command).Invoke(commandName);
int result = command.Parse(commandName).Invoke();

// Assert
Assert.Equal(0, result);
Assert.Equal(configurationValue, actualConfigurationValue);
}

Expand Down Expand Up @@ -124,10 +125,11 @@ await testService
.ConfigureAwait(false);
});

await new CommandLineConfiguration(command)
.InvokeAsync(commandName, TestContext.Current.CancellationToken);
int result = await command.Parse(commandName)
.InvokeAsync(cancellationToken: TestContext.Current.CancellationToken);

// Assert
Assert.Equal(0, result);
Assert.Equal(configurationValue, actualConfigurationValue);
}

Expand Down Expand Up @@ -202,10 +204,12 @@ await testService
// Act
AutomationCommand.Clone(source: commandOne, target: commandTwo);

await new CommandLineConfiguration(commandTwo)
.InvokeAsync([commandTwoName, "--optionOne", commandOptionValue], TestContext.Current.CancellationToken);
int result = await commandTwo
.Parse([commandTwoName, "--optionOne", commandOptionValue])
.InvokeAsync(cancellationToken: TestContext.Current.CancellationToken);

// Assert
Assert.Equal(0, result);
Assert.Equal(configurationValue, actualConfigurationValue);
Assert.Equal(commandOptionValue, actualOptionValue);
Assert.Equivalent(commandOne.Options, commandTwo.Options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

<ItemGroup>
<PackageReference Include="Bogus" />
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Moq" />
<PackageReference Include="xunit.v3" />
Expand Down
15 changes: 7 additions & 8 deletions src/CommandLine/test/Builder/AutomationConsoleBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using AutomationIoC.CommandLine.Test.TestBed.Commands;
using AutomationIoC.CommandLine.Test.TestBed.Services;
using AutomationIoC.Runtime.Context;
using FluentAssertions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Moq;
Expand All @@ -31,11 +30,11 @@ public void ShouldBuildCommandsWithAddCommand()

// Act
int invocationResult =
new CommandLineConfiguration(configuredRootCommand)
.Invoke(["test", "subcommand", "--optionOne", "testValue"]);
configuredRootCommand.Parse(["test", "subcommand", "--optionOne", "testValue"])
.Invoke();

// Assert
invocationResult.Should().Be(0);
Assert.Equal(0, invocationResult);
}

[Fact]
Expand Down Expand Up @@ -72,11 +71,11 @@ public void ShouldBuildCommandsWithAutomationContext()

// Act
int invocationResult =
new CommandLineConfiguration(configuredRootCommand)
.Invoke(["full-test", "--key", expectedKey]);
configuredRootCommand.Parse(["full-test", "--key", expectedKey])
.Invoke();

// Assert
invocationResult.Should().Be(0);
Assert.Equal(0, invocationResult);
testServiceMock.Verify(service => service.Execute(expectedKeyValue), Times.Once);
}

Expand Down Expand Up @@ -120,7 +119,7 @@ public void ShouldBuildAutomationConsoleApplication()
automationConsoleBuilder.Build().Run();

// Assert
invocationResult.Should().Be(0);
Assert.Equal(0, invocationResult);
testServiceMock.Verify(service => service.Execute(expectedKeyValue), Times.Once);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Moq" />
<PackageReference Include="xunit.v3" />
Expand Down
3 changes: 1 addition & 2 deletions src/PowerShell/Tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ Sample Test

```csharp
using AutomationIoC.PSCmdlets.Tools;
using FluentAssertions;
using Xunit;

public class RequestCardTests
Expand Down Expand Up @@ -138,7 +137,7 @@ public class RequestCardTests

var actualTestData = submitDataCommand.RunCommand<TestData>().First();

actualTestData.Should().BeEquivalentTo(expectedTestData);
Assert.Equivalent(expectedTestData, actualTestData);
}
}
```
Expand Down
1 change: 0 additions & 1 deletion src/Runtime/test/AutomationIoC.Runtime.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

<ItemGroup>
<PackageReference Include="Bogus" />
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Moq" />
<PackageReference Include="xunit.v3" />
Expand Down
11 changes: 3 additions & 8 deletions src/Runtime/test/Dependency/DependencyFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// Licensed under the MIT License
// -------------------------------------------------------

using FluentAssertions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
Expand All @@ -29,11 +28,8 @@ public void GenerateServiceProvider_ShouldBuildRuntimeProviderFromSession()
IServiceProvider actualServiceProvider = DependencyFactory.GenerateServiceProvider(sessionStorage, startup);

// Assert
actualServiceProvider.GetRequiredService<ISessionStorage>()
.Should().BeEquivalentTo(sessionStorage);

actualServiceProvider.GetRequiredService<IAutomationStartup>()
.Should().BeEquivalentTo(startup);
Assert.Equivalent(sessionStorage, actualServiceProvider.GetRequiredService<ISessionStorage>());
Assert.Equivalent(startup, actualServiceProvider.GetRequiredService<IAutomationStartup>());

Assert.NotNull(actualServiceProvider.GetService<IAutomationBinder>());
Assert.NotNull(actualServiceProvider.GetService<IContextBuilder>());
Expand All @@ -49,8 +45,7 @@ public void GenerateServiceProvider_ShouldBuildRuntimeProviderFromSessionStatPro
IServiceProvider actualServiceProvider = DependencyFactory.GenerateServiceProvider(sessionStorage);

// Assert
actualServiceProvider.GetRequiredService<ISessionStorage>()
.Should().BeEquivalentTo(sessionStorage);
Assert.Equivalent(sessionStorage, actualServiceProvider.GetRequiredService<ISessionStorage>());
}

[Fact]
Expand Down