Skip to content

Commit

Permalink
More simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink committed Dec 26, 2024
1 parent 1e54abb commit d8b5212
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/Adapter/MSTest.TestAdapter/PlatformServiceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ private PlatformServiceProvider() =>
#if !WINDOWS_UWP
// Set the provider that is used by DynamicDataAttribute when generating data, to allow substituting functionality
// in TestFramework without having to put all the stuff in that library.
TestTools.UnitTesting.DynamicDataProvider.Instance = SourceGeneratorToggle.UseSourceGenerator
UTF.DynamicDataProvider.Instance = SourceGeneratorToggle.UseSourceGenerator
? new SourceGeneratedDynamicDataOperations()
: new DynamicDataOperations();
#else
TestTools.UnitTesting.DynamicDataProvider.Instance = new DynamicDataOperations();
UTF.DynamicDataProvider.Instance = new DynamicDataOperations();
#endif

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal sealed class MSTestBannerCapability : IBannerMessageOwnerCapability
}

#if NETCOREAPP
if (System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeCompiled)
if (RuntimeFeature.IsDynamicCodeCompiled)
#endif
{
bannerMessage.Append(" [");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class MSTestDiscoverer : ITestDiscoverer
/// <param name="discoverySink">Used to send testcases and discovery related events back to Discoverer manager.</param>
[System.Security.SecurityCritical]
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0", Justification = "Discovery context can be null.")]
public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink) => MSTestDiscoverer.DiscoverTests(sources, discoveryContext, logger, discoverySink, null);
public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink) => DiscoverTests(sources, discoveryContext, logger, discoverySink, null);

