diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Assertions/StringAssertionsExtensions.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Assertions/StringAssertionsExtensions.cs index 1b69b04c5..e0483c39a 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Assertions/StringAssertionsExtensions.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Assertions/StringAssertionsExtensions.cs @@ -24,5 +24,15 @@ namespace Microsoft.DotNet.Tools.Test.Utilities return new AndConstraint(assertions); } + + public static AndConstraint ContainVisuallySameFragment(this StringAssertions assertions, string expected, string because = "", params object[] becauseArgs) + { + Execute.Assertion + .ForCondition(NormalizeLineEndings(assertions.Subject).Contains(NormalizeLineEndings(expected))) + .BecauseOf(because, becauseArgs) + .FailWith($"String \"{assertions.Subject}\" does not contain visually same fragment string \"{expected}\"."); + + return new AndConstraint(assertions); + } } } diff --git a/test/Msbuild.Tests.Utilities/Msbuild.Tests.Utilities.csproj b/test/Msbuild.Tests.Utilities/Msbuild.Tests.Utilities.csproj index 3c7f9fcb3..914e7441b 100644 --- a/test/Msbuild.Tests.Utilities/Msbuild.Tests.Utilities.csproj +++ b/test/Msbuild.Tests.Utilities/Msbuild.Tests.Utilities.csproj @@ -17,9 +17,8 @@ true - - true - + + true diff --git a/test/dotnet-add-p2p.Tests/dotnet-add-p2p.Tests.csproj b/test/dotnet-add-p2p.Tests/dotnet-add-p2p.Tests.csproj index 13e5d50f0..545a42239 100644 --- a/test/dotnet-add-p2p.Tests/dotnet-add-p2p.Tests.csproj +++ b/test/dotnet-add-p2p.Tests/dotnet-add-p2p.Tests.csproj @@ -20,6 +20,8 @@ true + + true diff --git a/test/dotnet-add-proj.Tests/GivenDotnetAddProj.cs b/test/dotnet-add-proj.Tests/GivenDotnetAddProj.cs index e84d1b90f..64f9a726c 100644 --- a/test/dotnet-add-proj.Tests/GivenDotnetAddProj.cs +++ b/test/dotnet-add-proj.Tests/GivenDotnetAddProj.cs @@ -36,7 +36,7 @@ Additional Arguments: var cmd = new DotnetCommand() .ExecuteWithCapturedOutput($"add project {helpArg}"); cmd.Should().Pass(); - cmd.StdOut.Should().Be(HelpText); + cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText); } [Theory] @@ -72,7 +72,7 @@ Additional Arguments: .ExecuteWithCapturedOutput($"add {solutionName} project p.csproj"); cmd.Should().Fail(); cmd.StdErr.Should().Be($"Could not find solution or directory `{solutionName}`."); - cmd.StdOut.Should().Be(HelpText); + cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText); } [Fact] @@ -91,7 +91,7 @@ Additional Arguments: .ExecuteWithCapturedOutput($"add InvalidSolution.sln project {projectToAdd}"); cmd.Should().Fail(); cmd.StdErr.Should().Be("Invalid solution `InvalidSolution.sln`."); - cmd.StdOut.Should().Be(HelpText); + cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText); } [Fact] @@ -111,7 +111,7 @@ Additional Arguments: .ExecuteWithCapturedOutput($"add project {projectToAdd}"); cmd.Should().Fail(); cmd.StdErr.Should().Be($"Invalid solution `{solutionPath}`."); - cmd.StdOut.Should().Be(HelpText); + cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText); } [Fact] @@ -129,7 +129,7 @@ Additional Arguments: .ExecuteWithCapturedOutput(@"add App.sln project"); cmd.Should().Fail(); cmd.StdErr.Should().Be("You must specify at least one project to add."); - cmd.StdOut.Should().Be(HelpText); + cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText); } [Fact] @@ -148,7 +148,7 @@ Additional Arguments: .ExecuteWithCapturedOutput(@"add project App.csproj"); cmd.Should().Fail(); cmd.StdErr.Should().Be($"Specified solution file {solutionPath + Path.DirectorySeparatorChar} does not exist, or there is no solution file in the directory."); - cmd.StdOut.Should().Be(HelpText); + cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText); } [Fact] @@ -167,7 +167,7 @@ Additional Arguments: .ExecuteWithCapturedOutput($"add project {projectToAdd}"); cmd.Should().Fail(); cmd.StdErr.Should().Be($"Found more than one solution file in {projectDirectory + Path.DirectorySeparatorChar}. Please specify which one to use."); - cmd.StdOut.Should().Be(HelpText); + cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText); } [Theory] diff --git a/test/dotnet-help.Tests/GivenThatIWantToShowHelpForDotnetCommand.cs b/test/dotnet-help.Tests/GivenThatIWantToShowHelpForDotnetCommand.cs index 488686fe3..1c072eaf1 100644 --- a/test/dotnet-help.Tests/GivenThatIWantToShowHelpForDotnetCommand.cs +++ b/test/dotnet-help.Tests/GivenThatIWantToShowHelpForDotnetCommand.cs @@ -59,7 +59,8 @@ Advanced Commands: { var cmd = new DotnetCommand() .ExecuteWithCapturedOutput($"{helpArg}"); - cmd.Should().Pass().And.HaveStdOutContaining(HelpText); + cmd.Should().Pass(); + cmd.StdOut.Should().ContainVisuallySameFragment(HelpText); } } } diff --git a/test/dotnet-list-p2ps.Tests/GivenDotnetListP2Ps.cs b/test/dotnet-list-p2ps.Tests/GivenDotnetListP2Ps.cs index 29a099d86..75049a8f8 100644 --- a/test/dotnet-list-p2ps.Tests/GivenDotnetListP2Ps.cs +++ b/test/dotnet-list-p2ps.Tests/GivenDotnetListP2Ps.cs @@ -35,7 +35,7 @@ Options: { var cmd = new ListP2PsCommand().Execute(helpArg); cmd.Should().Pass(); - cmd.StdOut.Should().Be(HelpText); + cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText); } [Theory] @@ -72,7 +72,7 @@ Options: .Execute($"\"{setup.ValidRefCsprojPath}\""); cmd.ExitCode.Should().NotBe(0); cmd.StdErr.Should().Be($"Could not find project or directory `{projName}`."); - cmd.StdOut.Should().Be(HelpText); + cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText); } [Fact] @@ -87,7 +87,7 @@ Options: .Execute($"\"{setup.ValidRefCsprojPath}\""); cmd.ExitCode.Should().NotBe(0); cmd.StdErr.Should().Be("Project `Broken/Broken.csproj` is invalid."); - cmd.StdOut.Should().Be(HelpText); + cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText); } [Fact] @@ -101,7 +101,7 @@ Options: .Execute($"\"{setup.ValidRefCsprojRelToOtherProjPath}\""); cmd.ExitCode.Should().NotBe(0); cmd.StdErr.Should().Be($"Found more than one project in `{workingDir + Path.DirectorySeparatorChar}`. Please specify which one to use."); - cmd.StdOut.Should().Be(HelpText); + cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText); } [Fact] @@ -114,7 +114,7 @@ Options: .Execute($"\"{setup.ValidRefCsprojPath}\""); cmd.ExitCode.Should().NotBe(0); cmd.StdErr.Should().Be($"Could not find any project in `{setup.TestRoot + Path.DirectorySeparatorChar}`."); - cmd.StdOut.Should().Be(HelpText); + cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText); } [Fact] @@ -144,7 +144,7 @@ Options: .WithProject(lib.CsProjPath) .Execute(); cmd.Should().Pass(); - cmd.StdOut.Should().Be(OutputText); + cmd.StdOut.Should().BeVisuallyEquivalentTo(OutputText); } [Fact] @@ -169,7 +169,7 @@ Options: .WithProject(lib.CsProjPath) .Execute(); cmd.Should().Pass(); - cmd.StdOut.Should().Be(OutputText); + cmd.StdOut.Should().BeVisuallyEquivalentTo(OutputText); } private TestSetup Setup([System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(Setup), string identifier = "") diff --git a/test/dotnet-list-p2ps.Tests/dotnet-list-p2ps.Tests.csproj b/test/dotnet-list-p2ps.Tests/dotnet-list-p2ps.Tests.csproj index 0508d4a5e..c1d57e9ce 100644 --- a/test/dotnet-list-p2ps.Tests/dotnet-list-p2ps.Tests.csproj +++ b/test/dotnet-list-p2ps.Tests/dotnet-list-p2ps.Tests.csproj @@ -6,7 +6,6 @@ true dotnet-list-p2ps.Tests $(PackageTargetFallback);dotnet5.4;portable-net451+win8 - $(DefineConstants);DISABLE_TRACE @@ -24,6 +23,8 @@ true + + diff --git a/test/dotnet-list-proj.Tests/GivenDotnetListProj.cs b/test/dotnet-list-proj.Tests/GivenDotnetListProj.cs index f639fd378..5def520b6 100644 --- a/test/dotnet-list-proj.Tests/GivenDotnetListProj.cs +++ b/test/dotnet-list-proj.Tests/GivenDotnetListProj.cs @@ -31,7 +31,7 @@ Options: var cmd = new DotnetCommand() .ExecuteWithCapturedOutput($"list projects {helpArg}"); cmd.Should().Pass(); - cmd.StdOut.Should().Be(HelpText); + cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText); } [Theory] @@ -66,7 +66,7 @@ Options: .ExecuteWithCapturedOutput($"list {solutionName} projects"); cmd.Should().Fail(); cmd.StdErr.Should().Be($"Could not find solution or directory `{solutionName}`."); - cmd.StdOut.Should().Be(HelpText); + cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText); } [Fact] @@ -84,7 +84,7 @@ Options: .ExecuteWithCapturedOutput("list InvalidSolution.sln projects"); cmd.Should().Fail(); cmd.StdErr.Should().Be("Invalid solution `InvalidSolution.sln`."); - cmd.StdOut.Should().Be(HelpText); + cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText); } [Fact] @@ -103,7 +103,7 @@ Options: .ExecuteWithCapturedOutput("list projects"); cmd.Should().Fail(); cmd.StdErr.Should().Be($"Invalid solution `{solutionFullPath}`."); - cmd.StdOut.Should().Be(HelpText); + cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText); } [Fact] @@ -122,7 +122,7 @@ Options: .ExecuteWithCapturedOutput("list projects"); cmd.Should().Fail(); cmd.StdErr.Should().Be($"Specified solution file {solutionDir + Path.DirectorySeparatorChar} does not exist, or there is no solution file in the directory."); - cmd.StdOut.Should().Be(HelpText); + cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText); } [Fact] @@ -140,7 +140,7 @@ Options: .ExecuteWithCapturedOutput("list projects"); cmd.Should().Fail(); cmd.StdErr.Should().Be($"Found more than one solution file in {projectDirectory + Path.DirectorySeparatorChar}. Please specify which one to use."); - cmd.StdOut.Should().Be(HelpText); + cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText); } [Fact] @@ -179,7 +179,7 @@ Options: .WithWorkingDirectory(projectDirectory) .ExecuteWithCapturedOutput("list projects"); cmd.Should().Pass(); - cmd.StdOut.Should().Be(OutputText); + cmd.StdOut.Should().BeVisuallyEquivalentTo(OutputText); } } } diff --git a/test/dotnet-remove-p2p.Tests/dotnet-remove-p2p.Tests.csproj b/test/dotnet-remove-p2p.Tests/dotnet-remove-p2p.Tests.csproj index ed48cbac9..48fc32042 100644 --- a/test/dotnet-remove-p2p.Tests/dotnet-remove-p2p.Tests.csproj +++ b/test/dotnet-remove-p2p.Tests/dotnet-remove-p2p.Tests.csproj @@ -23,6 +23,8 @@ true + + diff --git a/test/dotnet-remove-proj.Tests/GivenDotnetRemoveProj.cs b/test/dotnet-remove-proj.Tests/GivenDotnetRemoveProj.cs index 9c5f674ca..5462eb6d1 100644 --- a/test/dotnet-remove-proj.Tests/GivenDotnetRemoveProj.cs +++ b/test/dotnet-remove-proj.Tests/GivenDotnetRemoveProj.cs @@ -8,7 +8,7 @@ using System; using System.IO; using Xunit; -namespace Microsoft.DotNet.Cli.Remove.P2P.Tests +namespace Microsoft.DotNet.Cli.Remove.Project.Tests { public class GivenDotnetRemoveProj : TestBase { @@ -34,7 +34,7 @@ Additional Arguments: var cmd = new DotnetCommand() .ExecuteWithCapturedOutput($"remove project {helpArg}"); cmd.Should().Pass(); - cmd.StdOut.Should().Be(HelpText); + cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText); } [Fact] @@ -70,7 +70,7 @@ Additional Arguments: .ExecuteWithCapturedOutput($"remove {solutionName} project p.csproj"); cmd.Should().Fail(); cmd.StdErr.Should().Be($"Could not find solution or directory `{solutionName}`."); - cmd.StdOut.Should().Be(HelpText); + cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText); } [Fact] @@ -89,7 +89,7 @@ Additional Arguments: .ExecuteWithCapturedOutput($"remove InvalidSolution.sln project {projectToRemove}"); cmd.Should().Fail(); cmd.StdErr.Should().Be("Invalid solution `InvalidSolution.sln`."); - cmd.StdOut.Should().Be(HelpText); + cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText); } [Fact] @@ -109,7 +109,7 @@ Additional Arguments: .ExecuteWithCapturedOutput($"remove project {projectToRemove}"); cmd.Should().Fail(); cmd.StdErr.Should().Be($"Invalid solution `{solutionPath}`."); - cmd.StdOut.Should().Be(HelpText); + cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText); } [Fact] @@ -127,7 +127,7 @@ Additional Arguments: .ExecuteWithCapturedOutput(@"remove App.sln project"); cmd.Should().Fail(); cmd.StdErr.Should().Be("You must specify at least one project to remove."); - cmd.StdOut.Should().Be(HelpText); + cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText); } [Fact] @@ -146,7 +146,7 @@ Additional Arguments: .ExecuteWithCapturedOutput(@"remove project App.csproj"); cmd.Should().Fail(); cmd.StdErr.Should().Be($"Specified solution file {solutionPath + Path.DirectorySeparatorChar} does not exist, or there is no solution file in the directory."); - cmd.StdOut.Should().Be(HelpText); + cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText); } [Fact] @@ -165,7 +165,7 @@ Additional Arguments: .ExecuteWithCapturedOutput($"remove project {projectToRemove}"); cmd.Should().Fail(); cmd.StdErr.Should().Be($"Found more than one solution file in {projectDirectory + Path.DirectorySeparatorChar}. Please specify which one to use."); - cmd.StdOut.Should().Be(HelpText); + cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText); } [Fact] @@ -237,7 +237,7 @@ Additional Arguments: string outputText = $@"Project reference `{projectToRemove}` removed. Project reference `{projectToRemove}` removed."; - cmd.StdOut.Should().Be(outputText); + cmd.StdOut.Should().BeVisuallyEquivalentTo(outputText); slnFile = SlnFile.Read(solutionPath); slnFile.Projects.Count.Should().Be(1); @@ -267,7 +267,7 @@ Project reference `{projectToRemove}` removed."; string outputText = $@"Project reference `idontexist.csproj` could not be found. Project reference `{projectToRemove}` removed. Project reference `idontexisteither.csproj` could not be found."; - cmd.StdOut.Should().Be(outputText); + cmd.StdOut.Should().BeVisuallyEquivalentTo(outputText); slnFile = SlnFile.Read(solutionPath); slnFile.Projects.Count.Should().Be(1);