From 4f3be185c7923e3cedf4724b1b3ad40c1407820e Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Fri, 25 Sep 2020 07:30:52 -0700 Subject: [PATCH] Issue #880: Removed skipped test, added test for new decorator syntax. --- .../Features/DecoratorTests.cs | 17 +++++++++++++ ...eightAdapterRegistrationExtensionsTests.cs | 24 ------------------- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/test/Autofac.Specification.Test/Features/DecoratorTests.cs b/test/Autofac.Specification.Test/Features/DecoratorTests.cs index 05228087b..c909e6a0e 100644 --- a/test/Autofac.Specification.Test/Features/DecoratorTests.cs +++ b/test/Autofac.Specification.Test/Features/DecoratorTests.cs @@ -984,6 +984,23 @@ public void DecoratorsApplyToKeyedServices() Assert.IsType(instance.Decorated); } + [Fact] + public void DecoratorsApplyToNamedAndDefaultServices() + { + // Issue #529, #880: Old decorator syntax failed if a component + // being decorated was registered with both As() and Named(). + var builder = new ContainerBuilder(); + + builder.RegisterType().As().Named("service"); + builder.RegisterDecorator(); + var container = builder.Build(); + + var instance = container.Resolve(); + + Assert.IsType(instance); + Assert.IsType(instance.Decorated); + } + [Theory] [InlineData(typeof(IDecoratedService), typeof(ISomeOtherService))] [InlineData(typeof(ISomeOtherService), typeof(IDecoratedService))] diff --git a/test/Autofac.Test/Features/LightweightAdapters/LightweightAdapterRegistrationExtensionsTests.cs b/test/Autofac.Test/Features/LightweightAdapters/LightweightAdapterRegistrationExtensionsTests.cs index 29256f029..f2e597ae0 100644 --- a/test/Autofac.Test/Features/LightweightAdapters/LightweightAdapterRegistrationExtensionsTests.cs +++ b/test/Autofac.Test/Features/LightweightAdapters/LightweightAdapterRegistrationExtensionsTests.cs @@ -88,30 +88,6 @@ public void AdaptedMetadataIsPassed() } } - public class DecoratingServiceThatHasDefaultImplementation - { - private readonly IContainer _container; - - public DecoratingServiceThatHasDefaultImplementation() - { - const string from = "from"; - var builder = new ContainerBuilder(); - - builder.RegisterType().As().Named(from); - builder.RegisterDecorator(s => new Decorator(s), from); - - _container = builder.Build(); - } - - [Fact(Skip = "Issue #529 => #880")] - public void InstanceWithDefaultImplementationIsDecorated() - { - var decorator = _container.Resolve(); - Assert.IsType(decorator); - Assert.IsType(((Decorator)decorator).Decorated); - } - } - public interface IService { }