internal static void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink, IConfiguration? configuration)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal sealed class ReflectionOperations2 : ReflectionOperations, IReflectionO
public ReflectionOperations2()
{
#if NET8_0_OR_GREATER
if (!System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported)
if (!RuntimeFeature.IsDynamicCodeSupported)
{
throw new NotSupportedException("ReflectionOperations2 are not allowed when dynamic code is not supported, use NativeReflectionOperations instead");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public Task<ValidationResult> ValidateTestHostEnvironmentVariablesAsync(IReadOnl
static void AddError(StringBuilder errors, string variableName, string? expectedValue, string? actualValue)
{
string actualValueString = actualValue ?? "<null>";
errors.AppendLine(string.Format(System.Globalization.CultureInfo.InvariantCulture, CrashDumpResources.CrashDumpInvalidEnvironmentVariableValueErrorMessage, variableName, expectedValue, actualValueString));
errors.AppendLine(string.Format(CultureInfo.InvariantCulture, CrashDumpResources.CrashDumpInvalidEnvironmentVariableValueErrorMessage, variableName, expectedValue, actualValueString));
}
#endif
}
Expand Down
22 changes: 11 additions & 11 deletions src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ await LogTestHostCreatedAsync(
}

// Build the test host
ConsoleTestHost consoleHost = TestHostBuilder.CreateConsoleTestHost(
ConsoleTestHost consoleHost = CreateConsoleTestHost(
serviceProvider,
BuildTestFrameworkAsync,
(TestFrameworkManager)TestFramework,
Expand Down Expand Up @@ -648,10 +648,10 @@ private async Task<ITestFramework> BuildTestFrameworkAsync(TestFrameworkBuilderD
// creations and we could lose interesting diagnostic information.
List<IDataConsumer> dataConsumersBuilder = [];

await TestHostBuilder.RegisterAsServiceOrConsumerOrBothAsync(testFrameworkBuilderData.PlatformOutputDisplayService, serviceProvider, dataConsumersBuilder);
await TestHostBuilder.RegisterAsServiceOrConsumerOrBothAsync(testFrameworkBuilderData.TestExecutionRequestFactory, serviceProvider, dataConsumersBuilder);
await TestHostBuilder.RegisterAsServiceOrConsumerOrBothAsync(testFrameworkBuilderData.TestExecutionRequestInvoker, serviceProvider, dataConsumersBuilder);
await TestHostBuilder.RegisterAsServiceOrConsumerOrBothAsync(testFrameworkBuilderData.TestExecutionFilterFactory, serviceProvider, dataConsumersBuilder);
await RegisterAsServiceOrConsumerOrBothAsync(testFrameworkBuilderData.PlatformOutputDisplayService, serviceProvider, dataConsumersBuilder);
await RegisterAsServiceOrConsumerOrBothAsync(testFrameworkBuilderData.TestExecutionRequestFactory, serviceProvider, dataConsumersBuilder);
await RegisterAsServiceOrConsumerOrBothAsync(testFrameworkBuilderData.TestExecutionRequestInvoker, serviceProvider, dataConsumersBuilder);
await RegisterAsServiceOrConsumerOrBothAsync(testFrameworkBuilderData.TestExecutionFilterFactory, serviceProvider, dataConsumersBuilder);

// Create the test framework adapter
ITestFrameworkCapabilities testFrameworkCapabilities = serviceProvider.GetTestFrameworkCapabilities();
Expand All @@ -661,7 +661,7 @@ private async Task<ITestFramework> BuildTestFrameworkAsync(TestFrameworkBuilderD
serviceProvider.AllowTestAdapterFrameworkRegistration = true;
try
{
await TestHostBuilder.RegisterAsServiceOrConsumerOrBothAsync(new TestFrameworkProxy(testFramework), serviceProvider, dataConsumersBuilder);
await RegisterAsServiceOrConsumerOrBothAsync(new TestFrameworkProxy(testFramework), serviceProvider, dataConsumersBuilder);
}
finally
{
Expand All @@ -687,11 +687,11 @@ private async Task<ITestFramework> BuildTestFrameworkAsync(TestFrameworkBuilderD
{
if (testhostExtension.Extension is IDataConsumer)
{
await TestHostBuilder.RegisterAsServiceOrConsumerOrBothAsync(testhostExtension.Extension, serviceProvider, dataConsumersBuilder);
await RegisterAsServiceOrConsumerOrBothAsync(testhostExtension.Extension, serviceProvider, dataConsumersBuilder);
}
else
{
await TestHostBuilder.AddServiceIfNotSkippedAsync(testhostExtension.Extension, serviceProvider);
await AddServiceIfNotSkippedAsync(testhostExtension.Extension, serviceProvider);
}
}
}
Expand All @@ -705,7 +705,7 @@ private async Task<ITestFramework> BuildTestFrameworkAsync(TestFrameworkBuilderD
testSessionLifetimeHandlers.Add(handler);
}

await TestHostBuilder.RegisterAsServiceOrConsumerOrBothAsync(consumerService, serviceProvider, dataConsumersBuilder);
await RegisterAsServiceOrConsumerOrBothAsync(consumerService, serviceProvider, dataConsumersBuilder);
}

// Register the test session lifetime handlers container
Expand All @@ -721,7 +721,7 @@ private async Task<ITestFramework> BuildTestFrameworkAsync(TestFrameworkBuilderD

// Allow the ITestApplicationProcessExitCode to subscribe as IDataConsumer
ITestApplicationProcessExitCode testApplicationResult = serviceProvider.GetRequiredService<ITestApplicationProcessExitCode>();
await TestHostBuilder.RegisterAsServiceOrConsumerOrBothAsync(testApplicationResult, serviceProvider, dataConsumersBuilder);
await RegisterAsServiceOrConsumerOrBothAsync(testApplicationResult, serviceProvider, dataConsumersBuilder);

// We register the data consumer handler if we're connected to the dotnet test pipe
if (pushOnlyProtocolDataConsumer is not null)
Expand Down Expand Up @@ -817,7 +817,7 @@ private static async Task RegisterAsServiceOrConsumerOrBothAsync(object service,
return;
}

await TestHostBuilder.AddServiceIfNotSkippedAsync(service, serviceProvider);
await AddServiceIfNotSkippedAsync(service, serviceProvider);
}

private async Task DisplayBannerIfEnabledAsync(ApplicationLoggingState loggingState, ProxyOutputDevice outputDevice,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class MSBuildTests_Test : AcceptanceTestBase<NopAssetFixture>
private const string AssetName = "MSBuildTests";

public static string? FormatBuildMatrixEntry(MethodInfo method, object?[]? data)
=> $"{data![0]},{(string.Equals(TargetFrameworks.All.ToMSBuildTargetFrameworks(), data[1]) ? "multitfm" : data[1])},{data[2]},{((bool)data[3]! ? "Succeeded" : "Failed")}";
=> $"{data![0]},{(Equals(TargetFrameworks.All.ToMSBuildTargetFrameworks(), data[1]) ? "multitfm" : data[1])},{data[2]},{((bool)data[3]! ? "Succeeded" : "Failed")}";

internal static IEnumerable<(string BuildCommand, string TargetFramework, BuildConfiguration BuildConfiguration, bool TestSucceeded)> GetBuildMatrix()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void SetConfigurationFileShouldSetOMRedirectionIfConfigFileIsPresent()
""";

byte[] observedConfigBytes = setup.GetConfigurationBytes();
string observedXml = System.Text.Encoding.UTF8.GetString(observedConfigBytes);
string observedXml = Encoding.UTF8.GetString(observedConfigBytes);

Verify(SanitizeString(observedXml).Contains(SanitizeString(expectedRedir)), "Config must have OM redirection");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void GetSettingsShouldSetParallelScopeToClassLevelByDefault()
MSTest.TestAdapter.ObjectModel.TestAssemblySettings settings = TestAssemblySettingsProvider.GetSettings("Foo");

// Assert.
Verify(settings.Scope == UTF.ExecutionScope.ClassLevel);
Verify(settings.Scope == ExecutionScope.ClassLevel);
}

public void GetSettingsShouldSetParallelScope()
Expand All @@ -112,13 +112,13 @@ public void GetSettingsShouldSetParallelScope()
_testablePlatformServiceProvider
.MockReflectionOperations
.Setup(ro => ro.GetCustomAttributes(It.IsAny<Assembly>(), typeof(UTF.ParallelizeAttribute)))
.Returns([new UTF.ParallelizeAttribute { Scope = UTF.ExecutionScope.MethodLevel }]);
.Returns([new UTF.ParallelizeAttribute { Scope = ExecutionScope.MethodLevel }]);

// Act.
MSTest.TestAdapter.ObjectModel.TestAssemblySettings settings = TestAssemblySettingsProvider.GetSettings("Foo");

// Assert.
Verify(settings.Scope == UTF.ExecutionScope.MethodLevel);
Verify(settings.Scope == ExecutionScope.MethodLevel);
}

public void GetSettingsShouldSetCanParallelizeAssemblyToTrueByDefault()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

using AdapterTestOutcome = Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel.UnitTestOutcome;
using UTF = Microsoft.VisualStudio.TestTools.UnitTesting;
using UTFExtension = Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public TestablePlatformServiceProvider()
MockTraceListener = new Mock<ITraceListener>();
MockTraceListenerManager = new Mock<ITraceListenerManager>();
MockThreadOperations = new Mock<IThreadOperations>();
TestTools.UnitTesting.DynamicDataProvider.Instance = SourceGeneratorToggle.UseSourceGenerator
UTF.DynamicDataProvider.Instance = SourceGeneratorToggle.UseSourceGenerator
? new SourceGeneratedDynamicDataOperations()
: new DynamicDataOperations();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public partial class AssertTests
#region That tests
public void ThatShouldReturnAnInstanceOfAssert() => Verify(Assert.That is not null);

public void ThatShouldCacheAssertInstance() => Verify(object.ReferenceEquals(Assert.That, Assert.That));
public void ThatShouldCacheAssertInstance() => Verify(ReferenceEquals(Assert.That, Assert.That));
#endregion

#region ReplaceNullChars tests
Expand Down
4 changes: 2 additions & 2 deletions test/Utilities/Automation.CLI/CLITestBase.common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected static string GetTestPlatformVersion()

protected static string GetArtifactsBinFolderPath()
{
string assemblyLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;
string assemblyLocation = Assembly.GetExecutingAssembly().Location;

string artifactsBinFolder = Path.GetFullPath(Path.Combine(assemblyLocation, @"..\..\..\.."));
Directory.Exists(artifactsBinFolder).Should().BeTrue();
Expand All @@ -54,7 +54,7 @@ protected static string GetArtifactsBinFolderPath()

protected static string GetArtifactsTestResultsFolderPath()
{
string assemblyLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;
string assemblyLocation = Assembly.GetExecutingAssembly().Location;

string artifactsFolder = Path.GetFullPath(Path.Combine(assemblyLocation, @"..\..\..\..\.."));
Directory.Exists(artifactsFolder).Should().BeTrue();
Expand Down

0 comments on commit d8b5212

Please sign in to comment.