Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ dotnet_diagnostic.IDE0078.severity = warning # not default, increased severity t
# Keep this in sync with csharp_style_prefer_not_pattern
dotnet_diagnostic.IDE0083.severity = warning # not default, increased severity to ensure it is applied

# CA1836: Prefer IsEmpty over Count
dotnet_diagnostic.CA1836.severity = warning # not default, increased severity to ensure it is applied

# CA2211: Non-constant fields should not be visible
dotnet_diagnostic.CA2211.severity = warning # not default, increased severity to ensure it is applied

# CA1806: Do not ignore method results
dotnet_diagnostic.CA1806.severity = warning # not default, increased severity to ensure it is applied

# CA1834: Consider using 'StringBuilder.Append(char)' when applicable
dotnet_diagnostic.CA1834.severity = warning # not default, increased severity to ensure it is always applied

#### C# Coding Conventions ####

# var preferences
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.TestPlatform.Build/Tracing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Microsoft.TestPlatform.Build.Trace;
public static class Tracing
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Part of the public API.")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2211:Non-constant fields should not be visible", Justification = "Part of the public API.")]
public static bool traceEnabled = false;

public static void Trace(string message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Common.Telemetry;
/// <summary>
/// The Telemetry data constants.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2211:Non-constant fields should not be visible", Justification = "Part of the public API.")]
public static class TelemetryDataConstants
{
// ******************** Execution ***********************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static string GetExceptionMessage(Exception exception)
{
exceptionString
.AppendLine()
.Append(Resources.Resources.InnerException).Append(" ").AppendLine(inner.Message);
.Append(Resources.Resources.InnerException).Append(' ').AppendLine(inner.Message);
AppendStackTrace(exceptionString, inner);
inner = inner.InnerException;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public ParallelDiscoveryDataAggregator()
/// <returns></returns>
public IDictionary<string, object> GetAggregatedDiscoveryDataMetrics()
{
if (_metricsAggregator == null || _metricsAggregator.Count == 0)
if (_metricsAggregator == null || _metricsAggregator.IsEmpty)
{
return new ConcurrentDictionary<string, object>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public ITestRunStatistics GetAggregatedRunStats()
/// <returns></returns>
public IDictionary<string, object> GetAggregatedRunDataMetrics()
{
if (_metricsAggregator == null || _metricsAggregator.Count == 0)
if (_metricsAggregator == null || _metricsAggregator.IsEmpty)
{
return new ConcurrentDictionary<string, object>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,9 @@ private void ValidateAndAddTriggerBasedProcessDumpParameters(XmlElement collectD
{
case XmlAttribute attribute when string.Equals(attribute.Name, Constants.CollectDumpAlwaysKey, StringComparison.OrdinalIgnoreCase):

if (string.Equals(attribute.Value, Constants.TrueConfigurationValue, StringComparison.OrdinalIgnoreCase) || string.Equals(attribute.Value, Constants.FalseConfigurationValue, StringComparison.OrdinalIgnoreCase))
{
bool.TryParse(attribute.Value, out _collectDumpAlways);
}
else
if ((!string.Equals(attribute.Value, Constants.TrueConfigurationValue, StringComparison.OrdinalIgnoreCase)
&& !string.Equals(attribute.Value, Constants.FalseConfigurationValue, StringComparison.OrdinalIgnoreCase))
|| !bool.TryParse(attribute.Value, out _collectDumpAlways))
{
_logger.LogWarning(_context.SessionDataCollectionContext, string.Format(CultureInfo.CurrentUICulture, Resources.Resources.BlameParameterValueIncorrect, attribute.Name, Constants.TrueConfigurationValue, Constants.FalseConfigurationValue));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ namespace Microsoft.TestPlatform.Extensions.BlameDataCollector;
/// <summary>
/// The blame logger.
/// </summary>
[FriendlyName(BlameLogger.FriendlyName)]
[ExtensionUri(BlameLogger.ExtensionUri)]
[FriendlyName(FriendlyName)]
[ExtensionUri(ExtensionUri)]
public class BlameLogger : ITestLogger
{
#region Constants
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ public override string ToString()
StringBuilder returnString = new();
if (Count > 0)
{
returnString.Append(",");
returnString.Append(',');
foreach (TestCategoryItem item in this)
{
returnString.Append(item.TestCategory);
returnString.Append(",");
returnString.Append(',');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ public override string ToString()
StringBuilder returnString = new();
if (Count > 0)
{
returnString.Append(",");
returnString.Append(',');
foreach (WorkItem item in this)
{
returnString.Append(item);
returnString.Append(",");
returnString.Append(',');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ internal static LoggerSettings FromXml(XmlReader reader)
break;

case Constants.LoggerEnabledName:
bool.TryParse(reader.Value, out var value);
_ = bool.TryParse(reader.Value, out var value);
settings.IsEnabled = value;
break;

Expand Down
32 changes: 12 additions & 20 deletions src/Microsoft.TestPlatform.ObjectModel/TestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,26 +245,18 @@ protected override object ProtectedGetPropertyValue(TestProperty property, objec
{
ValidateArg.NotNull(property, nameof(property));

switch (property.Id)
return property.Id switch
{
case "TestCase.CodeFilePath":
return CodeFilePath;
case "TestCase.DisplayName":
return DisplayName;
case "TestCase.ExecutorUri":
return ExecutorUri;
case "TestCase.FullyQualifiedName":
return FullyQualifiedName;
case "TestCase.Id":
return Id;
case "TestCase.LineNumber":
return LineNumber;
case "TestCase.Source":
return Source;
}

// It is a custom test case property. Should be retrieved from the TestObject store.
return base.ProtectedGetPropertyValue(property, defaultValue);
"TestCase.CodeFilePath" => CodeFilePath,
"TestCase.DisplayName" => DisplayName,
"TestCase.ExecutorUri" => ExecutorUri,
"TestCase.FullyQualifiedName" => FullyQualifiedName,
"TestCase.Id" => Id,
"TestCase.LineNumber" => LineNumber,
"TestCase.Source" => Source,
// It is a custom test case property. Should be retrieved from the TestObject store.
_ => base.ProtectedGetPropertyValue(property, defaultValue),
};
}

/// <summary>
Expand Down Expand Up @@ -398,7 +390,7 @@ private static bool ValidateGuid(object value)
{
try
{
new Guid(value.ToString());
_ = new Guid(value.ToString());
return true;
}
catch (ArgumentNullException)
Expand Down
37 changes: 13 additions & 24 deletions src/vstest.console/Internal/ConsoleLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ internal class ConsoleLogger : ITestLoggerWithParameters
/// </summary>
public const string ExecutionIdPropertyIdentifier = "ExecutionId";

// Figure out the longest result string (+1 for ! where applicable), so we don't
// Figure out the longest result string (+1 for ! where applicable), so we don't
// get misaligned output on non-english systems
private static readonly int LongestResultIndicator = new[]
{
Expand Down Expand Up @@ -134,7 +134,7 @@ internal ConsoleLogger(IOutput output, IProgressIndicator progressIndicator, IFe

#endregion

#region Properties
#region Properties

/// <summary>
/// Gets instance of IOutput used for sending output.
Expand Down Expand Up @@ -163,7 +163,7 @@ protected static IOutput Output
#endif

/// <summary>
/// Tracks leaf test outcomes per source. This is needed to correctly count hierarchical tests as well as
/// Tracks leaf test outcomes per source. This is needed to correctly count hierarchical tests as well as
/// tracking counts per source for the minimal and quiet output.
/// </summary>
private ConcurrentDictionary<Guid, MinimalTestResult> LeafTestResults { get; set; }
Expand Down Expand Up @@ -230,13 +230,13 @@ public void Initialize(TestLoggerEvents events, Dictionary<string, string> param
var prefixExists = parameters.TryGetValue(PrefixParam, out var prefix);
if (prefixExists)
{
bool.TryParse(prefix, out AppendPrefix);
_ = bool.TryParse(prefix, out AppendPrefix);
}

var progressArgExists = parameters.TryGetValue(ProgressIndicatorParam, out var enableProgress);
if (progressArgExists)
{
bool.TryParse(enableProgress, out EnableProgress);
_ = bool.TryParse(enableProgress, out EnableProgress);
}

parameters.TryGetValue(DefaultLoggerParameterNames.TargetFramework, out _targetFramework);
Expand All @@ -249,7 +249,7 @@ public void Initialize(TestLoggerEvents events, Dictionary<string, string> param
#region Private Methods

/// <summary>
/// Prints the timespan onto console.
/// Prints the timespan onto console.
/// </summary>
private static void PrintTimeSpan(TimeSpan timeSpan)
{
Expand Down Expand Up @@ -544,7 +544,7 @@ private void TestResultHandler(object sender, TestResultEventArgs e)

if (!LeafTestResults.TryAdd(executionId, new MinimalTestResult(e.Result)))
{
// This would happen if the key already exists. This should not happen, because we are
// This would happen if the key already exists. This should not happen, because we are
// inserting by GUID key, so this would mean an error in our code.
throw new InvalidOperationException($"ExecutionId {executionId} already exists.");
}
Expand Down Expand Up @@ -751,24 +751,13 @@ private void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e)
sourceOutcome = TestOutcome.Skipped;
}


string resultString;
switch (sourceOutcome)
string resultString = sourceOutcome switch
{
case TestOutcome.Failed:
resultString = (CommandLineResources.FailedTestIndicator + "!").PadRight(LongestResultIndicator);
break;
case TestOutcome.Passed:
resultString = (CommandLineResources.PassedTestIndicator + "!").PadRight(LongestResultIndicator);
break;
case TestOutcome.Skipped:
resultString = (CommandLineResources.SkippedTestIndicator + "!").PadRight(LongestResultIndicator);
break;
default:
resultString = CommandLineResources.None.PadRight(LongestResultIndicator);
break;
}

TestOutcome.Failed => (CommandLineResources.FailedTestIndicator + "!").PadRight(LongestResultIndicator),
TestOutcome.Passed => (CommandLineResources.PassedTestIndicator + "!").PadRight(LongestResultIndicator),
TestOutcome.Skipped => (CommandLineResources.SkippedTestIndicator + "!").PadRight(LongestResultIndicator),
_ => CommandLineResources.None.PadRight(LongestResultIndicator),
};
var failed = sourceSummary.FailedTests.ToString().PadLeft(5);
var passed = sourceSummary.PassedTests.ToString().PadLeft(5);
var skipped = sourceSummary.SkippedTests.ToString().PadLeft(5);
Expand Down
5 changes: 2 additions & 3 deletions src/vstest.console/TestPlatformHelpers/TestRequestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ private bool UpdateRunSettingsIfRequired(
registrar);
settingsUpdated |= UpdateDesignMode(document, runConfiguration);
settingsUpdated |= UpdateCollectSourceInformation(document, runConfiguration);
settingsUpdated |= UpdateTargetDevice(navigator, document, runConfiguration);
settingsUpdated |= UpdateTargetDevice(navigator, document);
settingsUpdated |= AddOrUpdateConsoleLogger(document, runConfiguration, loggerRunSettings);

updatedRunSettingsXml = navigator.OuterXml;
Expand Down Expand Up @@ -752,8 +752,7 @@ private bool AddOrUpdateConsoleLogger(

private bool UpdateTargetDevice(
XPathNavigator navigator,
XmlDocument document,
RunConfiguration runConfiguration)
XmlDocument document)
{
bool updateRequired = InferRunSettingsHelper.TryGetDeviceXml(navigator, out string deviceXml);
if (updateRequired)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected static string DeriveFrameworkArgValue(IntegrationTestEnvironment testE
};

protected bool IsDesktopTargetFramework()
=> _testEnvironment.TargetFramework == AcceptanceTestBase.DesktopTargetFramework;
=> _testEnvironment.TargetFramework == DesktopTargetFramework;

protected string GetTargetFramworkForRunsettings()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class AppDomainTests : AcceptanceTestBase
[NetFullTargetFrameworkDataSource]
public void RunTestExecutionWithDisableAppDomain(RunnerInfo runnerInfo)
{
AcceptanceTestBase.SetTestEnvironment(_testEnvironment, runnerInfo);
SetTestEnvironment(_testEnvironment, runnerInfo);

using var tempDir = new TempDirectory();
var testAppDomainDetailFileName = Path.Combine(tempDir.Path, "appdomain_test.txt");
Expand Down
Loading