From b0df553ca9f6b514b6cd145119917dd3c6c72a6a Mon Sep 17 00:00:00 2001 From: Mike Bierlee Date: Sun, 1 Jun 2014 23:07:58 +0200 Subject: [PATCH] Add test for re-wiring existing members --- test/poodinis/containertest.d | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/poodinis/containertest.d b/test/poodinis/containertest.d index 9b0f2b5..ed84fdd 100644 --- a/test/poodinis/containertest.d +++ b/test/poodinis/containertest.d @@ -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"); + } } \ No newline at end of file