From 2f5ffd5da5a3e2d38bb7b53836775ece9c9a21a1 Mon Sep 17 00:00:00 2001 From: Mike Bierlee Date: Sun, 11 Dec 2016 17:25:01 +0100 Subject: [PATCH] Add test for value injection within injectors and their dependencies --- test/poodinis/valueinjectiontest.d | 51 ++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/test/poodinis/valueinjectiontest.d b/test/poodinis/valueinjectiontest.d index de2496b..df6e8da 100644 --- a/test/poodinis/valueinjectiontest.d +++ b/test/poodinis/valueinjectiontest.d @@ -150,7 +150,6 @@ version(unittest) { } container.register!(ValueInjector!int, IntInjector); - auto injector = cast(IntInjector) container.resolve!(ValueInjector!int); assert(injector.dependency is dependency); @@ -177,10 +176,58 @@ version(unittest) { } container.register!(ValueInjector!int, IntInjector); - auto injector = cast(IntInjector) container.resolve!(ValueInjector!int); assert(injector.dependency is injector); assert(injector.get("whatever") == 3); } + + // Test value injection within value injectors + unittest { + auto container = new shared DependencyContainer(); + + class IntInjector : ValueInjector!int { + + @Value("five") + public int count = 0; + + public override int get(string key) { + if (key == "five") { + return 5; + } + + return count; + } + } + + container.register!(ValueInjector!int, IntInjector); + auto injector = cast(IntInjector) container.resolve!(ValueInjector!int); + + assert(injector.count == 5); + } + + // Test value injection within dependencies of value injectors + unittest { + auto container = new shared DependencyContainer(); + container.register!ConfigWithDefaults; + + class IntInjector : ValueInjector!int { + + @Autowire + public ConfigWithDefaults config; + + public override int get(string key) { + if (key == "conf.missing") { + return 8899; + } + + return 0; + } + } + + container.register!(ValueInjector!int, IntInjector); + auto injector = cast(IntInjector) container.resolve!(ValueInjector!int); + + assert(injector.config.noms == 8899); + } }