From 419562ba95ee97cb1bad569db54ad4c35c662795 Mon Sep 17 00:00:00 2001 From: Nick Guerrera Date: Tue, 13 Jun 2017 19:24:30 -0700 Subject: [PATCH] Make dotnet-help.Tests pass on localized setup --- src/dotnet/Properties/AssemblyInfo.cs | 1 + .../Assertions/StringAssertionsExtensions.cs | 20 +++++++++++++++++++ ...ivenThatIWantToShowHelpForDotnetCommand.cs | 8 ++++---- ...ThatIWantToShowHelpForDotnetHelpCommand.cs | 2 +- .../dotnet-help.Tests.csproj | 3 +++ 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/dotnet/Properties/AssemblyInfo.cs b/src/dotnet/Properties/AssemblyInfo.cs index 1847e066c..ed811a3b5 100644 --- a/src/dotnet/Properties/AssemblyInfo.cs +++ b/src/dotnet/Properties/AssemblyInfo.cs @@ -6,4 +6,5 @@ using System.Runtime.CompilerServices; [assembly: AssemblyMetadataAttribute("Serviceable", "True")] [assembly: InternalsVisibleTo("dotnet.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] +[assembly: InternalsVisibleTo("dotnet-help.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("dotnet-msbuild.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Assertions/StringAssertionsExtensions.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Assertions/StringAssertionsExtensions.cs index e0483c39a..a2e2e5c1b 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Assertions/StringAssertionsExtensions.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Assertions/StringAssertionsExtensions.cs @@ -25,6 +25,16 @@ namespace Microsoft.DotNet.Tools.Test.Utilities return new AndConstraint(assertions); } + public static AndConstraint BeVisuallyEquivalentToIfNotLocalized(this StringAssertions assertions, string expected, string because = "", params object[] becauseArgs) + { + if (!DotnetUnderTest.IsLocalized()) + { + return BeVisuallyEquivalentTo(assertions, expected, because, becauseArgs); + } + + return new AndConstraint(assertions); + } + public static AndConstraint ContainVisuallySameFragment(this StringAssertions assertions, string expected, string because = "", params object[] becauseArgs) { Execute.Assertion @@ -34,5 +44,15 @@ namespace Microsoft.DotNet.Tools.Test.Utilities return new AndConstraint(assertions); } + + public static AndConstraint ContainVisuallySameFragmentIfNotLocalized(this StringAssertions assertions, string expected, string because = "", params object[] becauseArgs) + { + if (!DotnetUnderTest.IsLocalized()) + { + return ContainVisuallySameFragment(assertions, expected, because, becauseArgs); + } + + return new AndConstraint(assertions); + } } } diff --git a/test/dotnet-help.Tests/GivenThatIWantToShowHelpForDotnetCommand.cs b/test/dotnet-help.Tests/GivenThatIWantToShowHelpForDotnetCommand.cs index 8c33747ff..700367832 100644 --- a/test/dotnet-help.Tests/GivenThatIWantToShowHelpForDotnetCommand.cs +++ b/test/dotnet-help.Tests/GivenThatIWantToShowHelpForDotnetCommand.cs @@ -66,7 +66,7 @@ runtime-options: var cmd = new DotnetCommand() .ExecuteWithCapturedOutput($"{helpArg}"); cmd.Should().Pass(); - cmd.StdOut.Should().ContainVisuallySameFragment(HelpText); + cmd.StdOut.Should().ContainVisuallySameFragmentIfNotLocalized(HelpText); } [Fact] @@ -75,7 +75,7 @@ runtime-options: var cmd = new HelpCommand() .ExecuteWithCapturedOutput(); cmd.Should().Pass(); - cmd.StdOut.Should().ContainVisuallySameFragment(HelpText); + cmd.StdOut.Should().ContainVisuallySameFragmentIfNotLocalized(HelpText); } [Fact] @@ -85,8 +85,8 @@ runtime-options: .ExecuteWithCapturedOutput("help invalid"); cmd.Should().Fail(); - cmd.StdErr.Should().ContainVisuallySameFragment($"Specified command 'invalid' is not a valid CLI command. Please specify a valid CLI commands. For more information, run dotnet help."); - cmd.StdOut.Should().ContainVisuallySameFragment(HelpText); + cmd.StdErr.Should().Contain(string.Format(Tools.Help.LocalizableStrings.CommandDoesNotExist, "invalid")); + cmd.StdOut.Should().ContainVisuallySameFragmentIfNotLocalized(HelpText); } [WindowsOnlyFact] diff --git a/test/dotnet-help.Tests/GivenThatIWantToShowHelpForDotnetHelpCommand.cs b/test/dotnet-help.Tests/GivenThatIWantToShowHelpForDotnetHelpCommand.cs index e24d4e56a..ab13b7f9c 100644 --- a/test/dotnet-help.Tests/GivenThatIWantToShowHelpForDotnetHelpCommand.cs +++ b/test/dotnet-help.Tests/GivenThatIWantToShowHelpForDotnetHelpCommand.cs @@ -31,7 +31,7 @@ Options: var cmd = new HelpCommand() .ExecuteWithCapturedOutput($"{helpArg}"); cmd.Should().Pass(); - cmd.StdOut.Should().ContainVisuallySameFragment(HelpText); + cmd.StdOut.Should().ContainVisuallySameFragmentIfNotLocalized(HelpText); } } } diff --git a/test/dotnet-help.Tests/dotnet-help.Tests.csproj b/test/dotnet-help.Tests/dotnet-help.Tests.csproj index 73bdcfde8..d82d18516 100644 --- a/test/dotnet-help.Tests/dotnet-help.Tests.csproj +++ b/test/dotnet-help.Tests/dotnet-help.Tests.csproj @@ -6,6 +6,9 @@ $(CLI_SharedFrameworkVersion) true dotnet-help.Tests + ../../tools/Key.snk + true + true $(PackageTargetFallback);dnxcore50;portable-net45+win8