Skip to content

Commit

Permalink
Updated decorator tests to handle issue #963 caveats. Skipped for now.
Browse files Browse the repository at this point in the history
  • Loading branch information
tillig committed Mar 8, 2019
1 parent 296bbf5 commit 8ea04f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
11 changes: 7 additions & 4 deletions test/Autofac.Test/Features/Decorators/DecoratorTests.cs
Expand Up @@ -13,12 +13,12 @@ public interface IService
{
}

public interface IDecoratedService : IService
public interface IDecoratedService
{
IDecoratedService Decorated { get; }
}

public class ImplementorA : IDecoratedService
public class ImplementorA : IDecoratedService, IService
{
public IDecoratedService Decorated => this;
}
Expand Down Expand Up @@ -189,9 +189,12 @@ public void DecoratedRegistrationCanIncludeImplementationType()
Assert.IsType<ImplementorA>(container.Resolve<ImplementorA>());
}

[Fact]
[Fact(Skip = "Issue #963")]
public void DecoratedRegistrationCanIncludeOtherServices()
{
// Issue #963 - Make sure IDecoratedService does _not_ derive from
// IService. The idea is that a component may provide multiple
// services but only one of them may be decorated.
var builder = new ContainerBuilder();
builder.RegisterType<ImplementorA>().As<IDecoratedService>().As<IService>();
builder.RegisterDecorator<DecoratorA, IDecoratedService>();
Expand All @@ -204,7 +207,7 @@ public void DecoratedRegistrationCanIncludeOtherServices()
Assert.NotNull(decoratedServiceRegistration);
Assert.Same(serviceRegistration, decoratedServiceRegistration);

Assert.IsType<DecoratorA>(container.Resolve<IService>());
Assert.IsType<ImplementorA>(container.Resolve<IService>());
Assert.IsType<DecoratorA>(container.Resolve<IDecoratedService>());
}

Expand Down
Expand Up @@ -14,12 +14,12 @@ public interface IService<T>
{
}

public interface IDecoratedService<T> : IService<T>
public interface IDecoratedService<T>
{
IDecoratedService<T> Decorated { get; }
}

public class ImplementorA<T> : IDecoratedService<T>
public class ImplementorA<T> : IDecoratedService<T>, IService<T>
{
public IDecoratedService<T> Decorated => this;
}
Expand Down Expand Up @@ -186,9 +186,12 @@ public void DecoratedRegistrationCanIncludeImplementationType()
Assert.IsType<ImplementorA<int>>(container.Resolve<ImplementorA<int>>());
}

[Fact]
[Fact(Skip = "Issue #963")]
public void DecoratedRegistrationCanIncludeOtherServices()
{
// Issue #963 - Make sure IDecoratedService<T> does _not_ derive from
// IService<T>. The idea is that a component may provide multiple
// services but only one of them may be decorated.
var builder = new ContainerBuilder();
builder.RegisterGeneric(typeof(ImplementorA<>)).As(typeof(IDecoratedService<>)).As(typeof(IService<>));
builder.RegisterGenericDecorator(typeof(DecoratorA<>), typeof(IDecoratedService<>));
Expand All @@ -201,7 +204,7 @@ public void DecoratedRegistrationCanIncludeOtherServices()
Assert.NotNull(decoratedServiceRegistration);
Assert.Same(serviceRegistration, decoratedServiceRegistration);

Assert.IsType<DecoratorA<int>>(container.Resolve<IService<int>>());
Assert.IsType<ImplementorA<int>>(container.Resolve<IService<int>>());
Assert.IsType<DecoratorA<int>>(container.Resolve<IDecoratedService<int>>());
}

Expand Down

0 comments on commit 8ea04f0

Please sign in to comment.