mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
Add test for value injection within injectors and their dependencies
This commit is contained in:
parent
7c718ec159
commit
2f5ffd5da5
|
@ -150,7 +150,6 @@ version(unittest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
container.register!(ValueInjector!int, IntInjector);
|
container.register!(ValueInjector!int, IntInjector);
|
||||||
|
|
||||||
auto injector = cast(IntInjector) container.resolve!(ValueInjector!int);
|
auto injector = cast(IntInjector) container.resolve!(ValueInjector!int);
|
||||||
|
|
||||||
assert(injector.dependency is dependency);
|
assert(injector.dependency is dependency);
|
||||||
|
@ -177,10 +176,58 @@ version(unittest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
container.register!(ValueInjector!int, IntInjector);
|
container.register!(ValueInjector!int, IntInjector);
|
||||||
|
|
||||||
auto injector = cast(IntInjector) container.resolve!(ValueInjector!int);
|
auto injector = cast(IntInjector) container.resolve!(ValueInjector!int);
|
||||||
|
|
||||||
assert(injector.dependency is injector);
|
assert(injector.dependency is injector);
|
||||||
assert(injector.get("whatever") == 3);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue