diff --git a/eng/verify-nupkgs.ps1 b/eng/verify-nupkgs.ps1 index bef6bb99db..d39c6437ba 100644 --- a/eng/verify-nupkgs.ps1 +++ b/eng/verify-nupkgs.ps1 @@ -24,7 +24,7 @@ function Confirm-NugetPackages { "MSTest.TestFramework" = 148; "MSTest.TestAdapter" = 74; "MSTest" = 6; - "MSTest.Analyzers" = 10; + "MSTest.Analyzers" = 50; } $packageDirectory = Resolve-Path "$PSScriptRoot/../artifacts/packages/$configuration" diff --git a/src/Analyzers/MSTest.Analyzers.Package/MSTest.Analyzers.Package.csproj b/src/Analyzers/MSTest.Analyzers.Package/MSTest.Analyzers.Package.csproj index 36f7766c50..21b9ba6b27 100644 --- a/src/Analyzers/MSTest.Analyzers.Package/MSTest.Analyzers.Package.csproj +++ b/src/Analyzers/MSTest.Analyzers.Package/MSTest.Analyzers.Package.csproj @@ -34,10 +34,14 @@ - - - + + + + + + + diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/AnalyzersTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/AnalyzersTests.cs new file mode 100644 index 0000000000..95f24f5b3c --- /dev/null +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/AnalyzersTests.cs @@ -0,0 +1,49 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.Testing.Platform.Acceptance.IntegrationTests; +using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; + +namespace MSTest.Acceptance.IntegrationTests; + +[TestClass] +public sealed class AnalyzersTests : AcceptanceTestBase +{ + [TestMethod] + public async Task AnalyzerMessagesShouldBeLocalized() + { + string code = """ +#file Analyzers.csproj + + + + $TargetFrameworks$ + true + + + + +#file UnitTest1.cs +using Microsoft.VisualStudio.TestTools.UnitTesting; + +[TestClass] +public class UnitTest1 +{ + [DataRow(0)] + public void TestMethod() + { + } +} +""".PatchTargetFrameworks(TargetFrameworks.NetCurrent) + .PatchCodeWithReplace("$MSTestVersion$", MSTestVersion); + + using TestAsset testAsset = await TestAsset.GenerateAssetAsync("Analyzers", code); + DotnetMuxerResult result = await DotnetCli.RunAsync($"build {testAsset.TargetAssetPath}", AcceptanceFixture.NuGetGlobalPackagesFolder.Path, environmentVariables: new() + { + ["DOTNET_CLI_UI_LANGUAGE"] = "it-IT", + ["PreferredUILang"] = "it-IT", + ["VSLang"] = "1040", + }, warnAsError: false); + result.AssertOutputContains("DataRow deve essere impostato solo su un metodo di test"); + } +} diff --git a/test/Utilities/Microsoft.Testing.TestInfrastructure/DotnetCli.cs b/test/Utilities/Microsoft.Testing.TestInfrastructure/DotnetCli.cs index 0ab1e70ec0..7e41079af4 100644 --- a/test/Utilities/Microsoft.Testing.TestInfrastructure/DotnetCli.cs +++ b/test/Utilities/Microsoft.Testing.TestInfrastructure/DotnetCli.cs @@ -80,7 +80,11 @@ public static async Task RunAsync( } } - environmentVariables.Add(key!, entry.Value!.ToString()!); + // We use TryAdd to let tests "overwrite" existing environment variables. + // Consider that the given dictionary has "TESTINGPLATFORM_UI_LANGUAGE" as a key. + // And also Environment.GetEnvironmentVariables() is returning TESTINGPLATFORM_UI_LANGUAGE. + // In that case, we do a "TryAdd" which effectively means the value from the original dictionary wins. + environmentVariables.TryAdd(key!, entry.Value!.ToString()!); } if (disableTelemetry)