From 0127c0a80c34877c61f4f5352cc42f16708bc0da Mon Sep 17 00:00:00 2001 From: Mike Bierlee Date: Tue, 15 Jun 2021 23:34:50 +0300 Subject: [PATCH] Add unittest for fix in #37 --- test/poodinis/containertest.d | 14 ++++++++++++++ test/poodinis/testclasses.d | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/test/poodinis/containertest.d b/test/poodinis/containertest.d index 4de75db..2ba1028 100644 --- a/test/poodinis/containertest.d +++ b/test/poodinis/containertest.d @@ -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 { diff --git a/test/poodinis/testclasses.d b/test/poodinis/testclasses.d index 7d1bc3c..4e6133e 100644 --- a/test/poodinis/testclasses.d +++ b/test/poodinis/testclasses.d @@ -779,4 +779,14 @@ version (unittest) { } + + class ClassWithTemplatedConstructorArg(T) + { + public TemplatedComponent!T dependency; + + this(TemplatedComponent!T assignedDependency) + { + this.dependency = assignedDependency; + } + } }