Skip to content

Commit

Permalink
make some methods static (#4564)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Jan 9, 2025
1 parent 395aee9 commit e482b23
Show file tree
Hide file tree
Showing 20 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ private static async Task LogTestHostCreatedAsync(
}
}

private async Task<ITestFramework> BuildTestFrameworkAsync(TestFrameworkBuilderData testFrameworkBuilderData)
private static async Task<ITestFramework> BuildTestFrameworkAsync(TestFrameworkBuilderData testFrameworkBuilderData)
{
// Add the message bus proxy
ServiceProvider serviceProvider = testFrameworkBuilderData.ServiceProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task SendingEmptyDataToDynamicDataTest_WithoutSettingConsiderEmptyD
public async Task SendingEmptyDataToDataSourceTest_WithoutSettingConsiderEmptyDataSourceAsInconclusive_Fails(string currentTfm)
=> await RunTestsAsync(currentTfm, DataSourceAssetName, null);

private async Task RunTestsAsync(string currentTfm, string assetName, bool? isEmptyDataInconclusive)
private static async Task RunTestsAsync(string currentTfm, string assetName, bool? isEmptyDataInconclusive)
{
var testHost = TestHost.LocateFrom(AssetFixture.GetAssetPath(assetName), assetName, currentTfm);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task ThreadingContext_WhenChangedInClassInitialize_IsPassedToTestMe
public async Task ThreadingContext_WhenChangedInTestInitialize_IsPassedToTestMethod(string tfm)
=> await SetCultureInFixtureMethodAndRunTests(tfm, "MSTEST_TEST_SET_CULTURE_TEST_INIT");

private async Task SetCultureInFixtureMethodAndRunTests(string tfm, string envVarKey)
private static async Task SetCultureInFixtureMethodAndRunTests(string tfm, string envVarKey)
{
var testHost = TestHost.LocateFrom(AssetFixture.InitToTestProjectPath, TestAssetFixture.InitToTestProjectName, tfm);
TestHostResult testHostResult = await testHost.ExecuteAsync(environmentVariables: new() { [envVarKey] = "true" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,21 +362,21 @@ public async Task CooperativeCancellation_WhenTestCleanupTimeoutExpiresAndUserCh
testHostResult.AssertOutputContains("Test cleanup method 'TestClass.TestCleanup' timed out after 1000ms");
}

private async Task RunAndAssertTestWasCanceledAsync(string rootFolder, string assetName, string tfm, string envVarPrefix, string entryKind)
private static async Task RunAndAssertTestWasCanceledAsync(string rootFolder, string assetName, string tfm, string envVarPrefix, string entryKind)
{
var testHost = TestHost.LocateFrom(rootFolder, assetName, tfm);
TestHostResult testHostResult = await testHost.ExecuteAsync(environmentVariables: new() { { envVarPrefix + InfoByKind[entryKind].EnvVarSuffix, "1" } });
testHostResult.AssertOutputContains($"{InfoByKind[entryKind].Prefix} method '{InfoByKind[entryKind].MethodFullName}' was canceled");
}

private async Task RunAndAssertTestTimedOutAsync(string rootFolder, string assetName, string tfm, string envVarPrefix, string entryKind)
private static async Task RunAndAssertTestTimedOutAsync(string rootFolder, string assetName, string tfm, string envVarPrefix, string entryKind)
{
var testHost = TestHost.LocateFrom(rootFolder, assetName, tfm);
TestHostResult testHostResult = await testHost.ExecuteAsync(environmentVariables: new() { { envVarPrefix + InfoByKind[entryKind].EnvVarSuffix, "1" } });
testHostResult.AssertOutputContains($"{InfoByKind[entryKind].Prefix} method '{InfoByKind[entryKind].MethodFullName}' timed out after 1000ms");
}

private async Task RunAndAssertWithRunSettingsAsync(string tfm, int timeoutValue, bool assertAttributePrecedence, string entryKind)
private static async Task RunAndAssertWithRunSettingsAsync(string tfm, int timeoutValue, bool assertAttributePrecedence, string entryKind)
{
string runSettingsEntry = InfoByKind[entryKind].RunSettingsEntryName;
string runSettings = $"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class OutputTests : CLITestBase

public void OutputIsNotMixedWhenAsyncTestsRunInParallel() => ValidateOutputForClass("UnitTest2");

private void ValidateOutputForClass(string className)
private static void ValidateOutputForClass(string className)
{
// LogMessageListener uses an implementation of a string writer that captures output per async context.
// This allows us to capture output from tasks even when they are running in parallel.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Microsoft.MSTestV2.CLIAutomation;

public partial class CLITestBase : TestContainer
{
internal ImmutableArray<TestCase> DiscoverTests(string assemblyPath, string testCaseFilter = null)
internal static ImmutableArray<TestCase> DiscoverTests(string assemblyPath, string testCaseFilter = null)
{
var unitTestDiscoverer = new UnitTestDiscoverer();
var logger = new InternalLogger();
Expand All @@ -33,7 +33,7 @@ internal ImmutableArray<TestCase> DiscoverTests(string assemblyPath, string test
return sink.DiscoveredTests;
}

internal ImmutableArray<TestResult> RunTests(IEnumerable<TestCase> testCases)
internal static ImmutableArray<TestResult> RunTests(IEnumerable<TestCase> testCases)
{
var testExecutionManager = new TestExecutionManager();
var frameworkHandle = new InternalFrameworkHandle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void RunSingleTest_ClassInitialize_Failure_Runs_AssemblyFixtures()
ValidatePassedTests([AssemblyInitialize, AssemblyCleanup, ClassCleanup]);
}

private string GetRunSettings(bool fixturesEnabled, bool assemblyInitialize, bool assemblyCleanup, bool classInitialize, bool classCleanup, bool test)
private static string GetRunSettings(bool fixturesEnabled, bool assemblyInitialize, bool assemblyCleanup, bool classInitialize, bool classCleanup, bool test)
=> $@"<?xml version=""1.0"" encoding=""utf-8""?>
<RunSettings>
<RunConfiguration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public async Task Diag_EnableWithEnvironmentVariables_Disable_Succeeded(string t
testHostResult.AssertOutputContains("Diagnostic file");
}

private async Task<string> AssertDiagnosticReportWasGeneratedAsync(TestHostResult testHostResult, string diagPathPattern, string level = "Trace", string flushType = "async")
private static async Task<string> AssertDiagnosticReportWasGeneratedAsync(TestHostResult testHostResult, string diagPathPattern, string level = "Trace", string flushType = "async")
{
testHostResult.AssertExitCodeIs(ExitCodes.ZeroTests);

Expand All @@ -218,7 +218,7 @@ private async Task<string> AssertDiagnosticReportWasGeneratedAsync(TestHostResul
return match.Value;
}

private async Task<(bool IsMatch, string Content)> CheckDiagnosticContentsMatchAsync(string path, string pattern)
private static async Task<(bool IsMatch, string Content)> CheckDiagnosticContentsMatchAsync(string path, string pattern)
{
using var reader = new StreamReader(path);
string content = await reader.ReadToEndAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public async Task Telemetry_WhenEnableTelemetryIsFalse_WithTestApplicationOption
await AssertDiagnosticReportAsync(testHostResult, diagPathPattern, diagContentsPattern);
}

private async Task<string> AssertDiagnosticReportAsync(TestHostResult testHostResult, string diagPathPattern, string diagContentsPattern, string level = "Trace", string flushType = "async")
private static async Task<string> AssertDiagnosticReportAsync(TestHostResult testHostResult, string diagPathPattern, string diagContentsPattern, string level = "Trace", string flushType = "async")
{
testHostResult.AssertExitCodeIs(ExitCodes.ZeroTests);

Expand All @@ -126,7 +126,7 @@ private async Task<string> AssertDiagnosticReportAsync(TestHostResult testHostRe
return match.Value;
}

private async Task<(bool IsMatch, string Content)> CheckDiagnosticContentsMatchAsync(string path, string pattern)
private static async Task<(bool IsMatch, string Content)> CheckDiagnosticContentsMatchAsync(string path, string pattern)
{
using var reader = new StreamReader(path);
string content = await reader.ReadToEndAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private async Task AssertTrxReportWasGeneratedAsync(TestHostResult testHostResul
Assert.IsTrue(await CheckTrxContentsMatchAsync(match.Value, trxContentsPattern), $"Output of the test host is:\n{testHostResult}");
}

private async Task<bool> CheckTrxContentsMatchAsync(string path, string pattern)
private static async Task<bool> CheckTrxContentsMatchAsync(string path, string pattern)
{
using StreamReader reader = new(path);
return Regex.IsMatch(await reader.ReadToEndAsync(), pattern);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public void GetSpecificCustomAttributesOnAssemblyShouldReturnAllAttributes()
GetAttributeValuePairs(attributes).Should().Equal(expectedAttributes);
}

private Assembly ReflectionOnlyOnResolve(object sender, ResolveEventArgs args)
private static Assembly ReflectionOnlyOnResolve(object sender, ResolveEventArgs args)
{
string assemblyNameToLoad = AppDomain.CurrentDomain.ApplyPolicy(args.Name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public async Task<Files> ExecuteAsync(BuildArtifact payload, IContext context)
return new Files([sample]);
}

private async Task<string> PerfviewExecutable()
private static async Task<string> PerfviewExecutable()
{
string localPath = Path.Combine(Path.GetTempPath(), "PerfView", "PerfView.exe");
Directory.CreateDirectory(Path.GetDirectoryName(localPath)!);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public override void Initialize(AnalysisContext context)
context.RegisterSymbolAction(AnalyzeSymbol, SymbolKind.Method);
}

private void AnalyzeSymbol(SymbolAnalysisContext context)
private static void AnalyzeSymbol(SymbolAnalysisContext context)
{
var method = (IMethodSymbol)context.Symbol;
if (method.Name.EndsWith("Async", StringComparison.Ordinal))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public override void Initialize(AnalysisContext context)
context.RegisterSymbolAction(AnalyzeSymbol, SymbolKind.Method);
}

private void AnalyzeSymbol(SymbolAnalysisContext context)
private static void AnalyzeSymbol(SymbolAnalysisContext context)
{
var method = (IMethodSymbol)context.Symbol;
if (method.Name.EndsWith("Async", StringComparison.Ordinal))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ private void SetupNavigation(string source, UnitTestElement test, string classNa
SetTestCaseNavigationData(testCase1, testNavigationData.FileName, testNavigationData.MinLineNumber);
}

private void SetTestCaseNavigationData(TestCase testCase, string fileName, int lineNumber)
private static void SetTestCaseNavigationData(TestCase testCase, string fileName, int lineNumber)
{
testCase.LineNumber = lineNumber;
testCase.CodeFilePath = fileName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,7 @@ public void ResolveArgumentsShouldReturnPopulatedParamsWithAllProvided()

#region helper methods

private void RunWithTestablePlatformService(TestablePlatformServiceProvider testablePlatformServiceProvider, Action action)
private static void RunWithTestablePlatformService(TestablePlatformServiceProvider testablePlatformServiceProvider, Action action)
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.Testing.Platform.UnitTests;
[TestClass]
public sealed class ConfigurationExtensionsTests
{
private string GetActualValueFromConfiguration(IConfiguration configuration, string key) => key switch
private static string GetActualValueFromConfiguration(IConfiguration configuration, string key) => key switch
{
PlatformConfigurationConstants.PlatformResultDirectory => configuration.GetTestResultDirectory(),
PlatformConfigurationConstants.PlatformCurrentWorkingDirectory => configuration.GetCurrentWorkingDirectory(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void DeserializeSpecificTypes(Type type)
}
}

private void AssertRequestArgs<TRequestArgs>(Type type, TRequestArgs actualRequest, TRequestArgs expectedRequest)
private static void AssertRequestArgs<TRequestArgs>(Type type, TRequestArgs actualRequest, TRequestArgs expectedRequest)
where TRequestArgs : RequestArgsBase
{
Assert.AreEqual(expectedRequest.RunId, actualRequest.RunId);
Expand Down
2 changes: 1 addition & 1 deletion test/Utilities/Automation.CLI/CLITestBase.e2e.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static string GetNugetPackageFolder()
/// Gets the path to <c>vstest.console.exe</c>.
/// </summary>
/// <returns>Full path to <c>vstest.console.exe</c>.</returns>
public string GetConsoleRunnerPath()
public static string GetConsoleRunnerPath()
{
string testPlatformNuGetPackageFolder = Path.Combine(
GetNugetPackageFolder(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public async Task<int> ExecuteAsync(
cleanDefaultEnvironmentVariableIfCustomAreProvided: true,
timeoutInSeconds: timeoutInSeconds);

private IDictionary<string, string?> MergeEnvironmentVariables(
private static IDictionary<string, string?> MergeEnvironmentVariables(
IDictionary<string, string?> environmentVariables1,
IDictionary<string, string?> environmentVariables2)
{
Expand Down

0 comments on commit e482b23

Please sign in to comment.