diff --git a/.editorconfig b/.editorconfig index 6a4b177981..b58f07026d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -222,6 +222,9 @@ dotnet_diagnostic.CA1304.severity = warning # not default, increased severity to # CA1305: Specify IFormatProvider dotnet_diagnostic.CA1305.severity = warning # not default, increased severity to ensure it is applied +# CA1822: Mark members as static +dotnet_diagnostic.CA1822.severity = warning # not default, increased severity to ensure it is applied + #### C# Coding Conventions #### # var preferences diff --git a/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginCache.cs b/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginCache.cs index e3cdf5ea07..c3c87db9c5 100644 --- a/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginCache.cs +++ b/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginCache.cs @@ -320,8 +320,8 @@ internal Dictionary GetTestExtensions(), + var extensions = TestExtensions.GetExtensionsDiscoveredFromAssembly( + TestExtensions?.GetTestExtensionCache(), extensionAssembly); if (extensions?.Count > 0) @@ -347,7 +347,7 @@ internal Dictionary GetTestExtensions /// The extension assembly. /// Resolution paths for the assembly. - internal IList GetResolutionPaths(string extensionAssembly) + internal static IList GetResolutionPaths(string extensionAssembly) { var resolutionPaths = new List(); @@ -463,7 +463,7 @@ private Dictionary GetTestExtensions(extensionPaths); + return TestPluginDiscoverer.GetTestExtensionsInformation(extensionPaths); } protected void SetupAssemblyResolver(string? extensionAssembly) diff --git a/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginDiscoverer.cs b/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginDiscoverer.cs index 47f813e8a4..795b0b18a2 100644 --- a/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginDiscoverer.cs +++ b/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginDiscoverer.cs @@ -21,17 +21,9 @@ namespace Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework; /// /// Discovers test extensions in a directory. /// -internal class TestPluginDiscoverer +internal static class TestPluginDiscoverer { private static readonly HashSet UnloadableFiles = new(); - private readonly MetadataReaderExtensionsHelper _extensionHelper = new(); - - /// - /// Initializes a new instance of the class. - /// - public TestPluginDiscoverer() - { - } #if WINDOWS_UAP private static HashSet platformAssemblies = new HashSet(new string[] { @@ -58,7 +50,7 @@ public TestPluginDiscoverer() /// /// A dictionary of assembly qualified name and test plugin information. /// - public Dictionary GetTestExtensionsInformation(IEnumerable extensionPaths) where TPluginInfo : TestPluginInformation + public static Dictionary GetTestExtensionsInformation(IEnumerable extensionPaths) where TPluginInfo : TestPluginInformation { TPDebug.Assert(extensionPaths != null); @@ -98,9 +90,10 @@ private static void AddKnownExtensions(ref IEnumerable extensionPaths) /// /// Test plugins collection to add to. /// - private void GetTestExtensionsFromFiles( + private static void GetTestExtensionsFromFiles( string[] files, - Dictionary pluginInfos) where TPluginInfo : TestPluginInformation + Dictionary pluginInfos) + where TPluginInfo : TestPluginInformation { TPDebug.Assert(files != null, "null files"); TPDebug.Assert(pluginInfos != null, "null pluginInfos"); @@ -147,7 +140,8 @@ private void GetTestExtensionsFromFiles( /// /// Type of Extensions. /// - private void GetTestExtensionsFromAssembly(Assembly assembly, Dictionary pluginInfos, string filePath) where TPluginInfo : TestPluginInformation + private static void GetTestExtensionsFromAssembly(Assembly assembly, Dictionary pluginInfos, string filePath) + where TPluginInfo : TestPluginInformation { TPDebug.Assert(assembly != null, "null assembly"); TPDebug.Assert(pluginInfos != null, "null pluginInfos"); @@ -157,7 +151,7 @@ private void GetTestExtensionsFromAssembly(Assembly ass try { - var discoveredExtensions = _extensionHelper.DiscoverTestExtensionTypesV2Attribute(assembly, filePath); + var discoveredExtensions = MetadataReaderExtensionsHelper.DiscoverTestExtensionTypesV2Attribute(assembly, filePath); if (discoveredExtensions?.Length > 0) { types.AddRange(discoveredExtensions); diff --git a/src/Microsoft.TestPlatform.Common/ExtensionFramework/Utilities/TestExtensions.cs b/src/Microsoft.TestPlatform.Common/ExtensionFramework/Utilities/TestExtensions.cs index efb40f74a4..86915df6a8 100644 --- a/src/Microsoft.TestPlatform.Common/ExtensionFramework/Utilities/TestExtensions.cs +++ b/src/Microsoft.TestPlatform.Common/ExtensionFramework/Utilities/TestExtensions.cs @@ -418,7 +418,7 @@ internal void InvalidateCache() /// /// The . of extensions discovered in assembly /// - internal Dictionary GetExtensionsDiscoveredFromAssembly( + internal static Dictionary GetExtensionsDiscoveredFromAssembly( Dictionary? extensionCollection, string? extensionAssembly) { diff --git a/src/Microsoft.TestPlatform.Common/Utilities/AssemblyResolver.cs b/src/Microsoft.TestPlatform.Common/Utilities/AssemblyResolver.cs index 866986f199..8a75ba57be 100644 --- a/src/Microsoft.TestPlatform.Common/Utilities/AssemblyResolver.cs +++ b/src/Microsoft.TestPlatform.Common/Utilities/AssemblyResolver.cs @@ -190,7 +190,7 @@ internal void AddSearchDirectories(IEnumerable directories) /// /// The . /// - private bool RequestedAssemblyNameMatchesFound(AssemblyName requestedName, AssemblyName foundName) + private static bool RequestedAssemblyNameMatchesFound(AssemblyName requestedName, AssemblyName foundName) { TPDebug.Assert(requestedName != null); TPDebug.Assert(foundName != null); diff --git a/src/Microsoft.TestPlatform.Common/Utilities/InstallationContext.cs b/src/Microsoft.TestPlatform.Common/Utilities/InstallationContext.cs index 2acc877874..267faa0d58 100644 --- a/src/Microsoft.TestPlatform.Common/Utilities/InstallationContext.cs +++ b/src/Microsoft.TestPlatform.Common/Utilities/InstallationContext.cs @@ -1,6 +1,7 @@ // 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.Diagnostics.CodeAnalysis; using System.IO; using System.Reflection; @@ -39,11 +40,13 @@ public bool TryGetVisualStudioDirectory(out string visualStudioDirectory) return false; } + [SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Part of the public API")] public string GetVisualStudioPath(string visualStudioDirectory) { return Path.Combine(visualStudioDirectory, DevenvExe); } + [SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Part of the public API")] public string[] GetVisualStudioCommonLocations(string visualStudioDirectory) { return new[] diff --git a/src/Microsoft.TestPlatform.Common/Utilities/MetadataReaderHelper.cs b/src/Microsoft.TestPlatform.Common/Utilities/MetadataReaderHelper.cs index a0083b970c..1a49cf9678 100644 --- a/src/Microsoft.TestPlatform.Common/Utilities/MetadataReaderHelper.cs +++ b/src/Microsoft.TestPlatform.Common/Utilities/MetadataReaderHelper.cs @@ -38,16 +38,16 @@ public TestExtensionTypesV2Attribute(string extensionType, string extensionIdent } } */ -internal class MetadataReaderExtensionsHelper +internal static class MetadataReaderExtensionsHelper { private const string TestExtensionTypesAttributeV2 = "Microsoft.VisualStudio.TestPlatform.TestExtensionTypesV2Attribute"; private static readonly ConcurrentDictionary AssemblyCache = new(); private static readonly Type[] EmptyTypeArray = new Type[0]; - public Type[] DiscoverTestExtensionTypesV2Attribute(Assembly loadedAssembly, string assemblyFilePath) + public static Type[] DiscoverTestExtensionTypesV2Attribute(Assembly loadedAssembly, string assemblyFilePath) => AssemblyCache.GetOrAdd(assemblyFilePath, DiscoverTestExtensionTypesV2AttributeInternal(loadedAssembly, assemblyFilePath)); - private Type[] DiscoverTestExtensionTypesV2AttributeInternal(Assembly loadedAssembly, string assemblyFilePath) + private static Type[] DiscoverTestExtensionTypesV2AttributeInternal(Assembly loadedAssembly, string assemblyFilePath) { EqtTrace.Verbose($"MetadataReaderExtensionsHelper: Discovering extensions inside assembly '{loadedAssembly.FullName}' file path '{assemblyFilePath}'"); diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/JsonDataSerializer.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/JsonDataSerializer.cs index a7a623b2e9..02c0161ab8 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/JsonDataSerializer.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/JsonDataSerializer.cs @@ -292,6 +292,7 @@ private static bool TryGetSubstringUntilDelimiter(string rawMessage, int start, /// Version of serializer to be used. /// Target type to deserialize. /// An instance of . + [SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Part of the public API")] public T? Deserialize(string json, int version = 1) { var payloadSerializer = GetPayloadSerializer(version); @@ -355,6 +356,7 @@ public string SerializePayload(string? messageType, object? payload, int version /// Instance of the object to serialize. /// Version to be stamped. /// JSON string. + [SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Part of the public API")] public string Serialize(T data, int version = 1) { var payloadSerializer = GetPayloadSerializer(version); diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs index f4a2d0c25a..6530060db7 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs @@ -751,7 +751,7 @@ private void SetOperationComplete() Interlocked.CompareExchange(ref _operationCompleted, 1, 0); } - private ICommunicationEndPoint SetCommunicationEndPoint(TestHostConnectionInfo testhostConnectionInfo) + private static ICommunicationEndPoint SetCommunicationEndPoint(TestHostConnectionInfo testhostConnectionInfo) { // TODO: Use factory to get the communication endpoint. It will abstract out the type of communication endpoint like socket, shared memory or named pipe etc., // The connectionInfo here is what is provided to testhost, but we are in runner, and so the role needs diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/TestLoggerManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/TestLoggerManager.cs index 7a5db4544d..b1a37b82ee 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/TestLoggerManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/TestLoggerManager.cs @@ -427,7 +427,7 @@ internal bool TryGetUriFromFriendlyName(string? friendlyName, out Uri? loggerUri /// /// Test run settings. /// Test results directory - internal string? GetResultsDirectory(string? runSettings) + internal static string? GetResultsDirectory(string? runSettings) { string? resultsDirectory = null; if (runSettings != null) @@ -451,7 +451,7 @@ internal bool TryGetUriFromFriendlyName(string? friendlyName, out Uri? loggerUri /// /// Test run settings. /// Target framework - internal Framework? GetTargetFramework(string? runSettings) + internal static Framework? GetTargetFramework(string? runSettings) { Framework? targetFramework = null; if (runSettings != null) @@ -475,7 +475,7 @@ internal bool TryGetUriFromFriendlyName(string? friendlyName, out Uri? loggerUri /// /// /// - internal bool GetTreatNoTestsAsError(string? runSettings) + internal static bool GetTreatNoTestsAsError(string? runSettings) { return RunSettingsUtilities.GetTreatNoTestsAsError(runSettings); } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ProxyDataCollectionManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ProxyDataCollectionManager.cs index c689ebf21f..1cb86f1268 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ProxyDataCollectionManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ProxyDataCollectionManager.cs @@ -281,7 +281,7 @@ private int GetConnectionTimeout(int processId) return connectionTimeout; } - private void InvokeDataCollectionServiceAction(Action action, ITestMessageEventHandler? runEventsHandler) + private static void InvokeDataCollectionServiceAction(Action action, ITestMessageEventHandler? runEventsHandler) { try { diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/PathConverter.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/PathConverter.cs index 03cccc0025..ead3481ded 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/PathConverter.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/PathConverter.cs @@ -119,14 +119,14 @@ public ICollection UpdateAttachmentSets(ICollection UpdateAttachment(a, updateDirection)); return attachmentSet; } - private UriDataAttachment UpdateAttachment(UriDataAttachment attachment, PathConversionDirection _) + private static UriDataAttachment UpdateAttachment(UriDataAttachment attachment, PathConversionDirection _) { ValidateArg.NotNull(attachment, nameof(attachment)); // todo: convert uri? https://github.com/microsoft/vstest/issues/3367 diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Execution/BaseRunTests.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Execution/BaseRunTests.cs index 5d21e64282..8749e0a71a 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Execution/BaseRunTests.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Execution/BaseRunTests.cs @@ -574,7 +574,7 @@ private bool NotRequiredStaThread() } } - private void SetAdapterLoggingSettings() + private static void SetAdapterLoggingSettings() { // TODO: enable the below once runsettings is in. // var sessionMessageLogger = testExecutorFrameworkHandle as TestSessionMessageLogger; diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/ProcDumpDumper.cs b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/ProcDumpDumper.cs index 5c35bd9042..a8295236f1 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/ProcDumpDumper.cs +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/ProcDumpDumper.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; using System.Linq; @@ -48,6 +49,7 @@ public ProcDumpDumper(IProcessHelper processHelper, IFileHelper fileHelper, IEnv _environment = environment; } + [SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Part of the public API")] protected Action OutputReceivedCallback => (process, data) => // useful for visibility when debugging this tool // Console.ForegroundColor = ConsoleColor.Cyan; diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/ProcessDumpUtility.cs b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/ProcessDumpUtility.cs index aa52d7ac75..419493c979 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/ProcessDumpUtility.cs +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/ProcessDumpUtility.cs @@ -39,6 +39,7 @@ public ProcessDumpUtility(IProcessHelper processHelper, IFileHelper fileHelper, _crashDumperFactory = crashDumperFactory; } + [SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Part of the public API")] protected Action OutputReceivedCallback => (process, data) => // Log all standard output message of procdump in diag files. // Otherwise they end up coming on console in pipleine. diff --git a/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/TestElement.cs b/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/TestElement.cs index 9e48e7aae4..32c9c69cf2 100644 --- a/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/TestElement.cs +++ b/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/TestElement.cs @@ -255,6 +255,6 @@ public virtual void Save(System.Xml.XmlElement element, XmlTestStoreParameters? XmlTestStoreParameters testIdParameters = XmlTestStoreParameters.GetParameters(); testIdParameters[TestId.IdLocationKey] = "@id"; - h.SaveObject(_id, element, testIdParameters); + XmlPersistence.SaveObject(_id, element, testIdParameters); } } diff --git a/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/TestEntry.cs b/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/TestEntry.cs index 73c4c97c87..333088bffa 100644 --- a/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/TestEntry.cs +++ b/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/TestEntry.cs @@ -108,7 +108,7 @@ public void Save(System.Xml.XmlElement element, XmlTestStoreParameters? paramete XmlPersistence helper = new(); helper.SaveSingleFields(element, this, parameters); - helper.SaveObject(_testId, element, null); + XmlPersistence.SaveObject(_testId, element, null); helper.SaveGuid(element, "@executionId", ExecutionId); if (ParentExecutionId != Guid.Empty) helper.SaveGuid(element, "@parentExecutionId", ParentExecutionId); diff --git a/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/TestResult.cs b/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/TestResult.cs index 9a22b3c87b..610918355e 100644 --- a/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/TestResult.cs +++ b/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/TestResult.cs @@ -457,7 +457,7 @@ internal void AddResultFiles(IEnumerable resultFileList) TPDebug.Assert(!string.IsNullOrEmpty(resultFile), "'resultFile' is null or empty"); TPDebug.Assert(resultFile.Trim() == resultFile, "'resultFile' has whitespace at the ends"); - _resultFiles[_trxFileHelper.MakePathRelative(resultFile, testResultsDirectory)] = null; + _resultFiles[TrxFileHelper.MakePathRelative(resultFile, testResultsDirectory)] = null; } } diff --git a/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/TestRunConfiguration.cs b/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/TestRunConfiguration.cs index 0cf5b3ff7f..9f71db7581 100644 --- a/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/TestRunConfiguration.cs +++ b/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/TestRunConfiguration.cs @@ -142,7 +142,7 @@ public void Save(XmlElement element, XmlTestStoreParameters? parameters) helper.SaveSimpleField( element, "Deployment/@runDeploymentRoot", - _trxFileHelper.MakePathRelative(_runDeploymentRoot, Path.GetDirectoryName(_runDeploymentRoot)!), + TrxFileHelper.MakePathRelative(_runDeploymentRoot, Path.GetDirectoryName(_runDeploymentRoot)!), string.Empty); } else diff --git a/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/UriDataAttachment.cs b/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/UriDataAttachment.cs index 6faddb2897..9beb7066c7 100644 --- a/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/UriDataAttachment.cs +++ b/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/UriDataAttachment.cs @@ -101,7 +101,7 @@ internal UriDataAttachment Clone(string baseDirectory, bool useAbsoluteUri) { Uri uriToUse = useAbsoluteUri ? new Uri(Path.Combine(baseDirectory, Uri.OriginalString), UriKind.Absolute) - : new Uri(_trxFileHelper.MakePathRelative(Uri.OriginalString, baseDirectory), UriKind.Relative); + : new Uri(TrxFileHelper.MakePathRelative(Uri.OriginalString, baseDirectory), UriKind.Relative); return new UriDataAttachment(Description, uriToUse, _trxFileHelper); } diff --git a/src/Microsoft.TestPlatform.Extensions.TrxLogger/TrxLogger.cs b/src/Microsoft.TestPlatform.Extensions.TrxLogger/TrxLogger.cs index 4087274f8f..8154173ea2 100644 --- a/src/Microsoft.TestPlatform.Extensions.TrxLogger/TrxLogger.cs +++ b/src/Microsoft.TestPlatform.Extensions.TrxLogger/TrxLogger.cs @@ -263,8 +263,8 @@ internal void TestResultHandler(object? sender, TestResultEventArgs e) if (e.Result.Outcome == ObjectModel.TestOutcome.Skipped) HandleSkippedTest(e.Result); - var testType = _converter.GetTestType(e.Result); - var executionId = _converter.GetExecutionId(e.Result); + var testType = Converter.GetTestType(e.Result); + var executionId = Converter.GetExecutionId(e.Result); // Setting parent properties like parent result, parent test element, parent execution id. var parentExecutionId = _converter.GetParentExecutionId(e.Result); @@ -523,7 +523,7 @@ private string SetDefaultTrxFilePath() TPDebug.Assert(IsInitialized, "Logger is not initialized"); var defaultTrxFileName = LoggerTestRun.RunConfiguration.RunDeploymentRootDirectory + ".trx"; - return _trxFileHelper.GetNextIterationFileName(_testResultsDirPath, defaultTrxFileName, false); + return TrxFileHelper.GetNextIterationFileName(_testResultsDirPath, defaultTrxFileName, false); } /// @@ -546,7 +546,7 @@ private void CreateTestRun() LoggerTestRun.Started = TestRunStartTime; // Save default test settings - string runDeploymentRoot = _trxFileHelper.ReplaceInvalidFileNameChars(LoggerTestRun.Name); + string runDeploymentRoot = TrxFileHelper.ReplaceInvalidFileNameChars(LoggerTestRun.Name); TestRunConfiguration testrunConfig = new("default", _trxFileHelper); testrunConfig.RunDeploymentRootDirectory = runDeploymentRoot; LoggerTestRun.RunConfiguration = testrunConfig; @@ -606,7 +606,7 @@ private ITestElement GetOrCreateTestElement(Guid executionId, Guid parentExecuti } TestCase testCase = rockSteadyTestResult.TestCase; - Guid testId = _converter.GetTestId(testCase); + Guid testId = Converter.GetTestId(testCase); // Scenario for inner test case when parent test element is not present. string? testName = testCase.DisplayName; @@ -628,7 +628,7 @@ private ITestElement GetOrCreateTestElement(Guid executionId, Guid parentExecuti // Create test element if (testElement == null) { - testElement = _converter.ToTestElement(testId, executionId, parentExecutionId, testName!, testType, testCase); + testElement = Converter.ToTestElement(testId, executionId, parentExecutionId, testName!, testType, testCase); _testElements.TryAdd(testId, testElement); } @@ -671,7 +671,7 @@ private ITestResult CreateTestResult(Guid executionId, Guid parentExecutionId, T { TPDebug.Assert(IsInitialized, "Logger is not initialized"); // Create test result - TrxLoggerObjectModel.TestOutcome testOutcome = _converter.ToOutcome(rocksteadyTestResult.Outcome); + TrxLoggerObjectModel.TestOutcome testOutcome = Converter.ToOutcome(rocksteadyTestResult.Outcome); TPDebug.Assert(LoggerTestRun != null, "LoggerTestRun is null"); var testResult = _converter.ToTestResult(testElement.Id.Id, executionId, parentExecutionId, testElement.Name, _testResultsDirPath, testType, testElement.CategoryId, testOutcome, LoggerTestRun, rocksteadyTestResult); diff --git a/src/Microsoft.TestPlatform.Extensions.TrxLogger/Utility/Converter.cs b/src/Microsoft.TestPlatform.Extensions.TrxLogger/Utility/Converter.cs index 7358535016..bddab2bb64 100644 --- a/src/Microsoft.TestPlatform.Extensions.TrxLogger/Utility/Converter.cs +++ b/src/Microsoft.TestPlatform.Extensions.TrxLogger/Utility/Converter.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; using System.Linq; @@ -46,7 +47,7 @@ public Converter(IFileHelper fileHelper, TrxFileHelper trxFileHelper) /// /// /// Trx test element - public ITestElement ToTestElement( + public static ITestElement ToTestElement( Guid testId, Guid executionId, Guid parentExecutionId, @@ -141,7 +142,7 @@ public ITestResult ToTestResult( /// /// The . /// - public TrxObjectModel.TestOutcome ToOutcome(VisualStudio.TestPlatform.ObjectModel.TestOutcome rockSteadyOutcome) + public static TrxObjectModel.TestOutcome ToOutcome(VisualStudio.TestPlatform.ObjectModel.TestOutcome rockSteadyOutcome) { TrxObjectModel.TestOutcome outcome = TrxObjectModel.TestOutcome.Failed; @@ -229,7 +230,7 @@ public IList ToResultFiles(IEnumerable? attachmentSets, T /// /// TRX TestResult /// rock steady test result - private void UpdateResultMessages(TrxObjectModel.TestResult unitTestResult, VisualStudio.TestPlatform.ObjectModel.TestResult testResult) + private static void UpdateResultMessages(TrxObjectModel.TestResult unitTestResult, VisualStudio.TestPlatform.ObjectModel.TestResult testResult) { StringBuilder debugTrace = new(); StringBuilder stdErr = new(); @@ -270,7 +271,7 @@ private void UpdateResultMessages(TrxObjectModel.TestResult unitTestResult, Visu /// TestCase object extracted from the TestResult /// Property Name from the list of properties in TestCase /// list of properties - public List GetCustomPropertyValueFromTestCase(TestCase testCase, string categoryId) + public static List GetCustomPropertyValueFromTestCase(TestCase testCase, string categoryId) { var customProperty = testCase.Properties.FirstOrDefault(t => t.Id.Equals(categoryId)); @@ -289,7 +290,7 @@ public List GetCustomPropertyValueFromTestCase(TestCase testCase, string /// /// /// Test id - public Guid GetTestId(TestCase rockSteadyTestCase) + public static Guid GetTestId(TestCase rockSteadyTestCase) { Guid testId = Guid.Empty; @@ -312,6 +313,7 @@ public Guid GetTestId(TestCase rockSteadyTestCase) /// /// /// Parent execution id. + [SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Part of the public API")] public Guid GetParentExecutionId(VisualStudio.TestPlatform.ObjectModel.TestResult testResult) { TestProperty? parentExecutionIdProperty = testResult.Properties.FirstOrDefault( @@ -327,7 +329,7 @@ public Guid GetParentExecutionId(VisualStudio.TestPlatform.ObjectModel.TestResul /// /// /// Execution id. - public Guid GetExecutionId(VisualStudio.TestPlatform.ObjectModel.TestResult testResult) + public static Guid GetExecutionId(VisualStudio.TestPlatform.ObjectModel.TestResult testResult) { TestProperty? executionIdProperty = testResult.Properties.FirstOrDefault( property => property.Id.Equals(Constants.ExecutionIdPropertyIdentifier)); @@ -345,7 +347,7 @@ public Guid GetExecutionId(VisualStudio.TestPlatform.ObjectModel.TestResult test /// /// /// Test type - public TestType GetTestType(VisualStudio.TestPlatform.ObjectModel.TestResult testResult) + public static TestType GetTestType(VisualStudio.TestPlatform.ObjectModel.TestResult testResult) { var testTypeGuid = Constants.UnitTestTypeGuid; @@ -461,7 +463,7 @@ private CollectorDataEntry ToCollectorEntry(AttachmentSet attachmentSet, Guid te TPDebug.Assert(Path.IsPathRooted(sourceFile), "Source file is not rooted"); // copy the source file to the target location - string targetFileName = _trxFileHelper.GetNextIterationFileName(targetDirectory, Path.GetFileName(sourceFile), false); + string targetFileName = TrxFileHelper.GetNextIterationFileName(targetDirectory, Path.GetFileName(sourceFile), false); try { @@ -518,7 +520,7 @@ private IList ToResultFiles(AttachmentSet attachmentSet, Guid testResult TPDebug.Assert(Path.IsPathRooted(sourceFile), "Source file is not rooted"); // copy the source file to the target location - string targetFileName = _trxFileHelper.GetNextIterationFileName(testResultDirectory, Path.GetFileName(sourceFile), false); + string targetFileName = TrxFileHelper.GetNextIterationFileName(testResultDirectory, Path.GetFileName(sourceFile), false); try { diff --git a/src/Microsoft.TestPlatform.Extensions.TrxLogger/Utility/TrxFileHelper.cs b/src/Microsoft.TestPlatform.Extensions.TrxLogger/Utility/TrxFileHelper.cs index 3ab7811f08..58b2f6df05 100644 --- a/src/Microsoft.TestPlatform.Extensions.TrxLogger/Utility/TrxFileHelper.cs +++ b/src/Microsoft.TestPlatform.Extensions.TrxLogger/Utility/TrxFileHelper.cs @@ -67,7 +67,7 @@ public TrxFileHelper(Func timeProvider) /// /// the name of the file /// Replaced string. - public string ReplaceInvalidFileNameChars(string fileName) + public static string ReplaceInvalidFileNameChars(string fileName) { EqtAssert.StringNotNullOrEmpty(fileName, nameof(fileName)); @@ -115,7 +115,7 @@ public string ReplaceInvalidFileNameChars(string fileName) /// /// The . /// - public string GetNextIterationFileName(string parentDirectoryName, string originalFileName, bool checkMatchingDirectory) + public static string GetNextIterationFileName(string parentDirectoryName, string originalFileName, bool checkMatchingDirectory) { EqtAssert.StringNotNullOrEmpty(parentDirectoryName, nameof(parentDirectoryName)); EqtAssert.StringNotNullOrEmpty(originalFileName, nameof(originalFileName)); @@ -162,12 +162,12 @@ public string GetNextTimestampFileName(string directoryName, string fileName, st throw new Exception(string.Format(CultureInfo.CurrentCulture, TrxLoggerResources.Common_CannotGetNextTimestampFileName, fileName, directoryName, timestampFormat)); } - public string MakePathRelative(string path, string basePath) + public static string MakePathRelative(string path, string basePath) { EqtAssert.StringNotNullOrEmpty(path, nameof(path)); // Can't be relative to nothing - if (string.IsNullOrEmpty(basePath)) + if (basePath.IsNullOrEmpty()) { return path; } diff --git a/src/Microsoft.TestPlatform.Extensions.TrxLogger/XML/XmlPersistence.cs b/src/Microsoft.TestPlatform.Extensions.TrxLogger/XML/XmlPersistence.cs index b45e196300..d21da80136 100644 --- a/src/Microsoft.TestPlatform.Extensions.TrxLogger/XML/XmlPersistence.cs +++ b/src/Microsoft.TestPlatform.Extensions.TrxLogger/XML/XmlPersistence.cs @@ -267,7 +267,7 @@ public void SaveObject(object? objectToSave, XmlElement parentXml, string? locat /// /// The parameters. /// - public void SaveObject(object objectToSave, XmlNode nodeToSaveAt, XmlTestStoreParameters? parameters) + public static void SaveObject(object objectToSave, XmlNode nodeToSaveAt, XmlTestStoreParameters? parameters) { SaveObject(objectToSave, nodeToSaveAt, parameters, null); } @@ -287,7 +287,7 @@ public void SaveObject(object objectToSave, XmlNode nodeToSaveAt, XmlTestStorePa /// /// The default value. /// - public void SaveObject(object? objectToSave, XmlNode nodeToSaveAt, XmlTestStoreParameters? parameters, object? defaultValue) + public static void SaveObject(object? objectToSave, XmlNode nodeToSaveAt, XmlTestStoreParameters? parameters, object? defaultValue) { if (objectToSave == null) { diff --git a/src/Microsoft.TestPlatform.ObjectModel/Utilities/AssemblyHelper.cs b/src/Microsoft.TestPlatform.ObjectModel/Utilities/AssemblyHelper.cs index c4c92cf7b2..590b32694c 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Utilities/AssemblyHelper.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Utilities/AssemblyHelper.cs @@ -75,7 +75,7 @@ public static class AssemblyHelper null, null, null); } - return worker.CheckAssemblyReference(source, referenceAssemblyName, referenceAssemblyPublicKeyToken); + return AssemblyLoadWorker.CheckAssemblyReference(source, referenceAssemblyName, referenceAssemblyPublicKeyToken); } finally { @@ -121,7 +121,7 @@ public static KeyValuePair GetFrameworkVersionAn false, BindingFlags.Default, null, null, null, null); - worker.GetPlatformAndFrameworkSettings(testSource, out var procArchType, out var frameworkVersion); + AssemblyLoadWorker.GetPlatformAndFrameworkSettings(testSource, out var procArchType, out var frameworkVersion); Architecture targetPlatform = (Architecture)Enum.Parse(typeof(Architecture), procArchType); var targetFramework = frameworkVersion.ToUpperInvariant() switch @@ -191,7 +191,7 @@ public static KeyValuePair GetFrameworkVersionAn null, null, null); } - return worker.GetReferencedAssemblies(source); + return AssemblyLoadWorker.GetReferencedAssemblies(source); } finally { @@ -270,7 +270,7 @@ internal static string GetTargetFrameworkVersionString(string path) null, null, null); } - return worker.GetTargetFrameworkVersionStringFromPath(path); + return AssemblyLoadWorker.GetTargetFrameworkVersionStringFromPath(path); } finally { diff --git a/src/Microsoft.TestPlatform.ObjectModel/Utilities/AssemblyLoadWorker.cs b/src/Microsoft.TestPlatform.ObjectModel/Utilities/AssemblyLoadWorker.cs index 04ff3106ac..545e3bcfad 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Utilities/AssemblyLoadWorker.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Utilities/AssemblyLoadWorker.cs @@ -22,7 +22,7 @@ internal class AssemblyLoadWorker : MarshalByRefObject /// /// Path of the assembly file /// String representation of the target dot net framework e.g. .NETFramework,Version=v4.0 - public string GetTargetFrameworkVersionStringFromPath(string path) + public static string GetTargetFrameworkVersionStringFromPath(string path) { if (!File.Exists(path)) { @@ -76,9 +76,9 @@ internal static string GetTargetFrameworkStringFromAssembly(Assembly assembly) /// Returns null on failure and an empty array if there is no reference in the project. /// /// Path to the assembly file to load from. - public string[]? GetReferencedAssemblies(string path) + public static string[]? GetReferencedAssemblies(string path) { - TPDebug.Assert(!StringUtils.IsNullOrEmpty(path)); + TPDebug.Assert(!path.IsNullOrEmpty()); Assembly? a = null; try @@ -104,7 +104,7 @@ internal static string GetTargetFrameworkStringFromAssembly(Assembly assembly) /// /// Returns true if given assembly matched name and public key token. /// - public bool? CheckAssemblyReference(string path, string referenceAssemblyName, byte[] publicKeyToken) + public static bool? CheckAssemblyReference(string path, string referenceAssemblyName, byte[] publicKeyToken) { try { @@ -162,7 +162,7 @@ internal static string GetTargetFrameworkStringFromAssembly(Assembly assembly) /// /// /// - public void GetPlatformAndFrameworkSettings(string path, out string procArchType, out string frameworkVersion) + public static void GetPlatformAndFrameworkSettings(string path, out string procArchType, out string frameworkVersion) { procArchType = nameof(Architecture.Default); frameworkVersion = string.Empty; diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/common/Tracing/PlatformEqtTrace.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/common/Tracing/PlatformEqtTrace.cs index 4a3a2a4939..98ab6e49be 100644 --- a/src/Microsoft.TestPlatform.PlatformAbstractions/common/Tracing/PlatformEqtTrace.cs +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/common/Tracing/PlatformEqtTrace.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; @@ -258,6 +259,7 @@ public PlatformTraceLevel GetTraceLevel() return (PlatformTraceLevel)SourceTraceLevelsMap[Source.Switch.Level]; } + [SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Part of the public API")] public TraceLevel MapPlatformTraceToTrace(PlatformTraceLevel traceLevel) { switch (traceLevel) diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/net451/Tracing/PlatformEqtTrace.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/net451/Tracing/PlatformEqtTrace.cs index 75f21c34db..6185920c0e 100644 --- a/src/Microsoft.TestPlatform.PlatformAbstractions/net451/Tracing/PlatformEqtTrace.cs +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/net451/Tracing/PlatformEqtTrace.cs @@ -56,7 +56,7 @@ public void SetupRemoteEqtTraceListeners(AppDomain? childDomain) } } - remoteEqtTrace.SetupRemoteListeners(tptListner); + RemoteEqtTrace.SetupRemoteListeners(tptListner); } else { diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/net451/Tracing/RemoteEqtTrace.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/net451/Tracing/RemoteEqtTrace.cs index b8b167305c..84dae4f736 100644 --- a/src/Microsoft.TestPlatform.PlatformAbstractions/net451/Tracing/RemoteEqtTrace.cs +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/net451/Tracing/RemoteEqtTrace.cs @@ -5,6 +5,7 @@ using System; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; namespace Microsoft.VisualStudio.TestPlatform.ObjectModel; @@ -16,6 +17,7 @@ public sealed class RemoteEqtTrace : MarshalByRefObject /// /// Gets or sets the trace level. /// + [SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Part of the public API")] public TraceLevel TraceLevel { get @@ -33,7 +35,7 @@ public TraceLevel TraceLevel /// Register listeners from parent domain in current domain. /// /// Trace listener instance. - internal void SetupRemoteListeners(TraceListener? listener) + internal static void SetupRemoteListeners(TraceListener? listener) { PlatformEqtTrace.SetupRemoteListeners(listener); } diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/uap10.0/Tracing/PlatformEqtTrace.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/uap10.0/Tracing/PlatformEqtTrace.cs index 65f253efa3..3c5d4368d0 100644 --- a/src/Microsoft.TestPlatform.PlatformAbstractions/uap10.0/Tracing/PlatformEqtTrace.cs +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/uap10.0/Tracing/PlatformEqtTrace.cs @@ -175,7 +175,7 @@ private bool TraceInitialized() } } - private void UnInitializeTrace() + private static void UnInitializeTrace() { s_isInitialized = false; LogFile = null; diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs index de807d83f1..5a4f1cb205 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs @@ -112,6 +112,7 @@ internal DefaultTestHostManager( /// /// Gets the properties of the test executor launcher. These could be the targetID for emulator/phone specific scenarios. /// + [SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Part of the public API")] public IDictionary Properties => new Dictionary(); /// @@ -208,7 +209,7 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo( }; } - private string GetTestHostName(Architecture architecture, Framework targetFramework, PlatformArchitecture processArchitecture) + private static string GetTestHostName(Architecture architecture, Framework targetFramework, PlatformArchitecture processArchitecture) { // We ship multiple executables for testhost that follow this naming schema: // testhost<.tfm><.architecture>.exe diff --git a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs index 84cbefbc60..83a82545c0 100644 --- a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs +++ b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs @@ -92,7 +92,7 @@ public async Task> ProcessAttachmentSetsAsync(XmlElem return attachments; } - private async Task?> MergeCodeCoverageFilesAsync(IList files, IProgress progressReporter, CancellationToken cancellationToken) + private static async Task?> MergeCodeCoverageFilesAsync(IList files, IProgress progressReporter, CancellationToken cancellationToken) { try { @@ -120,7 +120,7 @@ public async Task> ProcessAttachmentSetsAsync(XmlElem return null; } - private async Task?> MergeCodeCoverageFilesAsync(IList files, CancellationToken cancellationToken) + private static async Task?> MergeCodeCoverageFilesAsync(IList files, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); diff --git a/src/SettingsMigrator/Migrator.cs b/src/SettingsMigrator/Migrator.cs index 8a93acd976..e8b4c981ea 100644 --- a/src/SettingsMigrator/Migrator.cs +++ b/src/SettingsMigrator/Migrator.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; using System.Xml; @@ -63,6 +64,7 @@ public class Migrator /// /// Path to old file /// Path to new file + [SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Part of the public API")] public void Migrate(string oldFilePath, string newFilePath) { if (!Path.IsPathRooted(oldFilePath)) @@ -89,7 +91,7 @@ public void Migrate(string oldFilePath, string newFilePath) /// /// Path to old runsettings. /// Path to new runsettings. - private void MigrateRunSettings(string oldRunSettingsPath, string newRunSettingsPath) + private static void MigrateRunSettings(string oldRunSettingsPath, string newRunSettingsPath) { string? testSettingsPath = null; using XmlTextReader reader = new(oldRunSettingsPath); @@ -133,7 +135,7 @@ private void MigrateRunSettings(string oldRunSettingsPath, string newRunSettings /// /// Path to old testsettings. /// Path to new runsettings. - private void MigrateTestSettings(string oldTestSettingsPath, string newRunSettingsPath) + private static void MigrateTestSettings(string oldTestSettingsPath, string newRunSettingsPath) { var runSettingsXmlDoc = new XmlDocument(); runSettingsXmlDoc.LoadXml(SampleRunSettingsContent); @@ -149,7 +151,7 @@ private void MigrateTestSettings(string oldTestSettingsPath, string newRunSettin /// /// Path to test settings /// Runsettings Xml - private void MigrateTestSettingsNodesToRunSettings(string testSettingsPath, XmlDocument runSettingsXmlDoc) + private static void MigrateTestSettingsNodesToRunSettings(string testSettingsPath, XmlDocument runSettingsXmlDoc) { var testSettingsNodes = ReadTestSettingsNodes(testSettingsPath); @@ -199,7 +201,7 @@ private void MigrateTestSettingsNodesToRunSettings(string testSettingsPath, XmlD } } - private TestSettingsNodes ReadTestSettingsNodes(string testSettingsPath) + private static TestSettingsNodes ReadTestSettingsNodes(string testSettingsPath) { var testSettingsNodes = new TestSettingsNodes(); @@ -235,7 +237,7 @@ private TestSettingsNodes ReadTestSettingsNodes(string testSettingsPath) /// Removes the embedded testSettings node if present. /// /// Xml doc to process - private void RemoveEmbeddedTestSettings(XmlDocument newXmlDoc) + private static void RemoveEmbeddedTestSettings(XmlDocument newXmlDoc) { var testSettingsNode = newXmlDoc.DocumentElement.SelectSingleNode(@"/RunSettings/MSTest/SettingsFile"); if (testSettingsNode != null) @@ -252,7 +254,7 @@ private void RemoveEmbeddedTestSettings(XmlDocument newXmlDoc) /// parallelTestCount /// hostProcessPlatform /// newXmlDoc - private void AddLegacyNodes(TestSettingsNodes testSettingsNodes, string? testTimeout, string? parallelTestCount, string? hostProcessPlatform, XmlDocument newXmlDoc) + private static void AddLegacyNodes(TestSettingsNodes testSettingsNodes, string? testTimeout, string? parallelTestCount, string? hostProcessPlatform, XmlDocument newXmlDoc) { if (testSettingsNodes.Deployment == null && testSettingsNodes.Script == null @@ -356,7 +358,7 @@ private void AddLegacyNodes(TestSettingsNodes testSettingsNodes, string? testTim /// /// Datacollector Nodes /// Xml doc to process - private void AddDataCollectorNodes(XmlNodeList oldDatacollectorNodes, XmlDocument newXmlDoc) + private static void AddDataCollectorNodes(XmlNodeList oldDatacollectorNodes, XmlDocument newXmlDoc) { var dataCollectionRunSettingsNode = newXmlDoc.DocumentElement.SelectSingleNode(@"/RunSettings/DataCollectionRunSettings"); if (dataCollectionRunSettingsNode == null) @@ -384,7 +386,7 @@ private void AddDataCollectorNodes(XmlNodeList oldDatacollectorNodes, XmlDocumen /// /// Run Timeout /// Xml doc to process - private void AddRunTimeoutNode(string runTimeout, XmlDocument newXmlDoc) + private static void AddRunTimeoutNode(string runTimeout, XmlDocument newXmlDoc) { var runConfigurationNode = newXmlDoc.DocumentElement.SelectSingleNode(@"/RunSettings/RunConfiguration"); if (runConfigurationNode == null) diff --git a/src/SettingsMigrator/PathResolver.cs b/src/SettingsMigrator/PathResolver.cs index d89d5d066e..8a4fb15d59 100644 --- a/src/SettingsMigrator/PathResolver.cs +++ b/src/SettingsMigrator/PathResolver.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; @@ -19,6 +20,7 @@ public class PathResolver /// /// User inputs /// New file path to create + [SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Part of the public API")] public string? GetTargetPath(string[] args) { string? newFilePath = null; diff --git a/src/vstest.console/CommandLine/CommandLineOptions.cs b/src/vstest.console/CommandLine/CommandLineOptions.cs index 609c012990..fc42e0457a 100644 --- a/src/vstest.console/CommandLine/CommandLineOptions.cs +++ b/src/vstest.console/CommandLine/CommandLineOptions.cs @@ -293,7 +293,7 @@ public void AddSource(string source) /// /// Resets the options. Clears the sources. /// - internal void Reset() + internal static void Reset() { s_instance = null; } diff --git a/src/vstest.console/CommandLine/Executor.cs b/src/vstest.console/CommandLine/Executor.cs index 2dc4ea0dee..dc6c98c0a8 100644 --- a/src/vstest.console/CommandLine/Executor.cs +++ b/src/vstest.console/CommandLine/Executor.cs @@ -349,7 +349,7 @@ private int IdentifyDuplicateArguments(IEnumerable argumentP /// /// The arguments that are being processed. /// A factory for creating argument processors. - private void EnsureActionArgumentIsPresent(List argumentProcessors, ArgumentProcessorFactory processorFactory) + private static void EnsureActionArgumentIsPresent(List argumentProcessors, ArgumentProcessorFactory processorFactory) { ValidateArg.NotNull(argumentProcessors, nameof(argumentProcessors)); ValidateArg.NotNull(processorFactory, nameof(processorFactory)); diff --git a/src/vstest.console/Internal/ConsoleLogger.cs b/src/vstest.console/Internal/ConsoleLogger.cs index 93ed032ec6..686c5a5081 100644 --- a/src/vstest.console/Internal/ConsoleLogger.cs +++ b/src/vstest.console/Internal/ConsoleLogger.cs @@ -382,7 +382,7 @@ private static void DisplayFullInformation(TestResult result) /// /// /// - private Guid GetParentExecutionId(TestResult testResult) + private static Guid GetParentExecutionId(TestResult testResult) { var parentExecutionIdProperty = testResult.Properties.FirstOrDefault(property => property.Id.Equals(ParentExecutionIdPropertyIdentifier)); @@ -396,7 +396,7 @@ private Guid GetParentExecutionId(TestResult testResult) /// /// /// - private Guid GetExecutionId(TestResult testResult) + private static Guid GetExecutionId(TestResult testResult) { var executionIdProperty = testResult.Properties.FirstOrDefault(property => property.Id.Equals(ExecutionIdPropertyIdentifier)); @@ -631,7 +631,7 @@ private void TestResultHandler(object sender, TestResultEventArgs e) static string GetFormattedTestIndicator(string indicator) => TestResultPrefix + indicator + TestResultSuffix; } - private string? GetFormattedDurationString(TimeSpan duration) + private static string? GetFormattedDurationString(TimeSpan duration) { if (duration == default) { diff --git a/src/vstest.console/Processors/CLIRunSettingsArgumentProcessor.cs b/src/vstest.console/Processors/CLIRunSettingsArgumentProcessor.cs index 7573115407..20b0c677b3 100644 --- a/src/vstest.console/Processors/CLIRunSettingsArgumentProcessor.cs +++ b/src/vstest.console/Processors/CLIRunSettingsArgumentProcessor.cs @@ -198,7 +198,7 @@ private void CreateOrOverwriteRunSettings(IRunSettingsProvider runSettingsProvid } } - private bool UpdateTestRunParameterNode(IRunSettingsProvider runSettingsProvider, string node) + private static bool UpdateTestRunParameterNode(IRunSettingsProvider runSettingsProvider, string node) { if (!node.Contains(Constants.TestRunParametersName)) { diff --git a/src/vstest.console/Processors/EnableBlameArgumentProcessor.cs b/src/vstest.console/Processors/EnableBlameArgumentProcessor.cs index 4795320a5d..e8f0505941 100644 --- a/src/vstest.console/Processors/EnableBlameArgumentProcessor.cs +++ b/src/vstest.console/Processors/EnableBlameArgumentProcessor.cs @@ -284,7 +284,7 @@ private void InitializeBlame(bool enableCrashDump, bool enableHangDump, Dictiona /// Parameters. /// Xml document. /// Outer node. - private void AddCollectDumpNode(Dictionary parameters, XmlDocument xmlDocument, XmlElement outernode) + private static void AddCollectDumpNode(Dictionary parameters, XmlDocument xmlDocument, XmlElement outernode) { var dumpNode = xmlDocument.CreateElement(Constants.BlameCollectDumpKey); if (parameters != null && parameters.Count > 0) @@ -305,7 +305,7 @@ private void AddCollectDumpNode(Dictionary parameters, XmlDocume /// Parameters. /// Xml document. /// Outer node. - private void AddCollectHangDumpNode(Dictionary parameters, XmlDocument xmlDocument, XmlElement outernode) + private static void AddCollectHangDumpNode(Dictionary parameters, XmlDocument xmlDocument, XmlElement outernode) { var dumpNode = xmlDocument.CreateElement(Constants.CollectDumpOnTestSessionHang); if (parameters != null && parameters.Count > 0) diff --git a/src/vstest.console/Processors/EnableDiagArgumentProcessor.cs b/src/vstest.console/Processors/EnableDiagArgumentProcessor.cs index 41406c05ea..6139e54ea4 100644 --- a/src/vstest.console/Processors/EnableDiagArgumentProcessor.cs +++ b/src/vstest.console/Processors/EnableDiagArgumentProcessor.cs @@ -162,7 +162,7 @@ public ArgumentProcessorResult Execute() /// /// Diag file path. /// Diag parameters - private void InitializeDiagLogging(string diagFilePath, Dictionary diagParameters) + private static void InitializeDiagLogging(string diagFilePath, Dictionary diagParameters) { // Get trace level from diag parameters. var traceLevel = GetDiagTraceLevel(diagParameters); @@ -183,7 +183,7 @@ private void InitializeDiagLogging(string diagFilePath, Dictionary /// Diag parameters. /// Diag trace level. - private PlatformTraceLevel GetDiagTraceLevel(Dictionary diagParameters) + private static PlatformTraceLevel GetDiagTraceLevel(Dictionary diagParameters) { // If diag parameters is null, set value of trace level as verbose. if (diagParameters == null) diff --git a/src/vstest.console/Processors/ListFullyQualifiedTestsArgumentProcessor.cs b/src/vstest.console/Processors/ListFullyQualifiedTestsArgumentProcessor.cs index 9b925023a2..5f1e32b437 100644 --- a/src/vstest.console/Processors/ListFullyQualifiedTestsArgumentProcessor.cs +++ b/src/vstest.console/Processors/ListFullyQualifiedTestsArgumentProcessor.cs @@ -96,11 +96,6 @@ internal class ListFullyQualifiedTestsArgumentExecutor : IArgumentExecutor /// private readonly ITestDiscoveryEventsRegistrar _discoveryEventsRegistrar; - /// - /// Test case filter instance - /// - private readonly TestCaseFilter _testCasefilter; - /// /// List to store the discovered tests /// @@ -139,8 +134,7 @@ internal ListFullyQualifiedTestsArgumentExecutor( _testRequestManager = testRequestManager; _runSettingsManager = runSettingsProvider; - _testCasefilter = new TestCaseFilter(); - _discoveryEventsRegistrar = new DiscoveryEventsRegistrar(output, _testCasefilter, _discoveredTests, _commandLineOptions); + _discoveryEventsRegistrar = new DiscoveryEventsRegistrar(output, _discoveredTests, _commandLineOptions); } #region IArgumentExecutor @@ -196,13 +190,11 @@ public ArgumentProcessorResult Execute() private class DiscoveryEventsRegistrar : ITestDiscoveryEventsRegistrar { - private readonly TestCaseFilter _testCasefilter; private readonly List _discoveredTests; private readonly CommandLineOptions _options; - public DiscoveryEventsRegistrar(IOutput output, TestCaseFilter filter, List discoveredTests, CommandLineOptions cmdOptions) + public DiscoveryEventsRegistrar(IOutput output, List discoveredTests, CommandLineOptions cmdOptions) { - _testCasefilter = filter; _discoveredTests = discoveredTests; _options = cmdOptions; } @@ -229,9 +221,9 @@ private void DiscoveryRequest_OnDiscoveredTests(object sender, DiscoveredTestsEv } // Initializing the test case filter here because the filter value is read late. - _testCasefilter.Initialize(_options.TestCaseFilterValue); + TestCaseFilter.Initialize(_options.TestCaseFilterValue); var discoveredTests = args.DiscoveredTestCases.ToList(); - var filteredTests = _testCasefilter.FilterTests(discoveredTests).ToList(); + var filteredTests = TestCaseFilter.FilterTests(discoveredTests).ToList(); // remove any duplicate tests filteredTests = filteredTests.Select(test => test.FullyQualifiedName) @@ -242,19 +234,14 @@ private void DiscoveryRequest_OnDiscoveredTests(object sender, DiscoveredTestsEv } } - private class TestCaseFilter + private static class TestCaseFilter { private static TestCaseFilterExpression? s_filterExpression; private const string TestCategory = "TestCategory"; private const string Category = "Category"; private const string Traits = "Traits"; - public TestCaseFilter() - { - - } - - public void Initialize(string? filterString) + public static void Initialize(string? filterString) { ValidateFilter(filterString); } @@ -262,7 +249,7 @@ public void Initialize(string? filterString) /// /// Filter tests /// - public IEnumerable FilterTests(IEnumerable testCases) + public static IEnumerable FilterTests(IEnumerable testCases) { EqtTrace.Verbose("TestCaseFilter.FilterTests : Test Filtering invoked."); diff --git a/src/vstest.console/Publisher/TextFileTelemetryPublisher.cs b/src/vstest.console/Publisher/TextFileTelemetryPublisher.cs index 1a0da9bded..36b287c52f 100644 --- a/src/vstest.console/Publisher/TextFileTelemetryPublisher.cs +++ b/src/vstest.console/Publisher/TextFileTelemetryPublisher.cs @@ -49,7 +49,7 @@ public void Dispose() /// /// The file Helper. /// - internal void LogToFile(string eventName, IDictionary metrics, IFileHelper fileHelper) + internal static void LogToFile(string eventName, IDictionary metrics, IFileHelper fileHelper) { string resultDirectory = Environment.GetEnvironmentVariable("VSTEST_LOGTELEMETRY_PATH") ?? Path.GetTempPath() + "TelemetryLogs"; diff --git a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs index e66f1f6bc5..ddc2657144 100644 --- a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs +++ b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs @@ -150,7 +150,7 @@ public void InitializeExtensions( /// public void ResetOptions() { - _commandLineOptions.Reset(); + CommandLineOptions.Reset(); } /// diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/TestRunAttachmentsProcessingEventHandler.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/TestRunAttachmentsProcessingEventHandler.cs index b862143985..2dd74862ac 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/TestRunAttachmentsProcessingEventHandler.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/TestRunAttachmentsProcessingEventHandler.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using Microsoft.VisualStudio.TestPlatform.ObjectModel; @@ -62,12 +63,14 @@ public void HandleRawMessage(string rawMessage) // No op } + [SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Usage is unclear so keeping as non-static")] public int LaunchProcessWithDebuggerAttached(TestProcessStartInfo _) { // No op return -1; } + [SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Usage is unclear so keeping as non-static")] public bool AttachDebuggerToProcess(int _) { // No op diff --git a/test/Microsoft.TestPlatform.Common.UnitTests/ExtensionFramework/TestPluginCacheTests.cs b/test/Microsoft.TestPlatform.Common.UnitTests/ExtensionFramework/TestPluginCacheTests.cs index 277f2d68e3..a33d8c122c 100644 --- a/test/Microsoft.TestPlatform.Common.UnitTests/ExtensionFramework/TestPluginCacheTests.cs +++ b/test/Microsoft.TestPlatform.Common.UnitTests/ExtensionFramework/TestPluginCacheTests.cs @@ -260,14 +260,14 @@ public void GetDefaultResolutionPathsShouldReturnDirectoryFromDefaultExtensionsP [TestMethod] public void GetResolutionPathsShouldThrowIfExtensionAssemblyIsNull() { - Assert.ThrowsException(() => TestPluginCache.Instance.GetResolutionPaths(null!)); + Assert.ThrowsException(() => TestPluginCache.GetResolutionPaths(null!)); } [TestMethod] public void GetResolutionPathsShouldReturnExtensionAssemblyDirectoryAndTpCommonDirectory() { var temp = Path.GetTempPath(); - var resolutionPaths = TestPluginCache.Instance.GetResolutionPaths($@"{temp}{Path.DirectorySeparatorChar}Idonotexist.dll").Select(p => p.Replace("/", "\\")).ToList(); + var resolutionPaths = TestPluginCache.GetResolutionPaths($@"{temp}{Path.DirectorySeparatorChar}Idonotexist.dll").Select(p => p.Replace("/", "\\")).ToList(); var tpCommonDirectory = Path.GetDirectoryName(typeof(TestPluginCache).GetTypeInfo().Assembly.Location)!; var expectedPaths = new List { temp, tpCommonDirectory }.ConvertAll(p => p.Replace("/", "\\").TrimEnd('\\')); @@ -280,7 +280,7 @@ public void GetResolutionPathsShouldNotHaveDuplicatePathsIfExtensionIsInSameDire { var tpCommonlocation = typeof(TestPluginCache).GetTypeInfo().Assembly.Location; - var resolutionPaths = TestPluginCache.Instance.GetResolutionPaths(tpCommonlocation); + var resolutionPaths = TestPluginCache.GetResolutionPaths(tpCommonlocation); var expectedPaths = new List { Path.GetDirectoryName(tpCommonlocation)! }; diff --git a/test/Microsoft.TestPlatform.Common.UnitTests/ExtensionFramework/TestPluginDiscovererTests.cs b/test/Microsoft.TestPlatform.Common.UnitTests/ExtensionFramework/TestPluginDiscovererTests.cs index 0608e0fd99..43e300c336 100644 --- a/test/Microsoft.TestPlatform.Common.UnitTests/ExtensionFramework/TestPluginDiscovererTests.cs +++ b/test/Microsoft.TestPlatform.Common.UnitTests/ExtensionFramework/TestPluginDiscovererTests.cs @@ -26,20 +26,13 @@ namespace TestPlatform.Common.UnitTests.ExtensionFramework; [TestClass] public class TestPluginDiscovererTests { - private readonly TestPluginDiscoverer _testPluginDiscoverer; - - public TestPluginDiscovererTests() - { - _testPluginDiscoverer = new TestPluginDiscoverer(); - } - [TestMethod] public void GetTestExtensionsInformationShouldNotThrowOnALoadException() { var pathToExtensions = new List { "foo.dll" }; // The below should not throw an exception. - Assert.IsNotNull(_testPluginDiscoverer.GetTestExtensionsInformation(pathToExtensions)); + Assert.IsNotNull(TestPluginDiscoverer.GetTestExtensionsInformation(pathToExtensions)); } [TestMethod] @@ -48,7 +41,7 @@ public void GetTestExtensionsInformationShouldNotConsiderAbstractClasses() var pathToExtensions = new List { typeof(TestPluginDiscovererTests).GetTypeInfo().Assembly.Location }; // The below should not throw an exception. - var testExtensions = _testPluginDiscoverer.GetTestExtensionsInformation(pathToExtensions); + var testExtensions = TestPluginDiscoverer.GetTestExtensionsInformation(pathToExtensions); var discovererPluginInformation = new TestDiscovererPluginInformation(typeof(AbstractTestDiscoverer)); Assert.IsFalse(testExtensions.ContainsKey(discovererPluginInformation.IdentifierData!)); } @@ -59,7 +52,7 @@ public void GetTestExtensionsInformationShouldReturnDiscovererExtensions() var pathToExtensions = new List { typeof(TestPluginDiscovererTests).GetTypeInfo().Assembly.Location }; // The below should not throw an exception. - var testExtensions = _testPluginDiscoverer.GetTestExtensionsInformation(pathToExtensions); + var testExtensions = TestPluginDiscoverer.GetTestExtensionsInformation(pathToExtensions); var discovererPluginInformation = new TestDiscovererPluginInformation(typeof(ValidDiscoverer)); var discovererPluginInformation2 = new TestDiscovererPluginInformation(typeof(ValidDiscoverer2)); @@ -74,7 +67,7 @@ public void GetTestExtensionsInformationShouldReturnExecutorExtensions() var pathToExtensions = new List { typeof(TestPluginDiscovererTests).GetTypeInfo().Assembly.Location }; // The below should not throw an exception. - var testExtensions = _testPluginDiscoverer.GetTestExtensionsInformation(pathToExtensions); + var testExtensions = TestPluginDiscoverer.GetTestExtensionsInformation(pathToExtensions); var pluginInformation = new TestExecutorPluginInformation(typeof(ValidExecutor)); var pluginInformation2 = new TestExecutorPluginInformation(typeof(ValidExecutor2)); @@ -90,7 +83,7 @@ public void GetTestExtensionsInformationShouldReturnLoggerExtensions() var pathToExtensions = new List { typeof(TestPluginDiscovererTests).GetTypeInfo().Assembly.Location }; // The below should not throw an exception. - var testExtensions = _testPluginDiscoverer.GetTestExtensionsInformation(pathToExtensions); + var testExtensions = TestPluginDiscoverer.GetTestExtensionsInformation(pathToExtensions); var pluginInformation = new TestLoggerPluginInformation(typeof(ValidLogger)); var pluginInformation2 = new TestLoggerPluginInformation(typeof(ValidLogger2)); @@ -105,7 +98,7 @@ public void GetTestExtensionsInformationShouldReturnDataCollectorExtensionsAndIg var pathToExtensions = new List { typeof(TestPluginDiscovererTests).GetTypeInfo().Assembly.Location }; // The below should not throw an exception. - var testExtensions = _testPluginDiscoverer.GetTestExtensionsInformation(pathToExtensions); + var testExtensions = TestPluginDiscoverer.GetTestExtensionsInformation(pathToExtensions); var pluginInformation = new DataCollectorConfig(typeof(ValidDataCollector)); @@ -120,7 +113,7 @@ public void GetTestExtensionsInformationShouldReturnSettingsProviderExtensions() var pathToExtensions = new List { typeof(TestPluginDiscovererTests).GetTypeInfo().Assembly.Location }; // The below should not throw an exception. - var testExtensions = _testPluginDiscoverer.GetTestExtensionsInformation(pathToExtensions); + var testExtensions = TestPluginDiscoverer.GetTestExtensionsInformation(pathToExtensions); var pluginInformation = new TestSettingsProviderPluginInformation(typeof(ValidSettingsProvider)); var pluginInformation2 = new TestSettingsProviderPluginInformation(typeof(ValidSettingsProvider2)); @@ -138,9 +131,9 @@ public void GetTestExtensionsInformationShouldNotAbortOnFaultyExtensions() typeof(TestPluginDiscovererTests).GetTypeInfo().Assembly.Location, }; - var testExtensions = _testPluginDiscoverer.GetTestExtensionsInformation(pathToExtensions); + var testExtensions = TestPluginDiscoverer.GetTestExtensionsInformation(pathToExtensions); - Assert.That.DoesNotThrow(() => _testPluginDiscoverer.GetTestExtensionsInformation(pathToExtensions)); + Assert.That.DoesNotThrow(() => TestPluginDiscoverer.GetTestExtensionsInformation(pathToExtensions)); } #region Implementations diff --git a/test/Microsoft.TestPlatform.Common.UnitTests/Utilities/MetadataReaderHelperTests.cs b/test/Microsoft.TestPlatform.Common.UnitTests/Utilities/MetadataReaderHelperTests.cs index 88029d5e0d..4874f0ee06 100644 --- a/test/Microsoft.TestPlatform.Common.UnitTests/Utilities/MetadataReaderHelperTests.cs +++ b/test/Microsoft.TestPlatform.Common.UnitTests/Utilities/MetadataReaderHelperTests.cs @@ -15,8 +15,6 @@ namespace TestPlatform.Common.UnitTests.Utilities; [TestClass] public class MetadataReaderHelperTests { - private readonly MetadataReaderExtensionsHelper _metadataReaderHelper = new(); - [TestMethod] public void MetadataReaderHelper_GetCollectorExtensionTypes() { @@ -25,7 +23,7 @@ public void MetadataReaderHelper_GetCollectorExtensionTypes() Directory.GetFiles(testAssetsPath, "AttachmentProcessorDataCollector.dll", SearchOption.AllDirectories) .Where(x => x.Contains("bin") && x.Contains(IntegrationTestEnvironment.BuildConfiguration)) .Single(); - var types = _metadataReaderHelper.DiscoverTestExtensionTypesV2Attribute(Assembly.LoadFile(dataCollectorFilePath), dataCollectorFilePath); + var types = MetadataReaderExtensionsHelper.DiscoverTestExtensionTypesV2Attribute(Assembly.LoadFile(dataCollectorFilePath), dataCollectorFilePath); Assert.IsTrue(types.Any(), $"File {dataCollectorFilePath}"); Assert.IsTrue(types[0].AssemblyQualifiedName!.StartsWith("AttachmentProcessorDataCollector.SampleDataCollectorV2"), $"File {dataCollectorFilePath}"); Assert.AreEqual(dataCollectorFilePath.Replace("/", @"\"), types[0].Assembly.Location.Replace("/", @"\"), $"File {dataCollectorFilePath}"); diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/TestLoggerManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/TestLoggerManagerTests.cs index 30f7074573..0432df7c67 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/TestLoggerManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/TestLoggerManagerTests.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Reflection; using System.Threading; @@ -66,8 +67,7 @@ public void TryGetUriFromFriendlyNameShouldNotReturnUriIfLoggerIsNotAdded() [TestMethod] public void GetResultsDirectoryShouldReturnNullIfRunSettingsIsNull() { - var testLoggerManager = new DummyTestLoggerManager(); - var result = testLoggerManager.GetResultsDirectory(null); + var result = TestLoggerManager.GetResultsDirectory(null); Assert.IsNull(result); } @@ -84,8 +84,7 @@ public void GetResultsDirectoryShouldReadResultsDirectoryFromSettingsIfSpecified "; - var testLoggerManager = new DummyTestLoggerManager(); - var result = testLoggerManager.GetResultsDirectory(runSettingsXml); + var result = TestLoggerManager.GetResultsDirectory(runSettingsXml); Assert.AreEqual(0, string.Compare("DummyTestResultsFolder", result)); } @@ -101,8 +100,7 @@ public void GetResultsDirectoryShouldReturnDefaultPathIfResultsDirectoryIsNotPro "; - var testLoggerManager = new DummyTestLoggerManager(); - var result = testLoggerManager.GetResultsDirectory(runSettingsXml); + var result = TestLoggerManager.GetResultsDirectory(runSettingsXml); Assert.AreEqual(0, string.Compare(Constants.DefaultResultsDirectory, result)); } @@ -119,8 +117,7 @@ public void GetTargetFrameworkShouldReturnFrameworkProvidedInRunSettings() "; - var testLoggerManager = new DummyTestLoggerManager(); - var framework = testLoggerManager.GetTargetFramework(runSettingsXml); + var framework = TestLoggerManager.GetTargetFramework(runSettingsXml); Assert.AreEqual(".NETFramework,Version=v4.5", framework?.Name); } @@ -1629,6 +1626,7 @@ private class InvalidLogger { public static int Counter; + [SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Usage is unclear so keeping as non-static")] public void Initialize(TestLoggerEvents _, string _2) { Counter++; diff --git a/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/TrxLoggerTests.cs b/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/TrxLoggerTests.cs index cb5ba57490..143e45d2ab 100644 --- a/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/TrxLoggerTests.cs +++ b/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/TrxLoggerTests.cs @@ -743,8 +743,7 @@ public void GetCustomPropertyValueFromTestCaseShouldReadCategoryAttributesFromTe testCase1.SetPropertyValue(testProperty, new[] { "ClassLevel", "AsmLevel" }); - var converter = new Converter(new Mock().Object, new TrxFileHelper()); - List listCategoriesActual = converter.GetCustomPropertyValueFromTestCase(testCase1, "MSTestDiscoverer.TestCategory"); + List listCategoriesActual = Converter.GetCustomPropertyValueFromTestCase(testCase1, "MSTestDiscoverer.TestCategory"); List listCategoriesExpected = new() { @@ -763,8 +762,7 @@ public void GetCustomPropertyValueFromTestCaseShouldReadWorkItemAttributesFromTe testCase1.SetPropertyValue(testProperty, new[] { "99999", "0" }); - var converter = new Converter(new Mock().Object, new TrxFileHelper()); - List listWorkItemsActual = converter.GetCustomPropertyValueFromTestCase(testCase1, "WorkItemIds"); + List listWorkItemsActual = Converter.GetCustomPropertyValueFromTestCase(testCase1, "WorkItemIds"); List listWorkItemsExpected = new() { diff --git a/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/Utility/ConverterTests.cs b/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/Utility/ConverterTests.cs index 63b56ad093..bbec597066 100644 --- a/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/Utility/ConverterTests.cs +++ b/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/Utility/ConverterTests.cs @@ -40,31 +40,31 @@ public ConverterTests() [TestMethod] public void ToOutcomeShouldMapFailedToFailed() { - Assert.AreEqual(TrxLoggerOutcome.Failed, _converter.ToOutcome(TestOutcome.Failed)); + Assert.AreEqual(TrxLoggerOutcome.Failed, Converter.ToOutcome(TestOutcome.Failed)); } [TestMethod] public void ToOutcomeShouldMapPassedToPassed() { - Assert.AreEqual(TrxLoggerOutcome.Passed, _converter.ToOutcome(TestOutcome.Passed)); + Assert.AreEqual(TrxLoggerOutcome.Passed, Converter.ToOutcome(TestOutcome.Passed)); } [TestMethod] public void ToOutcomeShouldMapSkippedToNotExecuted() { - Assert.AreEqual(TrxLoggerOutcome.NotExecuted, _converter.ToOutcome(TestOutcome.Skipped)); + Assert.AreEqual(TrxLoggerOutcome.NotExecuted, Converter.ToOutcome(TestOutcome.Skipped)); } [TestMethod] public void ToOutcomeShouldMapNoneToNotExecuted() { - Assert.AreEqual(TrxLoggerOutcome.NotExecuted, _converter.ToOutcome(TestOutcome.None)); + Assert.AreEqual(TrxLoggerOutcome.NotExecuted, Converter.ToOutcome(TestOutcome.None)); } [TestMethod] public void ToOutcomeShouldMapNotFoundToNotExecuted() { - Assert.AreEqual(TrxLoggerOutcome.NotExecuted, _converter.ToOutcome(TestOutcome.NotFound)); + Assert.AreEqual(TrxLoggerOutcome.NotExecuted, Converter.ToOutcome(TestOutcome.NotFound)); } [TestMethod] @@ -94,7 +94,7 @@ public void ToTestElementShouldAssignTestCategoryOfUnitTestElement() testCase.SetPropertyValue(testProperty, new[] { "AsmLevel", "ClassLevel", "MethodLevel" }); - var unitTestElement = _converter.ToTestElement(testCase.Id, Guid.Empty, Guid.Empty, testCase.DisplayName, TrxLoggerConstants.UnitTestType, testCase); + var unitTestElement = Converter.ToTestElement(testCase.Id, Guid.Empty, Guid.Empty, testCase.DisplayName, TrxLoggerConstants.UnitTestType, testCase); object[] expected = new[] { "MethodLevel", "ClassLevel", "AsmLevel" }; @@ -110,7 +110,7 @@ public void ToTestElementShouldAssignWorkItemOfUnitTestElement() testCase.SetPropertyValue(testProperty, new[] { "3", "99999", "0" }); - var unitTestElement = _converter.ToTestElement(testCase.Id, Guid.Empty, Guid.Empty, testCase.DisplayName, TrxLoggerConstants.UnitTestType, testCase); + var unitTestElement = Converter.ToTestElement(testCase.Id, Guid.Empty, Guid.Empty, testCase.DisplayName, TrxLoggerConstants.UnitTestType, testCase); int[] expected = new[] { 0, 3, 99999 }; @@ -125,7 +125,7 @@ public void ToTestElementShouldNotFailWhenThereIsNoTestCategories() { TestCase testCase = CreateTestCase("TestCase1"); - var unitTestElement = _converter.ToTestElement(testCase.Id, Guid.Empty, Guid.Empty, testCase.DisplayName, TrxLoggerConstants.UnitTestType, testCase); + var unitTestElement = Converter.ToTestElement(testCase.Id, Guid.Empty, Guid.Empty, testCase.DisplayName, TrxLoggerConstants.UnitTestType, testCase); object[] expected = Enumerable.Empty().ToArray(); @@ -197,17 +197,17 @@ public void ToTestElementShouldNotFailWhenClassNameIsTheSameAsFullyQualifiedName expectedClassName = expectedTestName = fullyQualifiedName = source = testName = "test1"; TestCase testCase = new(fullyQualifiedName, new Uri("some://uri"), source); - var unitTestElement = (UnitTestElement)_converter.ToTestElement(testCase.Id, Guid.Empty, Guid.Empty, testName, TrxLoggerConstants.UnitTestType, testCase); + var unitTestElement = (UnitTestElement)Converter.ToTestElement(testCase.Id, Guid.Empty, Guid.Empty, testName, TrxLoggerConstants.UnitTestType, testCase); Assert.AreEqual(expectedClassName, unitTestElement.TestMethod.ClassName); Assert.AreEqual(expectedTestName, unitTestElement.TestMethod.Name); } - private void ValidateTestMethodProperties(string testName, string fullyQualifiedName, string expectedClassName, string expectedTestName) + private static void ValidateTestMethodProperties(string testName, string fullyQualifiedName, string expectedClassName, string expectedTestName) { TestCase testCase = CreateTestCase(fullyQualifiedName); - var unitTestElement = (UnitTestElement)_converter.ToTestElement(testCase.Id, Guid.Empty, Guid.Empty, testName, TrxLoggerConstants.UnitTestType, testCase); + var unitTestElement = (UnitTestElement)Converter.ToTestElement(testCase.Id, Guid.Empty, Guid.Empty, testName, TrxLoggerConstants.UnitTestType, testCase); Assert.AreEqual(expectedClassName, unitTestElement.TestMethod.ClassName); Assert.AreEqual(expectedTestName, unitTestElement.TestMethod.Name); diff --git a/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/Utility/TrxFileHelperTests.cs b/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/Utility/TrxFileHelperTests.cs index 19371aef67..914f864432 100644 --- a/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/Utility/TrxFileHelperTests.cs +++ b/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/Utility/TrxFileHelperTests.cs @@ -13,8 +13,6 @@ public class TrxFileHelperTests [TestMethod] public void ReplaceInvalidFileNameCharsShouldReplaceSpace() { - var fileHelper = new TrxFileHelper(); - - Assert.AreEqual("samadala_SAMADALA_2017-10-13_18_33_17", fileHelper.ReplaceInvalidFileNameChars("samadala_SAMADALA 2017-10-13 18_33_17")); + Assert.AreEqual("samadala_SAMADALA_2017-10-13_18_33_17", TrxFileHelper.ReplaceInvalidFileNameChars("samadala_SAMADALA 2017-10-13 18_33_17")); } } diff --git a/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/XmlPersistenceTests.cs b/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/XmlPersistenceTests.cs index bc410dedae..3ef35906c5 100644 --- a/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/XmlPersistenceTests.cs +++ b/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/XmlPersistenceTests.cs @@ -26,7 +26,7 @@ public void SaveObjectShouldReplaceInvalidCharacter() invalidXmlCharacterArray[6] = (char)0x0; string strWithInvalidCharForXml = new(invalidXmlCharacterArray); - xmlPersistence.SaveObject(strWithInvalidCharForXml, node, null, "dummy"); + XmlPersistence.SaveObject(strWithInvalidCharForXml, node, null, "dummy"); string expectedResult = "\\u0005\\u000b\\u000f\\ud800\\udc00\\ufffe\\u0000"; Assert.AreEqual(0, string.Compare(expectedResult, node.InnerXml)); @@ -51,7 +51,7 @@ public void SaveObjectShouldNotReplaceValidCharacter() string strWithValidCharForXml = new(validXmlCharacterArray); - xmlPersistence.SaveObject(strWithValidCharForXml, node, null, "dummy"); + XmlPersistence.SaveObject(strWithValidCharForXml, node, null, "dummy"); string expectedResult = "\t\n\r 섣�"; Assert.AreEqual(0, string.Compare(expectedResult, node.InnerXml)); @@ -63,7 +63,7 @@ public void SaveObjectShouldReplaceOnlyInvalidCharacter() XmlPersistence xmlPersistence = new(); var node = xmlPersistence.CreateRootElement("TestRun"); string strWithInvalidCharForXml = "This string has these \0 \v invalid characters"; - xmlPersistence.SaveObject(strWithInvalidCharForXml, node, null, "dummy"); + XmlPersistence.SaveObject(strWithInvalidCharForXml, node, null, "dummy"); string expectedResult = "This string has these \\u0000 \\u000b invalid characters"; Assert.AreEqual(0, string.Compare(expectedResult, node.InnerXml)); } diff --git a/test/vstest.ProgrammerTests/BasicRunAndDiscovery.cs b/test/vstest.ProgrammerTests/BasicRunAndDiscovery.cs index 37e71ad330..79f3926154 100644 --- a/test/vstest.ProgrammerTests/BasicRunAndDiscovery.cs +++ b/test/vstest.ProgrammerTests/BasicRunAndDiscovery.cs @@ -7,6 +7,7 @@ using vstest.ProgrammerTests.Fakes; using Intent; +using System.Diagnostics.CodeAnalysis; #pragma warning disable IDE1006 // Naming Styles namespace vstest.ProgrammerTests; @@ -24,6 +25,7 @@ When we run tests. Then all 108 tests are executed. ")] + [SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Specific test needs to be non-static")] public async Task A() { // -- arrange @@ -78,6 +80,7 @@ When we run tests. Then all tests from all assemblies are run. ")] + [SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Specific test needs to be non-static")] public async Task B() { // -- arrange diff --git a/test/vstest.ProgrammerTests/MultiTFMRunAndDiscovery.cs b/test/vstest.ProgrammerTests/MultiTFMRunAndDiscovery.cs index 87b7a179a1..1badc169dd 100644 --- a/test/vstest.ProgrammerTests/MultiTFMRunAndDiscovery.cs +++ b/test/vstest.ProgrammerTests/MultiTFMRunAndDiscovery.cs @@ -12,6 +12,7 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Payloads; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; using System.Reflection; +using System.Diagnostics.CodeAnalysis; namespace vstest.ProgrammerTests; @@ -27,6 +28,7 @@ When we run test discovery. Then two testhosts should be started that target the same framework as each assembly. ")] + [SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Specific test needs to be non-static")] public async Task A() { // -- arrange @@ -127,6 +129,7 @@ and provide runsettings that define the desired target framework. Then two testhosts should be started that target the framework chosen by runsettings. ")] + [SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Specific test needs to be non-static")] public async Task B() { // -- arrange @@ -227,6 +230,7 @@ When we execute tests. Then two testhosts should be started that target the same framework as each assembly. ")] + [SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Specific test needs to be non-static")] public async Task C() { // -- arrange @@ -327,6 +331,7 @@ and provide runsettings that define the desired target framework. Then two testhosts should be started that target the framework chosen by runsettings. ")] + [SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Specific test needs to be non-static")] public async Task D() { // -- arrange @@ -429,6 +434,7 @@ and provide runsettings that define the desired target framework. Then two testhosts should be started that target the framework chosen by runsettings. ")] + [SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Specific test needs to be non-static")] public async Task E() { // -- arrange @@ -546,6 +552,7 @@ and we execute tests. Then two testhosts are both started for the same TFM. ")] + [SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Specific test needs to be non-static")] public async Task E() { // -- arrange diff --git a/test/vstest.console.UnitTests/CommandLine/CommandLineOptionsTests.cs b/test/vstest.console.UnitTests/CommandLine/CommandLineOptionsTests.cs index 02f9b2d647..513f8b607a 100644 --- a/test/vstest.console.UnitTests/CommandLine/CommandLineOptionsTests.cs +++ b/test/vstest.console.UnitTests/CommandLine/CommandLineOptionsTests.cs @@ -27,7 +27,7 @@ public CommandLineOptionsTests() { _fileHelper = new Mock(); _filePatternParser = new FilePatternParser(new Mock().Object, _fileHelper.Object); - CommandLineOptions.Instance.Reset(); + CommandLineOptions.Reset(); CommandLineOptions.Instance.FileHelper = _fileHelper.Object; CommandLineOptions.Instance.FilePatternParser = _filePatternParser; _fileHelper.Setup(fh => fh.GetCurrentDirectory()).Returns(_currentDirectory); diff --git a/test/vstest.console.UnitTests/CommandLine/GenerateFakesUtilitiesTests.cs b/test/vstest.console.UnitTests/CommandLine/GenerateFakesUtilitiesTests.cs index 720aeeb4be..fa36e54029 100644 --- a/test/vstest.console.UnitTests/CommandLine/GenerateFakesUtilitiesTests.cs +++ b/test/vstest.console.UnitTests/CommandLine/GenerateFakesUtilitiesTests.cs @@ -19,7 +19,7 @@ public class GenerateFakesUtilitiesTests public GenerateFakesUtilitiesTests() { _fileHelper = new Mock(); - CommandLineOptions.Instance.Reset(); + CommandLineOptions.Reset(); CommandLineOptions.Instance.FileHelper = _fileHelper.Object; _fileHelper.Setup(fh => fh.GetCurrentDirectory()).Returns(_currentDirectory); _runSettings = @".netstandard,Version=5.0"; diff --git a/test/vstest.console.UnitTests/Internal/ConsoleLoggerTests.cs b/test/vstest.console.UnitTests/Internal/ConsoleLoggerTests.cs index 7f6c9aa564..73ea2ea48c 100644 --- a/test/vstest.console.UnitTests/Internal/ConsoleLoggerTests.cs +++ b/test/vstest.console.UnitTests/Internal/ConsoleLoggerTests.cs @@ -959,7 +959,7 @@ public void TestRunStartHandlerShouldWriteNumberOfTestSourcesDiscoveredOnConsole loggerEvents.EnableEvents(); var fileHelper = new Mock(); - CommandLineOptions.Instance.Reset(); + CommandLineOptions.Reset(); CommandLineOptions.Instance.FileHelper = fileHelper.Object; CommandLineOptions.Instance.FilePatternParser = new FilePatternParser(new Mock().Object, fileHelper.Object); string testFilePath = Path.Combine(Path.GetTempPath(), "DmmyTestFile.dll"); @@ -987,7 +987,7 @@ public void TestRunStartHandlerShouldWriteTestSourcesDiscoveredOnConsoleIfVerbos loggerEvents.EnableEvents(); var fileHelper = new Mock(); - CommandLineOptions.Instance.Reset(); + CommandLineOptions.Reset(); CommandLineOptions.Instance.FileHelper = fileHelper.Object; CommandLineOptions.Instance.FilePatternParser = new FilePatternParser(new Mock().Object, fileHelper.Object); var temp = Path.GetTempPath(); @@ -1021,7 +1021,7 @@ public void TestRunStartHandlerShouldNotWriteTestSourcesDiscoveredOnConsoleIfVer loggerEvents.EnableEvents(); var fileHelper = new Mock(); - CommandLineOptions.Instance.Reset(); + CommandLineOptions.Reset(); CommandLineOptions.Instance.FileHelper = fileHelper.Object; CommandLineOptions.Instance.FilePatternParser = new FilePatternParser(new Mock().Object, fileHelper.Object); var temp = Path.GetTempPath(); diff --git a/test/vstest.console.UnitTests/Processors/CLIRunSettingsArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/CLIRunSettingsArgumentProcessorTests.cs index 38b15f965d..a27be02e89 100644 --- a/test/vstest.console.UnitTests/Processors/CLIRunSettingsArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/CLIRunSettingsArgumentProcessorTests.cs @@ -62,7 +62,7 @@ public CliRunSettingsArgumentProcessorTests() [TestCleanup] public void Cleanup() { - _commandLineOptions.Reset(); + CommandLineOptions.Reset(); } [TestMethod] diff --git a/test/vstest.console.UnitTests/Processors/EnvironmentArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/EnvironmentArgumentProcessorTests.cs index 99468471bd..2e86144420 100644 --- a/test/vstest.console.UnitTests/Processors/EnvironmentArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/EnvironmentArgumentProcessorTests.cs @@ -40,7 +40,7 @@ public EnvironmentArgumentProcessorTests() [TestCleanup] public void Cleanup() { - _commandLineOptions.Reset(); + CommandLineOptions.Reset(); } [TestMethod] diff --git a/test/vstest.console.UnitTests/Processors/FrameworkArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/FrameworkArgumentProcessorTests.cs index 2d662a6efa..69d8e91974 100644 --- a/test/vstest.console.UnitTests/Processors/FrameworkArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/FrameworkArgumentProcessorTests.cs @@ -24,7 +24,7 @@ public FrameworkArgumentProcessorTests() [TestCleanup] public void TestCleanup() { - CommandLineOptions.Instance.Reset(); + CommandLineOptions.Reset(); } [TestMethod] diff --git a/test/vstest.console.UnitTests/Processors/InIsolationArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/InIsolationArgumentProcessorTests.cs index 924bb275a7..2889fe8e0f 100644 --- a/test/vstest.console.UnitTests/Processors/InIsolationArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/InIsolationArgumentProcessorTests.cs @@ -26,7 +26,7 @@ public InIsolationArgumentProcessorTests() [TestCleanup] public void TestCleanup() { - CommandLineOptions.Instance.Reset(); + CommandLineOptions.Reset(); } [TestMethod] diff --git a/test/vstest.console.UnitTests/Processors/ListFullyQualifiedTestsArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/ListFullyQualifiedTestsArgumentProcessorTests.cs index 47e8cb65a0..c822fa458a 100644 --- a/test/vstest.console.UnitTests/Processors/ListFullyQualifiedTestsArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/ListFullyQualifiedTestsArgumentProcessorTests.cs @@ -67,7 +67,7 @@ private static ListFullyQualifiedTestsArgumentExecutor GetExecutor(ITestRequestM public void Cleanup() { File.Delete(_dummyFilePath); - CommandLineOptions.Instance.Reset(); + CommandLineOptions.Reset(); } public ListFullyQualifiedTestsArgumentProcessorTests() @@ -142,7 +142,7 @@ public void ExecutorInitializeWithValidSourceShouldAddItToTestSources() [TestMethod] public void ExecutorExecuteForNoSourcesShouldReturnFail() { - CommandLineOptions.Instance.Reset(); + CommandLineOptions.Reset(); var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, _mockTestPlatformEventSource.Object, _inferHelper, _mockMetricsPublisherTask, _mockProcessHelper.Object, _mockAttachmentsProcessingManager.Object, _mockEnvironment.Object); var executor = GetExecutor(testRequestManager, null); @@ -331,7 +331,7 @@ private void RunListFullyQualifiedTestArgumentProcessorExecuteWithMockSetup(Mock private void ResetAndAddSourceToCommandLineOptions(bool legitPath) { - CommandLineOptions.Instance.Reset(); + CommandLineOptions.Reset(); CommandLineOptions.Instance.FileHelper = _mockFileHelper.Object; CommandLineOptions.Instance.FilePatternParser = new FilePatternParser(new Mock().Object, _mockFileHelper.Object); diff --git a/test/vstest.console.UnitTests/Processors/ListTestsArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/ListTestsArgumentProcessorTests.cs index d09dc9055e..672441f6d2 100644 --- a/test/vstest.console.UnitTests/Processors/ListTestsArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/ListTestsArgumentProcessorTests.cs @@ -65,7 +65,7 @@ private static ListTestsArgumentExecutor GetExecutor(ITestRequestManager testReq [TestCleanup] public void Cleanup() { - CommandLineOptions.Instance.Reset(); + CommandLineOptions.Reset(); } public ListTestsArgumentProcessorTests() @@ -144,7 +144,7 @@ public void ExecutorInitializeWithValidSourceShouldAddItToTestSources() [TestMethod] public void ExecutorExecuteForNoSourcesShouldReturnFail() { - CommandLineOptions.Instance.Reset(); + CommandLineOptions.Reset(); var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, _mockTestPlatformEventSource.Object, _inferHelper, _mockMetricsPublisherTask, _mockProcessHelper.Object, _mockAttachmentsProcessingManager.Object, _mockEnvironment.Object); var executor = GetExecutor(testRequestManager, null); @@ -279,7 +279,7 @@ private void RunListTestArgumentProcessorExecuteWithMockSetup(Mock().Object, _mockFileHelper.Object); diff --git a/test/vstest.console.UnitTests/Processors/ParallelArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/ParallelArgumentProcessorTests.cs index 715e016f8a..9e0580aa63 100644 --- a/test/vstest.console.UnitTests/Processors/ParallelArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/ParallelArgumentProcessorTests.cs @@ -23,7 +23,7 @@ public ParallelArgumentProcessorTests() [TestCleanup] public void TestCleanup() { - CommandLineOptions.Instance.Reset(); + CommandLineOptions.Reset(); } [TestMethod] diff --git a/test/vstest.console.UnitTests/Processors/PlatformArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/PlatformArgumentProcessorTests.cs index e0e22d1a52..207e4590fd 100644 --- a/test/vstest.console.UnitTests/Processors/PlatformArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/PlatformArgumentProcessorTests.cs @@ -24,7 +24,7 @@ public PlatformArgumentProcessorTests() [TestCleanup] public void TestCleanup() { - CommandLineOptions.Instance.Reset(); + CommandLineOptions.Reset(); } [TestMethod] diff --git a/test/vstest.console.UnitTests/Processors/ResponseFileArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/ResponseFileArgumentProcessorTests.cs index dc4489fea0..3c433aefe7 100644 --- a/test/vstest.console.UnitTests/Processors/ResponseFileArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/ResponseFileArgumentProcessorTests.cs @@ -12,7 +12,7 @@ public class ResponseFileArgumentProcessorTests [TestCleanup] public void TestCleanup() { - CommandLineOptions.Instance.Reset(); + CommandLineOptions.Reset(); } [TestMethod] diff --git a/test/vstest.console.UnitTests/Processors/ResultsDirectoryArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/ResultsDirectoryArgumentProcessorTests.cs index 77318f0e33..bc5d345804 100644 --- a/test/vstest.console.UnitTests/Processors/ResultsDirectoryArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/ResultsDirectoryArgumentProcessorTests.cs @@ -28,7 +28,7 @@ public ResultsDirectoryArgumentProcessorTests() [TestCleanup] public void TestCleanup() { - CommandLineOptions.Instance.Reset(); + CommandLineOptions.Reset(); } [TestMethod] diff --git a/test/vstest.console.UnitTests/Processors/RunSettingsArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/RunSettingsArgumentProcessorTests.cs index cb4c752f42..1dd95a544b 100644 --- a/test/vstest.console.UnitTests/Processors/RunSettingsArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/RunSettingsArgumentProcessorTests.cs @@ -33,7 +33,7 @@ public RunSettingsArgumentProcessorTests() [TestCleanup] public void TestCleanup() { - CommandLineOptions.Instance.Reset(); + CommandLineOptions.Reset(); } [TestMethod] diff --git a/test/vstest.console.UnitTests/Processors/RunSpecificTestsArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/RunSpecificTestsArgumentProcessorTests.cs index bc6417ff72..a543cb54ee 100644 --- a/test/vstest.console.UnitTests/Processors/RunSpecificTestsArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/RunSpecificTestsArgumentProcessorTests.cs @@ -117,7 +117,7 @@ public void CapabilitiesShouldReturnAppropriateProperties() [TestMethod] public void InitializeShouldThrowIfArgumentIsNull() { - CommandLineOptions.Instance.Reset(); + CommandLineOptions.Reset(); var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, _mockTestPlatformEventSource.Object, _inferHelper, _mockMetricsPublisherTask, _mockProcessHelper.Object, _mockAttachmentsProcessingManager.Object, _mockEnvironment.Object); var executor = GetExecutor(testRequestManager); @@ -128,7 +128,7 @@ public void InitializeShouldThrowIfArgumentIsNull() [TestMethod] public void InitializeShouldThrowIfArgumentIsEmpty() { - CommandLineOptions.Instance.Reset(); + CommandLineOptions.Reset(); var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, _mockTestPlatformEventSource.Object, _inferHelper, _mockMetricsPublisherTask, _mockProcessHelper.Object, _mockAttachmentsProcessingManager.Object, _mockEnvironment.Object); var executor = GetExecutor(testRequestManager); @@ -139,7 +139,7 @@ public void InitializeShouldThrowIfArgumentIsEmpty() [TestMethod] public void InitializeShouldThrowIfArgumentIsWhiteSpace() { - CommandLineOptions.Instance.Reset(); + CommandLineOptions.Reset(); var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, _mockTestPlatformEventSource.Object, _inferHelper, _mockMetricsPublisherTask, _mockProcessHelper.Object, _mockAttachmentsProcessingManager.Object, _mockEnvironment.Object); var executor = GetExecutor(testRequestManager); @@ -150,7 +150,7 @@ public void InitializeShouldThrowIfArgumentIsWhiteSpace() [TestMethod] public void InitializeShouldThrowIfArgumentsAreEmpty() { - CommandLineOptions.Instance.Reset(); + CommandLineOptions.Reset(); var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, _mockTestPlatformEventSource.Object, _inferHelper, _mockMetricsPublisherTask, _mockProcessHelper.Object, _mockAttachmentsProcessingManager.Object, _mockEnvironment.Object); var executor = GetExecutor(testRequestManager); @@ -161,7 +161,7 @@ public void InitializeShouldThrowIfArgumentsAreEmpty() [TestMethod] public void ExecutorShouldSplitTestsSeparatedByComma() { - CommandLineOptions.Instance.Reset(); + CommandLineOptions.Reset(); var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, _mockTestPlatformEventSource.Object, _inferHelper, _mockMetricsPublisherTask, _mockProcessHelper.Object, _mockAttachmentsProcessingManager.Object, _mockEnvironment.Object); var executor = GetExecutor(testRequestManager); @@ -172,7 +172,7 @@ public void ExecutorShouldSplitTestsSeparatedByComma() [TestMethod] public void ExecutorExecuteForNoSourcesShouldThrowCommandLineException() { - CommandLineOptions.Instance.Reset(); + CommandLineOptions.Reset(); var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, _mockTestPlatformEventSource.Object, _inferHelper, _mockMetricsPublisherTask, _mockProcessHelper.Object, _mockAttachmentsProcessingManager.Object, _mockEnvironment.Object); var executor = GetExecutor(testRequestManager); @@ -601,7 +601,7 @@ public void ExecutorShouldNotDisplayWarningIfTestsAreExecuted() private void ResetAndAddSourceToCommandLineOptions() { - CommandLineOptions.Instance.Reset(); + CommandLineOptions.Reset(); CommandLineOptions.Instance.TestCaseFilterValue = null; CommandLineOptions.Instance.FilePatternParser = new FilePatternParser(new Mock().Object, _mockFileHelper.Object); CommandLineOptions.Instance.FileHelper = _mockFileHelper.Object; diff --git a/test/vstest.console.UnitTests/Processors/RunTestsArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/RunTestsArgumentProcessorTests.cs index d260437ccc..95251ea9ab 100644 --- a/test/vstest.console.UnitTests/Processors/RunTestsArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/RunTestsArgumentProcessorTests.cs @@ -117,7 +117,7 @@ public void ExecutorExecuteShouldReturnSuccessWithoutExecutionInDesignMode() var runSettingsProvider = new TestableRunSettingsProvider(); runSettingsProvider.UpdateRunSettings(""); - CommandLineOptions.Instance.Reset(); + CommandLineOptions.Reset(); CommandLineOptions.Instance.IsDesignMode = true; var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, _mockTestPlatformEventSource.Object, _inferHelper, _mockMetricsPublisherTask, _mockProcessHelper.Object, _mockAttachmentsProcessingManager.Object, _environment.Object); var executor = new RunTestsArgumentExecutor(CommandLineOptions.Instance, runSettingsProvider, testRequestManager, _artifactProcessingManager.Object, _mockOutput.Object); @@ -128,7 +128,7 @@ public void ExecutorExecuteShouldReturnSuccessWithoutExecutionInDesignMode() [TestMethod] public void ExecutorExecuteForNoSourcesShouldThrowCommandLineException() { - CommandLineOptions.Instance.Reset(); + CommandLineOptions.Reset(); var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, _mockTestPlatformEventSource.Object, _inferHelper, _mockMetricsPublisherTask, _mockProcessHelper.Object, _mockAttachmentsProcessingManager.Object, _environment.Object); var executor = GetExecutor(testRequestManager); @@ -272,7 +272,7 @@ private ArgumentProcessorResult RunRunArgumentProcessorExecuteWithMockSetup(ITes private void ResetAndAddSourceToCommandLineOptions() { - CommandLineOptions.Instance.Reset(); + CommandLineOptions.Reset(); CommandLineOptions.Instance.FileHelper = _mockFileHelper.Object; CommandLineOptions.Instance.FilePatternParser = new FilePatternParser(new Mock().Object, _mockFileHelper.Object); diff --git a/test/vstest.console.UnitTests/Processors/TestSourceArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/TestSourceArgumentProcessorTests.cs index a6ae3672ca..9f4533c153 100644 --- a/test/vstest.console.UnitTests/Processors/TestSourceArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/TestSourceArgumentProcessorTests.cs @@ -95,7 +95,7 @@ public void ExecuterInitializeWithValidSourceShouldAddItToTestSources() mockFileHelper.Setup(x => x.GetCurrentDirectory()).Returns(""); var options = CommandLineOptions.Instance; - options.Reset(); + CommandLineOptions.Reset(); options.FileHelper = mockFileHelper.Object; options.FilePatternParser = new FilePatternParser(new Mock().Object, mockFileHelper.Object); var executor = new TestSourceArgumentExecutor(options); diff --git a/test/vstest.console.UnitTests/Publisher/TextFileTelemetryPublisherTests.cs b/test/vstest.console.UnitTests/Publisher/TextFileTelemetryPublisherTests.cs index f8f5a8b5f1..f37e996488 100644 --- a/test/vstest.console.UnitTests/Publisher/TextFileTelemetryPublisherTests.cs +++ b/test/vstest.console.UnitTests/Publisher/TextFileTelemetryPublisherTests.cs @@ -17,7 +17,6 @@ public class TextFileTelemetryPublisherTests [TestMethod] public void LogToFileShouldCreateDirectoryIfNotExists() { - var publishMetrics = new TextFileTelemetryPublisher(); var dummyDictionary = new Dictionary(); var mockFileHelper = new Mock(); mockFileHelper.Setup(fh => fh.DirectoryExists(It.IsAny())).Returns(false); @@ -25,7 +24,7 @@ public void LogToFileShouldCreateDirectoryIfNotExists() dummyDictionary.Add("Dummy2", "DummyValue2"); // Act. - publishMetrics.LogToFile("dummyevent", dummyDictionary, mockFileHelper.Object); + TextFileTelemetryPublisher.LogToFile("dummyevent", dummyDictionary, mockFileHelper.Object); // Verify. mockFileHelper.Verify(fh => fh.CreateDirectory(It.IsAny()), Times.Once); @@ -34,14 +33,13 @@ public void LogToFileShouldCreateDirectoryIfNotExists() [TestMethod] public void LogToFileShouldWriteAllText() { - var publishMetrics = new TextFileTelemetryPublisher(); var dummyDictionary = new Dictionary(); var mockFileHelper = new Mock(); dummyDictionary.Add("DummyMessage://", "DummyValue"); dummyDictionary.Add("Dummy2", "DummyValue2"); // Act. - publishMetrics.LogToFile("dummyevent", dummyDictionary, mockFileHelper.Object); + TextFileTelemetryPublisher.LogToFile("dummyevent", dummyDictionary, mockFileHelper.Object); // Verify. mockFileHelper.Verify(fh => fh.WriteAllTextToFile(It.IsAny(), It.IsAny()), Times.Once); diff --git a/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs b/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs index 0e7a6480e9..b31509790f 100644 --- a/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs +++ b/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs @@ -107,7 +107,7 @@ public TestRequestManagerTests() [TestCleanup] public void Cleanup() { - CommandLineOptions.Instance.Reset(); + CommandLineOptions.Reset(); // Opt out the Telemetry Environment.SetEnvironmentVariable("VSTEST_TELEMETRY_OPTEDIN", "0");