diff --git a/src/dotnet/commands/dotnet-migrate/MigrateCommandParser.cs b/src/dotnet/commands/dotnet-migrate/MigrateCommandParser.cs index f5f5c771f..f878b67f2 100644 --- a/src/dotnet/commands/dotnet-migrate/MigrateCommandParser.cs +++ b/src/dotnet/commands/dotnet-migrate/MigrateCommandParser.cs @@ -29,15 +29,19 @@ namespace Microsoft.DotNet.Cli description: LocalizableStrings.CmdProjectArgumentDescription), CommonOptions.HelpOption(), Create.Option("-t|--template-file", - LocalizableStrings.CmdTemplateDescription), + LocalizableStrings.CmdTemplateDescription, + Accept.ExactlyOneArgument()), Create.Option("-v|--sdk-package-version", - LocalizableStrings.CmdVersionDescription), + LocalizableStrings.CmdVersionDescription, + Accept.ExactlyOneArgument()), Create.Option("-x|--xproj-file", - LocalizableStrings.CmdXprojFileDescription), + LocalizableStrings.CmdXprojFileDescription, + Accept.ExactlyOneArgument()), Create.Option("-s|--skip-project-references", LocalizableStrings.CmdSkipProjectReferencesDescription), Create.Option("-r|--report-file", - LocalizableStrings.CmdReportFileDescription), + LocalizableStrings.CmdReportFileDescription, + Accept.ExactlyOneArgument()), Create.Option("--format-report-file-json", LocalizableStrings.CmdReportOutputDescription), Create.Option("--skip-backup", diff --git a/test/dotnet.Tests/ParserTests/MigrateParserTests.cs b/test/dotnet.Tests/ParserTests/MigrateParserTests.cs new file mode 100644 index 000000000..814333dd0 --- /dev/null +++ b/test/dotnet.Tests/ParserTests/MigrateParserTests.cs @@ -0,0 +1,58 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Linq; +using FluentAssertions; +using Microsoft.DotNet.Cli.CommandLine; +using Microsoft.DotNet.Tools.Migrate; +using Xunit; +using Xunit.Abstractions; +using Parser = Microsoft.DotNet.Cli.Parser; + +namespace Microsoft.DotNet.Tests.ParserTests +{ + public class MigrateParserTests + { + public MigrateParserTests(ITestOutputHelper output) + { + this.output = output; + } + + private readonly ITestOutputHelper output; + + [Fact] + public void MigrateParserConstructMigrateCommandWithoutError() + { + var command = Parser.Instance; + + var result = command.Parse("dotnet migrate --skip-backup -s " + + "-x \"C:\\ConsoleAppOnCore_1\\ConsoleAppOnCore_1.xproj\" " + + "\"C:\\ConsoleAppOnCore_1\\project.json\" " + + "-r \"C:\\report.wfw\" " + + "--format-report-file-json"); + + Action a = () => result["dotnet"]["migrate"].Value(); + a.ShouldNotThrow(); + } + + [Fact] + public void MigrateParseGetResultCorrectlyAsFollowing() + { + var command = Parser.Instance; + + var result = command.Parse("dotnet migrate --skip-backup -s " + + "-x \"C:\\ConsoleAppOnCore_1\\ConsoleAppOnCore_1.xproj\" " + + "\"C:\\ConsoleAppOnCore_1\\project.json\" " + + "-r \"C:\\report.wfw\" " + + "--format-report-file-json"); + + result["dotnet"]["migrate"]["skip-backup"].Value().Should().BeTrue(); + result["dotnet"]["migrate"]["skip-project-references"].Value().Should().BeTrue(); + result["dotnet"]["migrate"]["format-report-file-json"].Value().Should().BeTrue(); + result["dotnet"]["migrate"]["xproj-file"].Value().Should().Be("C:\\ConsoleAppOnCore_1\\ConsoleAppOnCore_1.xproj"); + result["dotnet"]["migrate"]["report-file"].Value().Should().Be("C:\\report.wfw"); + result["dotnet"]["migrate"].Arguments.Contains("C:\\ConsoleAppOnCore_1\\project.json").Should().BeTrue(); + } + } +} \ No newline at end of file