Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/upgrade-spectre-console.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"SolarWinds.Changesets": Patch
---

Upgrade Spectre.Console to 0.56.0 and Spectre.Console.Cli to 0.55.0 (with matching testing packages). Adapts to the new command `ExecuteAsync(CommandContext, CancellationToken)` signature and the move of `CommandAppTester` into the new `Spectre.Console.Cli.Testing` package.
7 changes: 4 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
<PackageVersion Include="NUnit" Version="4.4.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="5.1.0" />
<PackageVersion Include="NUnit.Analyzers" Version="4.10.0" />
<PackageVersion Include="Spectre.Console" Version="0.50.0" />
<PackageVersion Include="Spectre.Console" Version="0.56.0" />
<PackageVersion Include="Spectre.Console.Analyzer" Version="1.0.0" />
<PackageVersion Include="Spectre.Console.Cli" Version="0.50.0" />
<PackageVersion Include="Spectre.Console.Testing" Version="0.50.0" />
<PackageVersion Include="Spectre.Console.Cli" Version="0.55.0" />
<PackageVersion Include="Spectre.Console.Cli.Testing" Version="0.55.0" />
<PackageVersion Include="Spectre.Console.Testing" Version="0.56.0" />
Comment thread
JohnCampionJr marked this conversation as resolved.
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ IConfigurationService configurationService
/// Executes Init command.
/// </summary>
/// <param name="context">Command context.</param>
/// <param name="cancellationToken">A token to observe for cancellation requests.</param>
/// <returns>
/// An integer indicating the result of the initialization:
/// - 0: Initialization succeeded.
/// - 1: Directory existed but config file was missing; default config created.
/// - 2: Changesets already initialized; no further action needed.
/// </returns>
public override async Task<int> ExecuteAsync(CommandContext context)
protected override async Task<int> ExecuteAsync(CommandContext context, CancellationToken cancellationToken)
{
if (Directory.Exists(Constants.ChangesetDirectoryFullPath))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected ConfigurationCommandBase(IConfigurationService configurationService)
_configurationService = configurationService;
}

