From fadd8bd5de9ad8e03699174a9fa375d818607118 Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Fri, 21 Jan 2022 19:48:46 -0600 Subject: [PATCH] test: Clean up composition root tests --- src/Trash.Tests/CompositionRootTest.cs | 51 ++++++++++++++------------ 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/src/Trash.Tests/CompositionRootTest.cs b/src/Trash.Tests/CompositionRootTest.cs index d1e8c17d..86de586e 100644 --- a/src/Trash.Tests/CompositionRootTest.cs +++ b/src/Trash.Tests/CompositionRootTest.cs @@ -12,24 +12,36 @@ namespace Trash.Tests; public record ServiceFactoryWrapper(Type Service, Action Instantiate); -[TestFixture] -[Parallelizable(ParallelScope.All)] -public class CompositionRootTest +public static class FactoryForService { - private static class FactoryForService + public static ServiceFactoryWrapper WithArgs(TP1 arg1 = default!) { - public static ServiceFactoryWrapper WithArgs(TP1 arg1 = default!) - { - return new ServiceFactoryWrapper(typeof(TService), - c => c.Resolve>().Invoke(arg1)); - } + return new ServiceFactoryWrapper(typeof(TService), + c => c.Resolve>().Invoke(arg1)); } +} +[TestFixture] +[Parallelizable(ParallelScope.All)] +public class CompositionRootTest +{ private static readonly List FactoryTests = new() { FactoryForService.WithArgs("path") }; + [TestCaseSource(typeof(CompositionRootTest), nameof(FactoryTests))] + public void Service_requiring_factory_should_be_instantiable(ServiceFactoryWrapper service) + { + var act = () => + { + using var container = CompositionRoot.Setup(); + service.Instantiate(container); + }; + + act.Should().NotThrow(); + } + private sealed class ConcreteTypeEnumerator : IEnumerable { private readonly IContainer _container; @@ -44,28 +56,19 @@ public class CompositionRootTest return _container.ComponentRegistry.Registrations .SelectMany(x => x.Services) .OfType() - .Where(x => FactoryTests.All(y => y.Service != x.ServiceType)) + .Select(x => x.ServiceType) + .Distinct() + .Except(FactoryTests.Select(x => x.Service)) + .Where(x => x.FullName == null || !x.FullName.StartsWith("Autofac.")) .GetEnumerator(); } } - [TestCaseSource(typeof(CompositionRootTest), nameof(FactoryTests))] - public void Service_requiring_factory_should_be_instantiable(ServiceFactoryWrapper service) - { - var act = () => - { - using var container = CompositionRoot.Setup(); - service.Instantiate(container); - }; - - act.Should().NotThrow(); - } - [TestCaseSource(typeof(ConcreteTypeEnumerator))] - public void Service_should_be_instantiable(Service service) + public void Service_should_be_instantiable(Type service) { using var container = CompositionRoot.Setup(); - container.Invoking(c => c.ResolveService(service)) + container.Invoking(c => c.Resolve(service)) .Should().NotThrow() .And.NotBeNull(); }