Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit 8754fa4

Browse files
committed
Make dotnet-sln-add.Tests pass on localized setup
1 parent 5da3bfd commit 8754fa4

File tree

4 files changed

+28
-21
lines changed

4 files changed

+28
-21
lines changed

src/Microsoft.DotNet.Cli.Sln.Internal/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Runtime.CompilerServices;
66

77
[assembly: InternalsVisibleTo("Microsoft.DotNet.Cli.Sln.Internal.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100039ac461fa5c82c7dd2557400c4fd4e9dcdf7ac47e3d572548c04cd4673e004916610f4ea5cbf86f2b1ca1cb824f2a7b3976afecfcf4eb72d9a899aa6786effa10c30399e6580ed848231fec48374e41b3acf8811931343fc2f73acf72dae745adbcb7063cc4b50550618383202875223fc75401351cd89c44bf9b50e7fa3796")]
8+
[assembly: InternalsVisibleTo("dotnet-sln-add.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
89
[assembly: InternalsVisibleTo("dotnet-sln-list.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
910
[assembly: InternalsVisibleTo("dotnet-sln-remove.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
1011

src/dotnet/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
[assembly: InternalsVisibleTo("dotnet-add-package.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
1010
[assembly: InternalsVisibleTo("dotnet-help.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
1111
[assembly: InternalsVisibleTo("dotnet-remove-package.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
12+
[assembly: InternalsVisibleTo("dotnet-sln-add.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
1213
[assembly: InternalsVisibleTo("dotnet-sln-list.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
1314
[assembly: InternalsVisibleTo("dotnet-sln-remove.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
1415
[assembly: InternalsVisibleTo("dotnet-msbuild.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]

test/dotnet-sln-add.Tests/GivenDotnetSlnAdd.cs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using FluentAssertions;
55
using Microsoft.Build.Construction;
66
using Microsoft.DotNet.Cli.Sln.Internal;
7+
using Microsoft.DotNet.Tools;
78
using Microsoft.DotNet.Tools.Test.Utilities;
89
using System;
910
using System.IO;
@@ -198,7 +199,7 @@ public void WhenHelpOptionIsPassedItPrintsUsage(string helpArg)
198199
var cmd = new DotnetCommand()
199200
.ExecuteWithCapturedOutput($"sln add {helpArg}");
200201
cmd.Should().Pass();
201-
cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText);
202+
cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(HelpText);
202203
}
203204

204205
[Theory]
@@ -209,8 +210,8 @@ public void WhenNoCommandIsPassedItPrintsError(string commandName)
209210
var cmd = new DotnetCommand()
210211
.ExecuteWithCapturedOutput($"sln {commandName}");
211212
cmd.Should().Fail();
212-
cmd.StdErr.Should().Be("Required command was not provided.");
213-
cmd.StdOut.Should().BeVisuallyEquivalentTo(SlnCommandHelpText);
213+
cmd.StdErr.Should().Be(CommonLocalizableStrings.RequiredCommandNotPassed);
214+
cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(SlnCommandHelpText);
214215
}
215216

216217
[Fact]
@@ -219,7 +220,7 @@ public void WhenTooManyArgumentsArePassedItPrintsError()
219220
var cmd = new DotnetCommand()
220221
.ExecuteWithCapturedOutput("sln one.sln two.sln three.sln add");
221222
cmd.Should().Fail();
222-
cmd.StdErr.Should().BeVisuallyEquivalentTo("Unrecognized command or argument 'two.sln'\r\nUnrecognized command or argument 'three.sln'\r\nYou must specify at least one project to add.");
223+
cmd.StdErr.Should().BeVisuallyEquivalentTo($"Unrecognized command or argument 'two.sln'\r\nUnrecognized command or argument 'three.sln'\r\n{CommonLocalizableStrings.SpecifyAtLeastOneProjectToAdd}");
223224
}
224225

225226
[Theory]
@@ -233,8 +234,8 @@ public void WhenNonExistingSolutionIsPassedItPrintsErrorAndUsage(string solution
233234
var cmd = new DotnetCommand()
234235
.ExecuteWithCapturedOutput($"sln {solutionName} add p.csproj");
235236
cmd.Should().Fail();
236-
cmd.StdErr.Should().Be($"Could not find solution or directory `{solutionName}`.");
237-
cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText);
237+
cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.CouldNotFindSolutionOrDirectory, solutionName));
238+
cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(HelpText);
238239
}
239240

240241
[Fact]
@@ -252,8 +253,8 @@ public void WhenInvalidSolutionIsPassedItPrintsErrorAndUsage()
252253
.WithWorkingDirectory(projectDirectory)
253254
.ExecuteWithCapturedOutput($"sln InvalidSolution.sln add {projectToAdd}");
254255
cmd.Should().Fail();
255-
cmd.StdErr.Should().Be("Invalid solution `InvalidSolution.sln`. Expected file header not found.");
256-
cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText);
256+
cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.InvalidSolutionFormatString, "InvalidSolution.sln", LocalizableStrings.FileHeaderMissingError));
257+
cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(HelpText);
257258
}
258259

259260
[Fact]
@@ -272,8 +273,8 @@ public void WhenInvalidSolutionIsFoundItPrintsErrorAndUsage()
272273
.WithWorkingDirectory(projectDirectory)
273274
.ExecuteWithCapturedOutput($"sln add {projectToAdd}");
274275
cmd.Should().Fail();
275-
cmd.StdErr.Should().Be($"Invalid solution `{solutionPath}`. Expected file header not found.");
276-
cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText);
276+
cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.InvalidSolutionFormatString, solutionPath, LocalizableStrings.FileHeaderMissingError));
277+
cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(HelpText);
277278
}
278279

279280
[Fact]
@@ -290,14 +291,14 @@ public void WhenNoProjectIsPassedItPrintsErrorAndUsage()
290291
.WithWorkingDirectory(projectDirectory)
291292
.ExecuteWithCapturedOutput(@"sln App.sln add");
292293
cmd.Should().Fail();
293-
cmd.StdErr.Should().Be("You must specify at least one project to add.");
294+
cmd.StdErr.Should().Be(CommonLocalizableStrings.SpecifyAtLeastOneProjectToAdd);
294295

295296
_output.WriteLine("[STD OUT]");
296297
_output.WriteLine(cmd.StdOut);
297298
_output.WriteLine("[HelpText]");
298299
_output.WriteLine(HelpText);
299300

300-
cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText);
301+
cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(HelpText);
301302
}
302303

303304
[Fact]
@@ -315,8 +316,8 @@ public void WhenNoSolutionExistsInTheDirectoryItPrintsErrorAndUsage()
315316
.WithWorkingDirectory(solutionPath)
316317
.ExecuteWithCapturedOutput(@"sln add App.csproj");
317318
cmd.Should().Fail();
318-
cmd.StdErr.Should().Be($"Specified solution file {solutionPath + Path.DirectorySeparatorChar} does not exist, or there is no solution file in the directory.");
319-
cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText);
319+
cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.SolutionDoesNotExist, solutionPath + Path.DirectorySeparatorChar));
320+
cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(HelpText);
320321
}
321322