public sealed override async Task<int> ExecuteAsync(CommandContext context)
protected sealed override async Task<int> ExecuteAsync(CommandContext context, CancellationToken cancellationToken)
{
if (!Directory.Exists(Constants.ChangesetDirectoryFullPath))
{
Expand Down
30 changes: 16 additions & 14 deletions tests/SolarWinds.Changesets.Tests/Add/AddCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using SolarWinds.Changesets.Infrastructure;
using SolarWinds.Changesets.Shared;
using Spectre.Console.Cli;
using Spectre.Console.Cli.Testing;
using Spectre.Console.Testing;

namespace SolarWinds.Changesets.Tests.Add;
Expand All @@ -14,8 +15,8 @@ namespace SolarWinds.Changesets.Tests.Add;
internal sealed class AddCommandTests
{
private readonly Mock<IProjectFileNamesLocator> _projectFileNameLocator = new();
private TypeRegistrar _typeRegistrar = null!;
private CommandAppTester _app = null!;
private TestConsole _console = null!;
private ChangesetsRepository _changesetsRepository = null!;

[SetUp]
Expand All @@ -29,8 +30,8 @@ public void SetUp()
_changesetsRepository = new ChangesetsRepository();
serviceCollection.AddSingleton<IChangesetsRepository>(_changesetsRepository);

TypeRegistrar typeRegistrar = new(serviceCollection);
_app = new(typeRegistrar);
_typeRegistrar = new(serviceCollection);
_app = new(_typeRegistrar);
_app.Configure(config =>
{
config
Expand All @@ -51,27 +52,28 @@ public async Task AddCommand_HappyPath_ChangesetIsCreated()
// Arrange
_projectFileNameLocator.Setup(x => x.GetProjectFileNames(It.IsAny<string>())).Returns(["A", "B"]);

_console = new();
_console.Interactive();
CommandAppTester initApp = new(_typeRegistrar);
initApp.SetDefaultCommand<InitChangesetCommand>();
await initApp.RunAsync();
Comment on lines +55 to +57

_app.Console.Interactive();

// MultiSelectionPrompt - Select 2nd project 'B'
_console.Input.PushKey(ConsoleKey.DownArrow);
_console.Input.PushKey(ConsoleKey.Spacebar);
_console.Input.PushKey(ConsoleKey.Enter);
_app.Console.Input.PushKey(ConsoleKey.DownArrow);
_app.Console.Input.PushKey(ConsoleKey.Spacebar);
_app.Console.Input.PushKey(ConsoleKey.Enter);

// SelectionPrompt - Select BumpType 'Minor'
_console.Input.PushKey(ConsoleKey.DownArrow);
_console.Input.PushKey(ConsoleKey.Enter);
_app.Console.Input.PushKey(ConsoleKey.DownArrow);
_app.Console.Input.PushKey(ConsoleKey.Enter);

// TextPrompt - Describe changes
string expectedDescription = "Test example description";
_console.Input.PushTextWithEnter(expectedDescription);
_app.Console.Input.PushTextWithEnter(expectedDescription);

// Act
_app.SetDefaultCommand<InitChangesetCommand>();
await _app.RunAsync();
_app.SetDefaultCommand<AddChangesetCommand>();
CommandAppResult result = _app.RunWithCustomConsole([], _console);
CommandAppResult result = await _app.RunAsync();

// Assert
result.ExitCode.Should().Be(ResultCodes.Success, result.Output);
Expand Down

This file was deleted.

24 changes: 14 additions & 10 deletions tests/SolarWinds.Changesets.Tests/Init/InitCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
using SolarWinds.Changesets.Commands.Init;
using SolarWinds.Changesets.Infrastructure;
using SolarWinds.Changesets.Shared;
using Spectre.Console.Testing;
using Spectre.Console.Cli.Testing;

namespace SolarWinds.Changesets.Tests.Init;

[TestFixture]
internal sealed class InitCommandTests
{
private CommandAppTester _app = null!;
private TypeRegistrar _typeRegistrar = null!;

[SetUp]
public void SetUp()
Expand All @@ -19,10 +19,14 @@ public void SetUp()

ServiceCollection serviceCollection = new();
serviceCollection.AddSingleton<IConfigurationService, ConfigurationService>();
TypeRegistrar typeRegistrar = new(serviceCollection);
CommandAppTester app = new(typeRegistrar);
_typeRegistrar = new(serviceCollection);
}

private CommandAppTester CreateApp()
{
CommandAppTester app = new(_typeRegistrar);
app.SetDefaultCommand<InitChangesetCommand>();
_app = app;
return app;
}

[TearDown]
Expand All @@ -35,7 +39,7 @@ public void TearDown()
public void InitCommand_HappyPath_FolderAndFilesAreCreated()
{
// Arrange, Act
CommandAppResult result = _app.Run();
CommandAppResult result = CreateApp().Run();

// Assert
AssertInitCommand(result, ResultCodes.Success);
Expand All @@ -45,23 +49,23 @@ public void InitCommand_HappyPath_FolderAndFilesAreCreated()
public void InitCommand_HappyPathRunTwice_ConfigIsMissingAndWillBeGenerated()
{
// Arrange, Act, Assert
CommandAppResult result = _app.Run();
CommandAppResult result = CreateApp().Run();
AssertInitCommand(result, ResultCodes.Success);

File.Delete(Constants.ChangesetConfigFileFullPath);

CommandAppResult result2 = _app.Run();
CommandAppResult result2 = CreateApp().Run();
AssertInitCommand(result2, ResultCodes.ConfigFileWasGenerated);
}

[Test]
public void InitCommand_HappyPathRunTwice_ConsoleContainMessageThatAlreadyExists()
{
// Arrange, Act, Assert
CommandAppResult result = _app.Run();
CommandAppResult result = CreateApp().Run();
AssertInitCommand(result, ResultCodes.Success);

CommandAppResult result2 = _app.Run();
CommandAppResult result2 = CreateApp().Run();
AssertInitCommand(result2, ResultCodes.AlreadyInitialized);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using SolarWinds.Changesets.Commands.Publish.Services;
using SolarWinds.Changesets.Infrastructure;
using SolarWinds.Changesets.Shared;
using Spectre.Console.Testing;
using Spectre.Console.Cli.Testing;

namespace SolarWinds.Changesets.Tests.Publish;

Expand All @@ -31,9 +31,12 @@ public void SetUp()
_configurationServiceMock.Setup(x => x.GetConfigAsync(It.IsAny<string>())).Returns(Task.FromResult(new ChangesetConfig()));

TypeRegistrar typeRegistrar = new(serviceCollection);

CommandAppTester initApp = new(typeRegistrar);
initApp.SetDefaultCommand<InitChangesetCommand>();
initApp.Run();
Comment on lines 33 to +37

_app = new(typeRegistrar);
_app.SetDefaultCommand<InitChangesetCommand>();
_app.Run();
_app.SetDefaultCommand<PublishChangesetCommand>();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Spectre.Console.Cli.Testing" />
<PackageReference Include="Spectre.Console.Testing" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using SolarWinds.Changesets.Commands.Status;
using SolarWinds.Changesets.Infrastructure;
using SolarWinds.Changesets.Shared;
using Spectre.Console.Testing;
using Spectre.Console.Cli.Testing;

namespace SolarWinds.Changesets.Tests.Status;

Expand All @@ -23,9 +23,12 @@ public void SetUp()
serviceCollection.AddSingleton(_changesetsRepositoryMock.Object);

TypeRegistrar typeRegistrar = new(serviceCollection);

CommandAppTester initApp = new(typeRegistrar);
initApp.SetDefaultCommand<InitChangesetCommand>();
initApp.Run();
Comment on lines 25 to +29

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are left unchanged from prior code, left alone for consistency.


_app = new(typeRegistrar);
_app.SetDefaultCommand<InitChangesetCommand>();
_app.Run();
_app.SetDefaultCommand<StatusChangesetCommand>();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using SolarWinds.Changesets.Commands.Version.Helpers;
using SolarWinds.Changesets.Infrastructure;
using SolarWinds.Changesets.Shared;
using Spectre.Console.Testing;
using Spectre.Console.Cli.Testing;

namespace SolarWinds.Changesets.Tests.Version;

Expand Down