Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable culture analyzer and fix issues #3678

Merged
merged 23 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix culture issues on object model
  • Loading branch information
Evangelink committed Jun 30, 2022
commit 2bd3703e4791b1c1f9b0a71272882bcf737c5fad
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Globalization;
using System.Runtime.Serialization;

namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection;
Expand Down Expand Up @@ -132,7 +133,7 @@ public int CompareTo(object? obj)

RequestId? other = obj as RequestId;
return other == null
? throw new ArgumentException(string.Format(Resources.Resources.Common_ObjectMustBeOfType, new object[] { typeof(RequestId).Name }), nameof(obj))
? throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Resources.Common_ObjectMustBeOfType, new object[] { typeof(RequestId).Name }), nameof(obj))
: Id.CompareTo(other.Id);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Globalization;
using System.IO;

using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;
Expand Down Expand Up @@ -59,7 +60,7 @@ public FileTransferInformation(DataCollectionContext context, string path, bool
// Make sure the file exists.
if (!_fileHelper.Exists(path))
{
throw new FileNotFoundException(string.Format(Resources.Resources.Common_FileNotExist, new object[] { path }), path);
throw new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, Resources.Resources.Common_FileNotExist, new object[] { path }), path);
}

// Make sure the path we have is a full path (not relative).
Expand Down
12 changes: 11 additions & 1 deletion src/Microsoft.TestPlatform.ObjectModel/Framework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

#if !NETSTANDARD1_0

#if !NETCOREAPP1_0 && !NETSTANDARD1_0 && !NETSTANDARD1_3 && !WINDOWS_UWP
using System.Globalization;
#endif

using NuGet.Frameworks;

using static NuGet.Frameworks.FrameworkConstants;
Expand Down Expand Up @@ -74,7 +78,13 @@ private Framework()
{
// IDE always sends framework in form of ENUM, which always throws exception
// This throws up in first chance exception, refer Bug https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems/edit/591142
switch (frameworkString.Trim().ToLower())
var formattedFrameworkString = frameworkString.Trim()
.ToLower(
#if !NETCOREAPP1_0 && !NETSTANDARD1_0 && !NETSTANDARD1_3 && !WINDOWS_UWP
CultureInfo.InvariantCulture
#endif
);
switch (formattedFrameworkString)
{
case "framework35":
name = CommonFrameworks.Net35.DotNetFrameworkName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;

Expand Down Expand Up @@ -138,7 +140,7 @@ private bool OpenSession(string filename, string? searchPath)
int hResult = _source.LoadDataForExe(filename, searchPath, IntPtr.Zero);
if (HResult.Failed(hResult))
{
throw new COMException(string.Format(Resources.Resources.FailedToCreateDiaSession, hResult));
throw new COMException(string.Format(CultureInfo.CurrentCulture, Resources.Resources.FailedToCreateDiaSession, hResult));
}

// Open the session and return it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ internal static class DiaSourceObject

if (modHandle == IntPtr.Zero)
{
throw new COMException(string.Format(Resources.Resources.FailedToLoadMsDia));
throw new COMException(Resources.Resources.FailedToLoadMsDia);
}

var diaSourceClassGuid = new Guid("{E6756135-1E65-4D17-8576-610761398C3C}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,7 @@ private void PopulateCacheForTypeAndMethodSymbols(string binaryPath)
}
else
{
EqtTrace.Error(
string.Format(
"Unable to find source information for method: {0} type: {1}",
methodInfo.Name,
type.FullName));
EqtTrace.Error($"Unable to find source information for method: {methodInfo.Name} type: {type.FullName}");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,15 +459,15 @@ public override XmlElement ToXml()
}

XmlElement maxCpuCount = doc.CreateElement("MaxCpuCount");
maxCpuCount.InnerXml = MaxCpuCount.ToString();
maxCpuCount.InnerXml = MaxCpuCount.ToString(CultureInfo.CurrentCulture);
root.AppendChild(maxCpuCount);

XmlElement batchSize = doc.CreateElement("BatchSize");
batchSize.InnerXml = BatchSize.ToString();
batchSize.InnerXml = BatchSize.ToString(CultureInfo.CurrentCulture);
root.AppendChild(batchSize);

XmlElement testSessionTimeout = doc.CreateElement("TestSessionTimeout");
testSessionTimeout.InnerXml = TestSessionTimeout.ToString();
testSessionTimeout.InnerXml = TestSessionTimeout.ToString(CultureInfo.CurrentCulture);
root.AppendChild(testSessionTimeout);

XmlElement designMode = doc.CreateElement("DesignMode");
Expand Down
10 changes: 5 additions & 5 deletions src/Microsoft.TestPlatform.ObjectModel/TestResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public override string ToString()

// Add the outcome of the test and the name of the test.
result.AppendFormat(
CultureInfo.CurrentUICulture,
CultureInfo.CurrentCulture,
Resources.Resources.BasicTestResultFormat,
TestCase.DisplayName,
TestOutcomeHelper.GetOutcomeString(Outcome));
Expand All @@ -129,14 +129,14 @@ public override string ToString()
{
// Add Error message.
result.AppendLine();
result.AppendFormat(CultureInfo.CurrentUICulture, Resources.Resources.TestFailureMessageFormat, ErrorMessage);
result.AppendFormat(CultureInfo.CurrentCulture, Resources.Resources.TestFailureMessageFormat, ErrorMessage);

// Add stack trace if we have one.
if (!StringUtils.IsNullOrWhiteSpace(ErrorStackTrace))
{
result.AppendLine();
result.AppendFormat(
CultureInfo.CurrentUICulture,
CultureInfo.CurrentCulture,
Resources.Resources.TestFailureStackTraceFormat,
ErrorStackTrace);
}
Expand All @@ -151,7 +151,7 @@ public override string ToString()
if (!StringUtils.IsNullOrEmpty(message?.Category) && !StringUtils.IsNullOrEmpty(message.Text))
{
testMessages.AppendFormat(
CultureInfo.CurrentUICulture,
CultureInfo.CurrentCulture,
Resources.Resources.TestResultMessageFormat,
message.Category,
message.Text);
Expand All @@ -160,7 +160,7 @@ public override string ToString()

result.AppendLine();
result.AppendFormat(
CultureInfo.CurrentUICulture,
CultureInfo.CurrentCulture,
Resources.Resources.TestResultTextMessagesFormat,
testMessages.ToString());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// 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;
using System.Xml;

namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities;
Expand Down Expand Up @@ -55,10 +54,7 @@ public static void ReadToRootNode(XmlReader reader)
// Verify that it is a "RunSettings" node.
if (reader.Name != RunSettingsRootNodeName)
{
throw new SettingsException(
string.Format(
CultureInfo.CurrentCulture,
Resources.Resources.InvalidRunSettingsRootNode));
throw new SettingsException(Resources.Resources.InvalidRunSettingsRootNode);
}
}

Expand Down