Add unittest for fix in #37

This commit is contained in:
Mike Bierlee 2021-06-15 23:34:50 +03:00
parent 00dd758e01
commit 0127c0a80c
2 changed files with 24 additions and 0 deletions

View file

@ -547,6 +547,20 @@ version (unittest)
assert(instance.red is container.resolve!Red);
}
// Test autowired, constructor injected class where constructor argument is templated
unittest
{
auto container = new shared DependencyContainer();
container.register!PieChart;
container.register!(TemplatedComponent!PieChart);
container.register!(ClassWithTemplatedConstructorArg!PieChart);
auto instance = container.resolve!(ClassWithTemplatedConstructorArg!PieChart);
assert(instance !is null);
assert(instance.dependency !is null);
assert(instance.dependency.instance !is null);
}
// Test injecting constructor with super-type parameter
unittest
{

View file

@ -779,4 +779,14 @@ version (unittest)
{
}
class ClassWithTemplatedConstructorArg(T)
{
public TemplatedComponent!T dependency;
this(TemplatedComponent!T assignedDependency)
{
this.dependency = assignedDependency;
}
}
}