Add test for re-wiring existing members

This commit is contained in:
Mike Bierlee 2014-06-01 23:07:58 +02:00
parent 6b82c35b2e
commit b0df553ca9

View file

@ -143,4 +143,19 @@ version(unittest) {
container.removeRegistration!TestClass;
assertThrown!ResolveException(container.resolve!TestClass);
}
// Test autowiring does not autowire member where instance is non-null
unittest {
auto container = new Container();
auto existingA = new AutowiredClass();
auto existingB = new ComponentClass();
existingB.autowiredClass = existingA;
container.register!AutowiredClass;
container.register!(ComponentClass).existingInstance(existingB);
auto resolvedA = container.resolve!AutowiredClass;
auto resolvedB = container.resolve!ComponentClass;
assert(resolvedB.autowiredClass is existingA && resolvedA !is existingA, "Autowiring shouldn't rewire member when it is already wired to an instance");
}
}