Move value injection test to its own test file

This commit is contained in:
Mike Bierlee 2016-12-10 22:39:37 +01:00
parent e7e114d09f
commit 4954979574
2 changed files with 61 additions and 51 deletions

View file

@ -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);
}
}

View file

@ -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);
}
}