322323
[Fact]
@@ -334,8 +335,8 @@ public void WhenMoreThanOneSolutionExistsInTheDirectoryItPrintsErrorAndUsage()
334335
.WithWorkingDirectory(projectDirectory)
335336
.ExecuteWithCapturedOutput($"sln add {projectToAdd}");
336337
cmd.Should().Fail();
337-
cmd.StdErr.Should().Be($"Found more than one solution file in {projectDirectory + Path.DirectorySeparatorChar}. Please specify which one to use.");
338-
cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText);
338+
cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.MoreThanOneSolutionInDirectory, projectDirectory + Path.DirectorySeparatorChar));
339+
cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(HelpText);
339340
}
340341

341342
[Fact]
@@ -476,7 +477,7 @@ public void WhenValidProjectIsPassedItGetsAdded(string testAsset)
476477
.WithWorkingDirectory(projectDirectory)
477478
.ExecuteWithCapturedOutput($"sln App.sln add {projectToAdd}");
478479
cmd.Should().Pass();
479-
cmd.StdOut.Should().Be($"Project `{projectPath}` added to the solution.");
480+
cmd.StdOut.Should().Be(string.Format(CommonLocalizableStrings.ProjectAddedToTheSolution, projectPath));
480481
cmd.StdErr.Should().BeEmpty();
481482
}
482483

