mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
Simplify templated calls in test
This commit is contained in:
parent
85c31574ac
commit
13921a128e
|
@ -78,7 +78,7 @@ version(unittest) {
|
|||
shared(DependencyContainer) container = new DependencyContainer();
|
||||
container.register!ComponentA;
|
||||
auto componentB = new ComponentB();
|
||||
container.autowire!(ComponentB)(componentB);
|
||||
container.autowire(componentB);
|
||||
assert(componentB !is null, "Autowirable dependency failed to autowire");
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ version(unittest) {
|
|||
shared(DependencyContainer) container = new DependencyContainer();
|
||||
container.register!(InterfaceA, ComponentC);
|
||||
auto componentD = new ComponentD();
|
||||
container.autowire!(ComponentD)(componentD);
|
||||
container.autowire(componentD);
|
||||
assert(componentD.componentC !is null, "Autowirable dependency failed to autowire");
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ version(unittest) {
|
|||
shared(DependencyContainer) container = new DependencyContainer();
|
||||
container.register!(InterfaceA, ComponentC);
|
||||
auto componentD = new ComponentD();
|
||||
container.autowire!(ComponentD)(componentD);
|
||||
container.autowire(componentD);
|
||||
assert(componentD.privateComponentC is componentD.componentC, "Autowire private dependency failed");
|
||||
}
|
||||
|
||||
|
@ -105,9 +105,9 @@ version(unittest) {
|
|||
shared(DependencyContainer) container = new DependencyContainer();
|
||||
container.register!(InterfaceA, ComponentC).newInstance();
|
||||
auto componentD = new ComponentD();
|
||||
container.autowire!(ComponentD)(componentD);
|
||||
container.autowire(componentD);
|
||||
auto expectedComponent = componentD.componentC;
|
||||
container.autowire!(ComponentD)(componentD);
|
||||
container.autowire(componentD);
|
||||
auto actualComponent = componentD.componentC;
|
||||
assert(expectedComponent is actualComponent, "Autowiring the second time wired a different instance");
|
||||
}
|
||||
|
@ -116,14 +116,14 @@ version(unittest) {
|
|||
unittest {
|
||||
shared(DependencyContainer) container = new DependencyContainer();
|
||||
auto componentD = new ComponentD();
|
||||
assertThrown!(ResolveException)(container.autowire!(ComponentD)(componentD), "Autowiring unregistered type should throw ResolveException");
|
||||
assertThrown!(ResolveException)(container.autowire(componentD), "Autowiring unregistered type should throw ResolveException");
|
||||
}
|
||||
|
||||
// Test autowiring member with non-autowire attribute does not autowire
|
||||
unittest {
|
||||
shared(DependencyContainer) container = new DependencyContainer();
|
||||
auto componentE = new ComponentE();
|
||||
container.autowire!ComponentE(componentE);
|
||||
container.autowire(componentE);
|
||||
assert(componentE.componentC is null, "Autowiring should not occur for members with attributes other than @Autowire");
|
||||
}
|
||||
|
||||
|
|
|
@ -183,15 +183,15 @@ version(unittest) {
|
|||
// Test register concrete type
|
||||
unittest {
|
||||
shared(DependencyContainer) container = new DependencyContainer();
|
||||
auto registration = container.register!(TestClass)();
|
||||
auto registration = container.register!TestClass;
|
||||
assert(registration.registeredType == typeid(TestClass), "Type of registered type not the same");
|
||||
}
|
||||
|
||||
// Test resolve registered type
|
||||
unittest {
|
||||
shared(DependencyContainer) container = new DependencyContainer();
|
||||
container.register!(TestClass)();
|
||||
TestClass actualInstance = container.resolve!(TestClass)();
|
||||
container.register!TestClass;
|
||||
TestClass actualInstance = container.resolve!TestClass;
|
||||
assert(actualInstance !is null, "Resolved type is null");
|
||||
assert(cast(TestClass) actualInstance, "Resolved class is not the same type as expected");
|
||||
}
|
||||
|
@ -199,8 +199,8 @@ version(unittest) {
|
|||
// Test register interface
|
||||
unittest {
|
||||
shared(DependencyContainer) container = new DependencyContainer();
|
||||
container.register!(TestInterface, TestClass)();
|
||||
TestInterface actualInstance = container.resolve!(TestInterface)();
|
||||
container.register!(TestInterface, TestClass);
|
||||
TestInterface actualInstance = container.resolve!TestInterface;
|
||||
assert(actualInstance !is null, "Resolved type is null");
|
||||
assert(cast(TestInterface) actualInstance, "Resolved class is not the same type as expected");
|
||||
}
|
||||
|
@ -208,15 +208,15 @@ version(unittest) {
|
|||
// Test resolve non-registered type
|
||||
unittest {
|
||||
shared(DependencyContainer) container = new DependencyContainer();
|
||||
assertThrown!ResolveException(container.resolve!(TestClass)(), "Resolving non-registered type does not fail");
|
||||
assertThrown!ResolveException(container.resolve!TestClass, "Resolving non-registered type does not fail");
|
||||
}
|
||||
|
||||
// Test clear registrations
|
||||
unittest {
|
||||
shared(DependencyContainer) container = new DependencyContainer();
|
||||
container.register!(TestClass)();
|
||||
container.register!TestClass;
|
||||
container.clearAllRegistrations();
|
||||
assertThrown!ResolveException(container.resolve!(TestClass)(), "Resolving cleared type does not fail");
|
||||
assertThrown!ResolveException(container.resolve!TestClass, "Resolving cleared type does not fail");
|
||||
}
|
||||
|
||||
// Test get singleton of container
|
||||
|
@ -229,18 +229,18 @@ version(unittest) {
|
|||
// Test resolve single instance for type
|
||||
unittest {
|
||||
shared(DependencyContainer) container = new DependencyContainer();
|
||||
container.register!(TestClass)().singleInstance();
|
||||
auto instance1 = container.resolve!(TestClass);
|
||||
auto instance2 = container.resolve!(TestClass);
|
||||
container.register!TestClass.singleInstance();
|
||||
auto instance1 = container.resolve!TestClass;
|
||||
auto instance2 = container.resolve!TestClass;
|
||||
assert(instance1 is instance2, "Resolved instance from single instance scope is not the each time it is resolved");
|
||||
}
|
||||
|
||||
// Test resolve new instance for type
|
||||
unittest {
|
||||
shared(DependencyContainer) container = new DependencyContainer();
|
||||
container.register!(TestClass)().newInstance();
|
||||
auto instance1 = container.resolve!(TestClass);
|
||||
auto instance2 = container.resolve!(TestClass);
|
||||
container.register!TestClass.newInstance();
|
||||
auto instance1 = container.resolve!TestClass;
|
||||
auto instance2 = container.resolve!TestClass;
|
||||
assert(instance1 !is instance2, "Resolved instance from new instance scope is the same each time it is resolved");
|
||||
}
|
||||
|
||||
|
@ -248,8 +248,8 @@ version(unittest) {
|
|||
unittest {
|
||||
shared(DependencyContainer) container = new DependencyContainer();
|
||||
auto expectedInstance = new TestClass();
|
||||
container.register!(TestClass)().existingInstance(expectedInstance);
|
||||
auto actualInstance = container.resolve!(TestClass);
|
||||
container.register!TestClass.existingInstance(expectedInstance);
|
||||
auto actualInstance = container.resolve!TestClass;
|
||||
assert(expectedInstance is actualInstance, "Resolved instance from existing instance scope is not the same as the registered instance");
|
||||
}
|
||||
|
||||
|
@ -289,7 +289,7 @@ version(unittest) {
|
|||
existingB.autowiredClass = existingA;
|
||||
|
||||
container.register!AutowiredClass;
|
||||
container.register!(ComponentClass).existingInstance(existingB);
|
||||
container.register!ComponentClass.existingInstance(existingB);
|
||||
auto resolvedA = container.resolve!AutowiredClass;
|
||||
auto resolvedB = container.resolve!ComponentClass;
|
||||
|
||||
|
@ -323,9 +323,9 @@ version(unittest) {
|
|||
// Test autowiring deep circular dependencies with newInstance scope does not autowire new instance second time
|
||||
unittest {
|
||||
shared(DependencyContainer) container = new DependencyContainer();
|
||||
container.register!(Ittie).newInstance();
|
||||
container.register!(Bittie).newInstance();
|
||||
container.register!(Banana).newInstance();
|
||||
container.register!Ittie.newInstance();
|
||||
container.register!Bittie.newInstance();
|
||||
container.register!Banana.newInstance();
|
||||
|
||||
auto ittie = container.resolve!Ittie;
|
||||
|
||||
|
|
Loading…
Reference in a new issue