Add test for resolve by interface workaround

This commit is contained in:
Mike Bierlee 2014-06-22 16:33:15 +02:00
parent 17c833a114
commit 47d7f72fae

View file

@ -42,6 +42,16 @@ version(unittest) {
public ComponentC componentC; public ComponentC componentC;
} }
class ComponentF {
@Autowire
public ComponentA componentA;
public this() {
auto container = Container.getInstance();
container.autowire!ComponentF(this);
}
}
// Test autowiring concrete type to existing instance // Test autowiring concrete type to existing instance
unittest { unittest {
auto container = new Container(); auto container = new Container();
@ -86,4 +96,17 @@ version(unittest) {
container.autowire!ComponentE(componentE); container.autowire!ComponentE(componentE);
assert(componentE.componentC is null, "Autowiring should not occur for members with attributes other than @Autowire"); assert(componentE.componentC is null, "Autowiring should not occur for members with attributes other than @Autowire");
} }
// Test autowire in constructor
unittest {
auto container = Container.getInstance();
container.register!ComponentA;
auto componentF = new ComponentF();
auto autowiredComponentA = componentF.componentA;
container.register!(ComponentF).existingInstance(componentF);
assert(componentF.componentA !is null, "Constructor did not autowire component F");
auto resolvedComponentF = container.resolve!ComponentF;
assert(resolvedComponentF.componentA is autowiredComponentA, "Resolving instance of ComponentF rewired members");
}
} }