diff --git a/test/poodinis/containertest.d b/test/poodinis/containertest.d index 2e351d1..f9147b9 100644 --- a/test/poodinis/containertest.d +++ b/test/poodinis/containertest.d @@ -224,21 +224,6 @@ version(unittest) { this(Ola ola) {} } - struct Thing { - int x; - } - - class MyConfig { - @Value("conf.stuffs") - int stuffs; - - @Value("conf.name") - string name; - - @Value("conf.thing") - Thing thing; - } - // Test register concrete type unittest { auto container = new shared DependencyContainer(); @@ -762,40 +747,4 @@ version(unittest) { container.register!Hello; container.resolve!Hello; } - - // Test injection of values - unittest { - auto container = new shared DependencyContainer(); - container.register!MyConfig; - - class IntInjector : ValueInjector!int { - public override int get(string key) { - assert(key == "conf.stuffs"); - return 364; - } - } - - class StringInjector : ValueInjector!string { - public override string get(string key) { - assert(key == "conf.name"); - return "Le Chef"; - } - } - - class ThingInjector : ValueInjector!Thing { - public override Thing get(string key) { - assert(key == "conf.thing"); - return Thing(8899); - } - } - - container.register!(ValueInjector!int, IntInjector); - container.register!(ValueInjector!string, StringInjector); - container.register!(ValueInjector!Thing, ThingInjector); - - auto instance = container.resolve!MyConfig; - assert(instance.stuffs == 364); - assert(instance.name == "Le Chef"); - assert(instance.thing.x == 8899); - } } diff --git a/test/poodinis/valueinjectiontest.d b/test/poodinis/valueinjectiontest.d new file mode 100644 index 0000000..19b96bb --- /dev/null +++ b/test/poodinis/valueinjectiontest.d @@ -0,0 +1,61 @@ +/** + * Poodinis Dependency Injection Framework + * Copyright 2014-2016 Mike Bierlee + * This software is licensed under the terms of the MIT license. + * The full terms of the license can be found in the LICENSE file. + */ + +import poodinis; + +version(unittest) { + struct Thing { + int x; + } + + class MyConfig { + @Value("conf.stuffs") + int stuffs; + + @Value("conf.name") + string name; + + @Value("conf.thing") + Thing thing; + } + + // Test injection of values + unittest { + auto container = new shared DependencyContainer(); + container.register!MyConfig; + + class IntInjector : ValueInjector!int { + public override int get(string key) { + assert(key == "conf.stuffs"); + return 364; + } + } + + class StringInjector : ValueInjector!string { + public override string get(string key) { + assert(key == "conf.name"); + return "Le Chef"; + } + } + + class ThingInjector : ValueInjector!Thing { + public override Thing get(string key) { + assert(key == "conf.thing"); + return Thing(8899); + } + } + + container.register!(ValueInjector!int, IntInjector); + container.register!(ValueInjector!string, StringInjector); + container.register!(ValueInjector!Thing, ThingInjector); + + auto instance = container.resolve!MyConfig; + assert(instance.stuffs == 364); + assert(instance.name == "Le Chef"); + assert(instance.thing.x == 8899); + } +}