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
43 changes: 43 additions & 0 deletions src/MigrationTools.Host.Tests/Commands/VersionCommandTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MigrationTools.Services;

namespace MigrationTools.Host.Tests.Commands
{
[TestClass()]
public class VersionCommandTests
{
private IHost host;

[TestInitialize]
public void Setup()
{
host = MigrationToolHost.CreateDefaultBuilder(new string[] { "version", "--skipVersionCheck" }).Build();
}

[TestCleanup]
public void Cleanup()
{
host?.Dispose();
}

[TestMethod, TestCategory("L0")]
public void VersionCommand_ServiceResolution_ShouldSucceed()
{
// Verify that all required services can be resolved
var migrationToolVersion = host.Services.GetRequiredService<IMigrationToolVersion>();
Assert.IsNotNull(migrationToolVersion);
}

[TestMethod, TestCategory("L0")]
public void VersionCommand_GetRunningVersion_ShouldReturnVersionInfo()
{
var migrationToolVersion = host.Services.GetRequiredService<IMigrationToolVersion>();
var versionInfo = migrationToolVersion.GetRunningVersion();

Assert.IsNotNull(versionInfo);

Check warning on line 39 in src/MigrationTools.Host.Tests/Commands/VersionCommandTests.cs

View workflow job for this annotation

GitHub Actions / Build, Test, Sonar Cloud Analysis, & Package

Review or remove the assertion as its condition is known to be always true (https://learn.microsoft.com/dotnet/core/testing/mstest-analyzers/mstest0032)

Check warning on line 39 in src/MigrationTools.Host.Tests/Commands/VersionCommandTests.cs

View workflow job for this annotation

GitHub Actions / Build, Test, Sonar Cloud Analysis, & Package

Review or remove the assertion as its condition is known to be always true (https://learn.microsoft.com/dotnet/core/testing/mstest-analyzers/mstest0032)
Assert.IsNotNull(versionInfo.versionString);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<Content Include="..\..\configuration-default.json" Link="configuration-default.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="..\..\appsettings.json" Link="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/MigrationTools.Host/Commands/CommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void RunStartupLogic(TSettings settings)
Log.Debug(" IsRunningInDebug: {IsRunningInDebug}", _detectVersionService.IsRunningInDebug);
Log.Verbose("Full version data: ${_detectVersionService}", _detectVersionService);

Log.Information("Verion Info:");
Log.Information("Version Info:");
Log.Information(" Running: {RunningVersion}", _detectVersionService.RunningVersion);
Log.Information(" Installed: {InstalledVersion}", _detectVersionService.InstalledVersion);
Log.Information(" Available: {AvailableVersion}", _detectVersionService.AvailableVersion);
Expand Down
50 changes: 50 additions & 0 deletions src/MigrationTools.Host/Commands/VersionCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using MigrationTools.Host.Services;
using MigrationTools.Services;
using Spectre.Console;
using Spectre.Console.Cli;

namespace MigrationTools.Host.Commands
{
internal class VersionCommand : CommandBase<VersionCommandSettings>
{
private readonly IMigrationToolVersion _migrationToolVersion;

public VersionCommand(
IHostApplicationLifetime appLifetime,
IServiceProvider services,
IDetectOnlineService detectOnlineService,
IDetectVersionService2 detectVersionService,
ILogger<CommandBase<VersionCommandSettings>> logger,
ITelemetryLogger telemetryLogger,
IMigrationToolVersion migrationToolVersion,
IConfiguration configuration,
ActivitySource activitySource)
: base(appLifetime, services, detectOnlineService, detectVersionService, logger, telemetryLogger,
migrationToolVersion, configuration, activitySource)
{
_migrationToolVersion = migrationToolVersion;
}

internal override Task<int> ExecuteInternalAsync(CommandContext context, VersionCommandSettings settings)
{
var versionInfo = _migrationToolVersion.GetRunningVersion();

AnsiConsole.MarkupLine($"[bold cyan]Version:[/] {Markup.Escape(versionInfo.versionString)}");

if (versionInfo.version.Major == 0)
{
AnsiConsole.MarkupLine($"[dim]Git Tag:[/] {Markup.Escape(ThisAssembly.Git.Tag)}");
AnsiConsole.MarkupLine($"[dim]Git Branch:[/] {Markup.Escape(ThisAssembly.Git.Branch)}");
AnsiConsole.MarkupLine($"[dim]Git Commits:[/] {Markup.Escape(ThisAssembly.Git.Commits)}");
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

return Task.FromResult(0);
}
}
}
9 changes: 9 additions & 0 deletions src/MigrationTools.Host/Commands/VersionCommandSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.ComponentModel;
using Spectre.Console.Cli;

namespace MigrationTools.Host.Commands
{
internal class VersionCommandSettings : CommandSettingsBase
{
}
}
4 changes: 4 additions & 0 deletions src/MigrationTools.Host/MigrationToolHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ public static IHostBuilder CreateDefaultBuilder(string[] args, Action<IConfigura
.WithDescription("Creates or edits a configuration file")
.WithExample("builder --config \"configuration.json\"").IsHidden();

config.AddCommand<Commands.VersionCommand>("version")
.WithDescription("Displays the version of the tool")
.WithExample("version");

extraCommands?.Invoke(config);
config.PropagateExceptions();
});
Expand Down
Loading