Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,14 @@ public static async Task<ValidationResult> ValidateAsync(
// (testconfig.json is case-insensitive everywhere else). Use OrdinalIgnoreCase so a JSON
// entry such as "Timeout": "30s" resolves to the same provider/option metadata as
// "--timeout 30s" on the command line.
var providerAndOptionByOptionName = extensionOptionsByProvider.Concat(systemOptionsByProvider)
.SelectMany(tuple => tuple.Value.Select(option => (provider: tuple.Key, option)))
.ToDictionary(tuple => tuple.option.Name, StringComparer.OrdinalIgnoreCase);
var providerAndOptionByOptionName = new Dictionary<string, (ICommandLineOptionsProvider Provider, CommandLineOption Option)>(StringComparer.OrdinalIgnoreCase);
foreach (KeyValuePair<ICommandLineOptionsProvider, IReadOnlyCollection<CommandLineOption>> provider in extensionOptionsByProvider.Concat(systemOptionsByProvider))
{
foreach (CommandLineOption option in provider.Value)
{
providerAndOptionByOptionName.Add(option.Name, (provider.Key, option));
}
}

if (ValidateOptionsArgumentArity(commandLineParseResult, jsonCommandLineOptions, jsonCommandLineOptionDefaults, providerAndOptionByOptionName) is { IsValid: false } result5)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal sealed class ServiceProvider : IServiceProvider, ICloneable
public bool AllowTestAdapterFrameworkRegistration { get; set; }

#pragma warning disable CS0618 // Type or member is obsolete
private static Type[] InternalOnlyExtensions =>
private static readonly Type[] InternalOnlyExtensions =
[
// TestHost
typeof(ITestHostApplicationLifetime),
Expand Down Expand Up @@ -126,7 +126,22 @@ public IEnumerable<object> GetServicesInternal(
}

public object? GetServiceInternal(Type serviceType, bool skipInternalOnlyExtensions = false)
=> GetServicesInternal(serviceType, stopAtFirst: true, skipInternalOnlyExtensions).FirstOrDefault();
{
if (skipInternalOnlyExtensions && InternalOnlyExtensions.Contains(serviceType))
{
return null;
}

foreach (object serviceInstance in _services)
{
if (serviceType.IsInstanceOfType(serviceInstance))
{
return serviceInstance;
}
}

return null;
}

private void RegisterCoverageProducer(object service)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ public static TService GetRequiredPlatformService<TService>(this IServiceProvide
_ = provider ?? throw new ArgumentNullException(nameof(provider));

object? service = provider.GetService(typeof(TService));
ApplicationStateGuard.Ensure(service is not null, string.Format(CultureInfo.InvariantCulture, PlatformResources.ServiceProviderCannotFindServiceErrorMessage, typeof(TService)));

return (TService)service;
return (TService)(service ?? throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, PlatformResources.ServiceProviderCannotFindServiceErrorMessage, typeof(TService))));
}

/// <summary>
Expand Down Expand Up @@ -189,9 +187,7 @@ internal static TService GetRequiredServiceInternal<TService>(this IServiceProvi
_ = provider ?? throw new ArgumentNullException(nameof(provider));

object? service = ((ServiceProvider)provider).GetServiceInternal(typeof(TService));
ApplicationStateGuard.Ensure(service is not null, string.Format(CultureInfo.InvariantCulture, PlatformResources.ServiceProviderCannotFindServiceErrorMessage, typeof(TService)));

return (TService)service;
return (TService)(service ?? throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, PlatformResources.ServiceProviderCannotFindServiceErrorMessage, typeof(TService))));
}

internal static TService? GetServiceInternal<TService>(this IServiceProvider provider)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@
requireProcessRestart = true;
}

<<<<<<< HEAD

Check failure on line 165 in src/Platform/Microsoft.Testing.Platform/TestHostControllers/TestHostControllersManager.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Linux Release)

src/Platform/Microsoft.Testing.Platform/TestHostControllers/TestHostControllersManager.cs#L165

src/Platform/Microsoft.Testing.Platform/TestHostControllers/TestHostControllersManager.cs(165,1): error CS8300: Merge conflict marker encountered

Check failure on line 165 in src/Platform/Microsoft.Testing.Platform/TestHostControllers/TestHostControllersManager.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Linux Release)

src/Platform/Microsoft.Testing.Platform/TestHostControllers/TestHostControllersManager.cs#L165

