2014-05-20 21:54:11 +02:00
|
|
|
import poodinis.registration;
|
|
|
|
|
|
|
|
import std.exception;
|
|
|
|
|
|
|
|
version(unittest) {
|
|
|
|
class TestType {
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test getting instance without scope defined throws exception
|
|
|
|
unittest {
|
|
|
|
Registration registration = Registration();
|
|
|
|
registration.registeredType = typeid(TestType);
|
|
|
|
assertThrown!(NoScopeDefinedException)(registration.getInstance());
|
|
|
|
}
|
2014-05-20 22:03:50 +02:00
|
|
|
|
|
|
|
// Test getting instance from single instance scope
|
|
|
|
unittest {
|
|
|
|
Registration registration = Registration();
|
|
|
|
registration.registeredType = typeid(TestType);
|
|
|
|
registration.registationScope = new SingleInstanceScope(typeid(TestType));
|
|
|
|
auto instance1 = registration.getInstance();
|
|
|
|
auto instance2 = registration.getInstance();
|
|
|
|
assert(instance1 is instance2, "Registration with single instance scope did not return the same instance");
|
|
|
|
}
|
2014-05-20 21:54:11 +02:00
|
|
|
}
|