From 4957b67b498d28272ef63ebb237130dab17684ca Mon Sep 17 00:00:00 2001 From: Mike Bierlee Date: Tue, 27 May 2014 02:02:07 +0200 Subject: [PATCH] Test that you can autowire members declared as an interface type --- test/poodinis/autowiretest.d | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/poodinis/autowiretest.d b/test/poodinis/autowiretest.d index 59b444a..db78ad4 100644 --- a/test/poodinis/autowiretest.d +++ b/test/poodinis/autowiretest.d @@ -12,6 +12,20 @@ version(unittest) { } } + interface InterfaceA { + } + + class ComponentC : InterfaceA { + } + + class ComponentD { + public @Autowire InterfaceA componentC; + + public bool componentIsNull() { + return componentC is null; + } + } + // Test autowiring concrete type to existing instance unittest { auto container = new Container(); @@ -20,4 +34,13 @@ version(unittest) { container.autowire!(ComponentB)(componentB); assert(!componentB.componentIsNull(), "Autowirable dependency failed to autowire"); } + + // Test autowiring interface type to existing instance + unittest { + auto container = new Container(); + container.register!(InterfaceA, ComponentC); + ComponentD componentD = new ComponentD(); + container.autowire!(ComponentD)(componentD); + assert(!componentD.componentIsNull(), "Autowirable dependency failed to autowire"); + } } \ No newline at end of file