Created
November 11, 2011 11:51
-
-
Save GraemeF/1357829 to your computer and use it in GitHub Desktop.
Test to show that the DefaultTypedFactoryComponentSelector doesn't match parameters on dependencies of the returned type.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace TypedFactoryTests | |
{ | |
#region Using Directives | |
using Castle.Facilities.TypedFactory; | |
using Castle.MicroKernel.Registration; | |
using Castle.Windsor; | |
using Should.Fluent; | |
using Xunit; | |
#endregion | |
public interface IFooFactory | |
{ | |
IFoo CreateFoo(IBaz baz); | |
} | |
public interface IBaz | |
{ | |
} | |
public class MyBaz : IBaz | |
{ | |
} | |
public interface IFoo | |
{ | |
IBar Bar { get; set; } | |
} | |
public class MyFoo : IFoo | |
{ | |
public MyFoo(IBar bar) | |
{ | |
Bar = bar; | |
} | |
public IBar Bar { get; set; } | |
} | |
public interface IBar | |
{ | |
IBaz Baz { get; set; } | |
} | |
public class MyBar : IBar | |
{ | |
public MyBar(IBaz baz) | |
{ | |
Baz = baz; | |
} | |
public IBaz Baz { get; set; } | |
} | |
public class Test | |
{ | |
private readonly IWindsorContainer container = new WindsorContainer(); | |
public Test() | |
{ | |
container.AddFacility<TypedFactoryFacility>(); | |
container.Register(Component.For<IFoo>().ImplementedBy<MyFoo>()); | |
container.Register(Component.For<IBar>().ImplementedBy<MyBar>()); | |
container.Register(Component.For<IBaz>().ImplementedBy<MyBaz>()); | |
container.Register(Component.For<IFooFactory>().AsFactory()); | |
} | |
[Fact] | |
public void FactoryResolvesDependenciesWithParameters() | |
{ | |
var theBaz = new MyBaz(); | |
IFoo factoryFoo = container.Resolve<IFooFactory>().CreateFoo(theBaz); | |
factoryFoo.Bar.Baz.Should().Be.SameAs(theBaz); | |
} | |
[Fact] | |
public void ResolvesDependenciesWithoutParameters() | |
{ | |
var theBaz = new MyBaz(); | |
var foo = container.Resolve<IFoo>(); | |
foo.Bar.Baz.Should().Not.Be.SameAs(theBaz); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment