Skip to content

Commit

Permalink
Issue #880: Removed skipped test, added test for new decorator syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
tillig committed Sep 25, 2020
1 parent 46e8503 commit 4f3be18
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
17 changes: 17 additions & 0 deletions test/Autofac.Specification.Test/Features/DecoratorTests.cs
Expand Up @@ -984,6 +984,23 @@ public void DecoratorsApplyToKeyedServices()
Assert.IsType<ImplementorA>(instance.Decorated);
}

[Fact]
public void DecoratorsApplyToNamedAndDefaultServices()
{
// Issue #529, #880: Old decorator syntax failed if a component
// being decorated was registered with both As<T>() and Named<T>().
var builder = new ContainerBuilder();

builder.RegisterType<ImplementorA>().As<IDecoratedService>().Named<IDecoratedService>("service");
builder.RegisterDecorator<DecoratorA, IDecoratedService>();
var container = builder.Build();

var instance = container.Resolve<IDecoratedService>();

Assert.IsType<DecoratorA>(instance);
Assert.IsType<ImplementorA>(instance.Decorated);
}

[Theory]
[InlineData(typeof(IDecoratedService), typeof(ISomeOtherService))]
[InlineData(typeof(ISomeOtherService), typeof(IDecoratedService))]
Expand Down
Expand Up @@ -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<Implementer1>().As<IService>().Named<IService>(from);
builder.RegisterDecorator<IService>(s => new Decorator(s), from);

_container = builder.Build();
}

[Fact(Skip = "Issue #529 => #880")]
public void InstanceWithDefaultImplementationIsDecorated()
{
var decorator = _container.Resolve<IService>();
Assert.IsType<Decorator>(decorator);
Assert.IsType<Implementer1>(((Decorator)decorator).Decorated);
}
}

public interface IService
{
}
Expand Down

0 comments on commit 4f3be18

Please sign in to comment.