Skip to content
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Globalization;

Check failure on line 4 in src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build MacOS Debug)

src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs#L4

src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs(4,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 4 in src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build MacOS Debug)

src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs#L4

src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs(4,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 4 in src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build MacOS Debug)

src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs#L4

src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs(4,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 4 in src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build MacOS Release)

src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs#L4

src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs(4,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 4 in src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build MacOS Release)

src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs#L4

src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs(4,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 4 in src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Linux Debug)

src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs#L4

src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs(4,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 4 in src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Linux Debug)

src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs#L4

src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs(4,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 4 in src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Linux Debug)

src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs#L4

src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs(4,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 4 in src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Linux Release)

src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs#L4

src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs(4,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 4 in src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Linux Release)

src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs#L4

src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs(4,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 4 in src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Linux Release)

src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs#L4

src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs(4,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 4 in src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx

src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs#L4

src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs(4,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 4 in src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx

src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs#L4

src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs(4,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

using Microsoft.Testing.Platform.Extensions;
using Microsoft.Testing.Platform.Extensions.CommandLine;
using Microsoft.Testing.Platform.Helpers;
Expand Down Expand Up @@ -111,7 +113,7 @@
{
string arg = arguments[0];
int size = arg.Length;
if ((char.ToLowerInvariant(arg[size - 1]) != 'h' && char.ToLowerInvariant(arg[size - 1]) != 'm' && char.ToLowerInvariant(arg[size - 1]) != 's') || !float.TryParse(arg[..(size - 1)], out float _))
if ((char.ToLowerInvariant(arg[size - 1]) != 'h' && char.ToLowerInvariant(arg[size - 1]) != 'm' && char.ToLowerInvariant(arg[size - 1]) != 's') || !float.TryParse(arg[..(size - 1)], NumberStyles.Float, CultureInfo.InvariantCulture, out float _))
{
return ValidationResult.InvalidTask(PlatformResources.PlatformCommandLineTimeoutArgumentErrorMessage);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Globalization;

Check failure on line 4 in src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build MacOS Debug)

src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs#L4

src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs(4,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 4 in src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build MacOS Debug)

src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs#L4

src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs(4,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 4 in src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build MacOS Release)

src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs#L4

src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs(4,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 4 in src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build MacOS Release)

src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs#L4

src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs(4,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 4 in src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build MacOS Release)

src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs#L4

src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs(4,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 4 in src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Linux Debug)

src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs#L4

src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs(4,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 4 in src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Linux Debug)

src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs#L4

src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs(4,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 4 in src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Linux Release)

src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs#L4

src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs(4,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 4 in src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Linux Release)

src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs#L4

src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs(4,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 4 in src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx

src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs#L4

src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs(4,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 4 in src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx

src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs#L4

src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs(4,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

using Microsoft.Testing.Internal.Framework;
using Microsoft.Testing.Platform.Builder;
using Microsoft.Testing.Platform.Capabilities.TestFramework;
Expand Down Expand Up @@ -255,7 +257,7 @@
{
string arg = args[0];
int size = arg.Length;
if (!float.TryParse(arg[..(size - 1)], out float value))
if (!float.TryParse(arg[..(size - 1)], NumberStyles.Float, CultureInfo.InvariantCulture, out float value))
{
throw ApplicationStateGuard.Unreachable();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,82 @@ public async Task IsNotValid_If_ExitOnProcess_Not_Running()
Assert.IsFalse(validateOptionsResult.IsValid);
Assert.IsTrue(validateOptionsResult.ErrorMessage.StartsWith($"Invalid PID '{pid}'", StringComparison.OrdinalIgnoreCase));
}

[TestMethod]
[DataRow("1.5s")]
[DataRow("2.0m")]
[DataRow("0.5h")]
[DataRow("10s")]
[DataRow("30m")]
[DataRow("1h")]
public async Task IsValid_If_Timeout_Has_CorrectFormat_InvariantCulture(string timeout)
{
var provider = new PlatformCommandLineProvider();
CommandLineOption option = provider.GetCommandLineOptions().First(x => x.Name == PlatformCommandLineProvider.TimeoutOptionKey);

// Save current culture
CultureInfo originalCulture = CultureInfo.CurrentCulture;

try
{
// Test with various cultures to ensure invariant parsing works
foreach (string cultureName in new[] { "en-US", "de-DE", "fr-FR" })
{
CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo(cultureName);

ValidationResult validateOptionsResult = await provider.ValidateOptionArgumentsAsync(option, [timeout]).ConfigureAwait(false);
Assert.IsTrue(validateOptionsResult.IsValid, $"Failed with culture {cultureName} and timeout {timeout}");
Assert.IsTrue(string.IsNullOrEmpty(validateOptionsResult.ErrorMessage));
}
}
finally
{
// Restore original culture
CultureInfo.CurrentCulture = originalCulture;
}
}

[TestMethod]
[DataRow("1,5s")] // German decimal separator
[DataRow("invalid")]
[DataRow("1.5")] // Missing unit
[DataRow("abc.5s")]
public async Task IsInvalid_If_Timeout_Has_IncorrectFormat(string timeout)
{
var provider = new PlatformCommandLineProvider();
CommandLineOption option = provider.GetCommandLineOptions().First(x => x.Name == PlatformCommandLineProvider.TimeoutOptionKey);

ValidationResult validateOptionsResult = await provider.ValidateOptionArgumentsAsync(option, [timeout]).ConfigureAwait(false);
Assert.IsFalse(validateOptionsResult.IsValid);
Assert.AreEqual(PlatformResources.PlatformCommandLineTimeoutArgumentErrorMessage, validateOptionsResult.ErrorMessage);
}

[TestMethod]
public async Task Timeout_Parsing_Uses_InvariantCulture_NotCurrentCulture()
{
var provider = new PlatformCommandLineProvider();
CommandLineOption option = provider.GetCommandLineOptions().First(x => x.Name == PlatformCommandLineProvider.TimeoutOptionKey);

// Save current culture
CultureInfo originalCulture = CultureInfo.CurrentCulture;

try
{
// Set culture to German where decimal separator is comma
CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("de-DE");

// This should work because we use invariant culture (period as decimal separator)
ValidationResult validResult = await provider.ValidateOptionArgumentsAsync(option, ["1.5s"]).ConfigureAwait(false);
Assert.IsTrue(validResult.IsValid, "1.5s should be valid when using invariant culture");

// This should fail because comma is not valid in invariant culture
ValidationResult invalidResult = await provider.ValidateOptionArgumentsAsync(option, ["1,5s"]).ConfigureAwait(false);
Assert.IsFalse(invalidResult.IsValid, "1,5s should be invalid when using invariant culture");
}
finally
{
// Restore original culture
CultureInfo.CurrentCulture = originalCulture;
}
}
}
Loading