src/Platform/Microsoft.Testing.Platform/TestHostControllers/TestHostControllersManager.cs(165,1): error CS8300: Merge conflict marker encountered
=======

Check failure on line 166 in src/Platform/Microsoft.Testing.Platform/TestHostControllers/TestHostControllersManager.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Linux Release)

src/Platform/Microsoft.Testing.Platform/TestHostControllers/TestHostControllersManager.cs#L166

src/Platform/Microsoft.Testing.Platform/TestHostControllers/TestHostControllersManager.cs(166,1): error CS8300: Merge conflict marker encountered

Check failure on line 166 in src/Platform/Microsoft.Testing.Platform/TestHostControllers/TestHostControllersManager.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Linux Release)

src/Platform/Microsoft.Testing.Platform/TestHostControllers/TestHostControllersManager.cs#L166

src/Platform/Microsoft.Testing.Platform/TestHostControllers/TestHostControllersManager.cs(166,1): error CS8300: Merge conflict marker encountered
if (!requireProcessRestart)
{
return new TestHostControllerConfiguration([], [], [], testHostLauncher, requireProcessRestart: false);
}

// Observers of an existing controller must not introduce an extra process themselves.
List<(IExtension Extension, int RegistrationOrder)> runCompletionHandlers = [];
await ExtensionBuilderHelper.BuildAndRegisterExtensionsAsync(_runCompletionHandlerFactories, serviceProvider, runCompletionHandlers, _factoryOrdering, registerInServiceProvider: true).ConfigureAwait(false);

>>>>>>> Reduce redundant platform startup work and service allocations

Check failure on line 176 in src/Platform/Microsoft.Testing.Platform/TestHostControllers/TestHostControllersManager.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Linux Release)

src/Platform/Microsoft.Testing.Platform/TestHostControllers/TestHostControllersManager.cs#L176

src/Platform/Microsoft.Testing.Platform/TestHostControllers/TestHostControllersManager.cs(176,1): error CS8300: Merge conflict marker encountered
return new TestHostControllerConfiguration(
[.. environmentVariableProviders.OrderBy(x => x.RegistrationOrder).Select(x => (ITestHostEnvironmentVariableProvider)x.Extension)],
[.. lifetimeHandlers.OrderBy(x => x.RegistrationOrder).Select(x => (ITestHostProcessLifetimeHandler)x.Extension)],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.Testing.Platform.Extensions.TestHost;
using Microsoft.Testing.Platform.Extensions.TestHostControllers;
using Microsoft.Testing.Platform.Logging;
using Microsoft.Testing.Platform.Resources;
using Microsoft.Testing.Platform.Services;

using Moq;
Expand Down Expand Up @@ -34,7 +35,34 @@ public void GetRequiredPlatformService_MissingServiceThrows()
{
IServiceProvider provider = new SingleServiceProvider(null);

Assert.ThrowsExactly<InvalidOperationException>(() => provider.GetRequiredPlatformService<object>());
InvalidOperationException exception = Assert.ThrowsExactly<InvalidOperationException>(() => provider.GetRequiredPlatformService<object>());

Assert.AreEqual(
string.Format(CultureInfo.InvariantCulture, PlatformResources.GetResourceString("ServiceProviderCannotFindServiceErrorMessage"), typeof(object)),
exception.Message);
}

[TestMethod]
public void GetRequiredServiceInternal_MissingServicePreservesDiagnostic()
{
InvalidOperationException exception = Assert.ThrowsExactly<InvalidOperationException>(
() => _serviceProvider.GetRequiredServiceInternal<object>());

Assert.AreEqual(
string.Format(CultureInfo.InvariantCulture, PlatformResources.GetResourceString("ServiceProviderCannotFindServiceErrorMessage"), typeof(object)),
exception.Message);
}

[TestMethod]
public void GetRequiredServiceInternal_ReturnsFirstMatchingService()
{
TestSessionLifetimeHandler first = new();
TestSessionLifetimeHandler second = new();
_serviceProvider.AddService(first);
_serviceProvider.AddService(second);

Assert.AreSame(first, _serviceProvider.GetRequiredServiceInternal<ITestSessionLifetimeHandler>());
Assert.IsNull(_serviceProvider.GetPlatformService<ITestSessionLifetimeHandler>());
}

[TestMethod]
Expand Down
Loading