Add test for value injection within injectors and their dependencies

This commit is contained in:
Mike Bierlee 2016-12-11 17:25:01 +01:00
parent 7c718ec159
commit 2f5ffd5da5

View file

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