@@ -503,7 +504,7 @@ public void WhenInvalidProjectIsPassedItDoesNotGetAdded(string testAsset)
503504
.ExecuteWithCapturedOutput($"sln App.sln add {projectToAdd}");
504505
cmd.Should().Pass();
505506
cmd.StdOut.Should().BeEmpty();
506-
cmd.StdErr.Should().Match("Invalid project `*`. The project file could not be loaded.*");
507+
cmd.StdErr.Should().Match(string.Format(CommonLocalizableStrings.InvalidProjectWithExceptionMessage, '*', '*'));
507508

508509
slnFile = SlnFile.Read(Path.Combine(projectDirectory, "App.sln"));
509510
slnFile.Projects.Count().Should().Be(expectedNumberOfProjects);
@@ -576,7 +577,7 @@ public void WhenSolutionAlreadyContainsProjectItDoesntDuplicate(string testAsset
576577
.WithWorkingDirectory(projectDirectory)
577578
.ExecuteWithCapturedOutput($"sln App.sln add {projectToAdd}");
578579
cmd.Should().Pass();
579-
cmd.StdOut.Should().Be($"Solution {solutionPath} already contains project {projectToAdd}.");
580+
cmd.StdOut.Should().Be(string.Format(CommonLocalizableStrings.SolutionAlreadyContainsProject, solutionPath, projectToAdd));
580581
cmd.StdErr.Should().BeEmpty();
581582
}
582583

@@ -598,7 +599,7 @@ public void WhenPassedMultipleProjectsAndOneOfthemDoesNotExistItCancelsWholeOper
598599
.WithWorkingDirectory(projectDirectory)
599600
.ExecuteWithCapturedOutput($"sln App.sln add {projectToAdd} idonotexist.csproj");
600601
cmd.Should().Fail();
601-
cmd.StdErr.Should().Be("Project `idonotexist.csproj` does not exist.");
602+
cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.ProjectDoesNotExist, "idonotexist.csproj"));
602603

603604
File.ReadAllText(slnFullPath)
604605
.Should().BeVisuallyEquivalentTo(contentBefore);
@@ -654,7 +655,7 @@ public void WhenPassedAProjectItAddsCorrectProjectTypeGuid(
654655
.WithWorkingDirectory(projectDirectory)
655656
.ExecuteWithCapturedOutput($"sln App.sln add {projectToAdd}");
656657
cmd.Should().Pass();
657-
cmd.StdOut.Should().Be($"Project `{projectToAdd}` added to the solution.");
658+
cmd.StdOut.Should().Be(string.Format(CommonLocalizableStrings.ProjectAddedToTheSolution, projectToAdd));
658659
cmd.StdErr.Should().BeEmpty();
659660

660661
var slnFile = SlnFile.Read(Path.Combine(projectDirectory, "App.sln"));

test/dotnet-sln-add.Tests/dotnet-sln-add.Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
<RuntimeFrameworkVersion>$(CLI_SharedFrameworkVersion)</RuntimeFrameworkVersion>
77
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
88
<AssemblyName>dotnet-sln-add.Tests</AssemblyName>
9+
<AssemblyOriginatorKeyFile>../../tools/Key.snk</AssemblyOriginatorKeyFile>
10+
<SignAssembly>true</SignAssembly>
11+
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
912
<PackageTargetFallback>$(PackageTargetFallback);dotnet5.4;portable-net451+win8</PackageTargetFallback>
1013
</PropertyGroup>
1114

@@ -15,6 +18,7 @@
1518
<ProjectReference Include="..\..\src\Microsoft.DotNet.Cli.Utils\Microsoft.DotNet.Cli.Utils.csproj" />
1619
<ProjectReference Include="..\..\src\Microsoft.DotNet.InternalAbstractions\Microsoft.DotNet.InternalAbstractions.csproj" />
1720
<ProjectReference Include="..\..\src\Microsoft.DotNet.TestFramework\Microsoft.DotNet.TestFramework.csproj" />
21+
<ProjectReference Include="..\..\src\dotnet\dotnet.csproj" />
1822
</ItemGroup>
1923

2024
<ItemGroup>

0 commit comments

Comments
 (0)