Родитель
ba5273dea2
Коммит
caef78e1ff
|
@ -95,4 +95,5 @@ launchSettings.json
|
|||
/.dotnet
|
||||
|
||||
# Bundled dotnet tools
|
||||
.tools/
|
||||
.tools/
|
||||
tools/
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.DotNet.UpgradeAssistant.Cli.Commands;
|
||||
using Microsoft.DotNet.UpgradeAssistant.Commands;
|
||||
|
@ -34,21 +35,33 @@ namespace Microsoft.DotNet.UpgradeAssistant.Cli
|
|||
_exit = new ExitCommand(lifetime.StopApplication);
|
||||
}
|
||||
|
||||
public IReadOnlyList<UpgradeCommand> GetCommands(UpgradeStep step)
|
||||
public IReadOnlyList<UpgradeCommand> GetCommands(UpgradeStep step, IUpgradeContext context)
|
||||
{
|
||||
if (step is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(step));
|
||||
}
|
||||
|
||||
return new List<UpgradeCommand>()
|
||||
if (context is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
var commands = new List<UpgradeCommand>
|
||||
{
|
||||
new ApplyNextCommand(step),
|
||||
new SkipNextCommand(step),
|
||||
new SeeMoreDetailsCommand(step, ShowStepStatus),
|
||||
new ConfigureConsoleLoggingCommand(_userInput, _logSettings),
|
||||
_exit,
|
||||
new SeeMoreDetailsCommand(step, ShowStepStatus)
|
||||
};
|
||||
|
||||
if (context.Projects.Count() > 1 && context.CurrentProject is not null)
|
||||
{
|
||||
commands.Add(new SelectProjectCommand());
|
||||
}
|
||||
|
||||
commands.Add(new ConfigureConsoleLoggingCommand(_userInput, _logSettings));
|
||||
commands.Add(_exit);
|
||||
return commands;
|
||||
}
|
||||
|
||||
private Task ShowStepStatus(UpgradeStep step)
|
||||
|
|
|
@ -54,35 +54,32 @@ namespace Microsoft.DotNet.UpgradeAssistant.Cli
|
|||
|
||||
while (step is not null)
|
||||
{
|
||||
while (!step.IsDone)
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
ShowUpgradeSteps(steps, context, step);
|
||||
_io.Output.WriteLine();
|
||||
|
||||
var commands = _commandProvider.GetCommands(step, context);
|
||||
var command = await _input.ChooseAsync("Choose a command:", commands, token);
|
||||
|
||||
// TODO : It might be nice to allow commands to show more details by having a 'status' property
|
||||
// that can be shown here. Also, commands currently only return bools but, in the future,
|
||||
// if they return more complex objects, custom handlers could be used to respond to the different
|
||||
// commands' return values.
|
||||
if (!await command.ExecuteAsync(context, token))
|
||||
{
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
ShowUpgradeSteps(steps, context, step);
|
||||
_io.Output.WriteLine();
|
||||
|
||||
var commands = _commandProvider.GetCommands(step);
|
||||
var command = await _input.ChooseAsync("Choose a command:", commands, token);
|
||||
|
||||
// TODO : It might be nice to allow commands to show more details by having a 'status' property
|
||||
// that can be shown here. Also, commands currently only return bools but, in the future,
|
||||
// if they return more complex objects, custom handlers could be used to respond to the different
|
||||
// commands' return values.
|
||||
if (!await command.ExecuteAsync(context, token))
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
_io.Output.WriteLine($"Command ({command.CommandText}) did not succeed");
|
||||
Console.ResetColor();
|
||||
}
|
||||
else if (await _input.WaitToProceedAsync(token))
|
||||
{
|
||||
ConsoleUtils.Clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Upgrade process was canceled. Quitting....");
|
||||
return;
|
||||
}
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
_io.Output.WriteLine($"Command ({command.CommandText}) did not succeed");
|
||||
Console.ResetColor();
|
||||
}
|
||||
else if (await _input.WaitToProceedAsync(token))
|
||||
{
|
||||
ConsoleUtils.Clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Upgrade process was canceled. Quitting....");
|
||||
return;
|
||||
}
|
||||
|
||||
step = await _upgrader.GetNextStepAsync(context, token);
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.DotNet.UpgradeAssistant.Commands
|
||||
{
|
||||
public class SelectProjectCommand : UpgradeCommand
|
||||
{
|
||||
public override string CommandText => "Select different project";
|
||||
|
||||
public override Task<bool> ExecuteAsync(IUpgradeContext context, CancellationToken token)
|
||||
{
|
||||
if (context is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
context.SetCurrentProject(null);
|
||||
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ using System.Threading;
|
|||
using System.Threading.Tasks;
|
||||
using Autofac.Extras.Moq;
|
||||
using Microsoft.DotNet.UpgradeAssistant.Commands;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.DotNet.UpgradeAssistant.Tests
|
||||
|
@ -124,5 +125,32 @@ namespace Microsoft.DotNet.UpgradeAssistant.Tests
|
|||
Assert.True(await command.ExecuteAsync(context, CancellationToken.None).ConfigureAwait(false));
|
||||
Assert.True(exitCalled);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SelectProjectCommandClearsProject()
|
||||
{
|
||||
// Arrange
|
||||
using var mock = AutoMock.GetLoose();
|
||||
var context = mock.Mock<IUpgradeContext>();
|
||||
|
||||
var command = new SelectProjectCommand();
|
||||
|
||||
// Act
|
||||
var result = await command.ExecuteAsync(context.Object, CancellationToken.None).ConfigureAwait(true);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
Assert.Equal("Select different project", command.CommandText);
|
||||
Assert.True(command.IsEnabled);
|
||||
context.Verify(c => c.SetCurrentProject(null), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task NegativeSelectProjectCommandTests()
|
||||
{
|
||||
var command = new SelectProjectCommand();
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>("context", () => command.ExecuteAsync(null!, CancellationToken.None)).ConfigureAwait(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче