@@ -305,6 +305,42 @@ public void GenericFactoryMethodsAreSupported()
305305 handlers . Single ( ) . Should ( ) . BeOfType < IntMessageHandler > ( ) ;
306306 }
307307
308+ [ Fact ]
309+ public void DecoratorShouldBeInjectedWithAppropriateBinding ( )
310+ {
311+ this . kernel . Bind < IWeapon > ( ) . To < DecoratedWeapon > ( ) ;
312+ this . kernel . Bind < IWeapon > ( ) . To < Sword > ( ) . WhenInjectedExactlyInto < DecoratedWeapon > ( ) ;
313+ this . kernel . Bind < IWeaponFactory > ( ) . ToFactory ( ) ;
314+
315+ var instance = this . kernel . Get < IWeaponFactory > ( ) . CreateWeapon ( ) ;
316+ var decoratedWeapon = instance as DecoratedWeapon ;
317+
318+ instance . Should ( ) . BeOfType < DecoratedWeapon > ( ) ;
319+ decoratedWeapon . WeaponToBeDecorated . Should ( ) . BeOfType < Sword > ( ) ;
320+
321+ }
322+
323+ [ Fact ]
324+ public void DecoratorShouldBeInjectedWithAppropriateBindingWithArguments ( )
325+ {
326+ const string Name = "Excalibur" ;
327+ const int Width = 34 ;
328+ const int Length = 123 ;
329+
330+ this . kernel . Bind < ICustomizableWeapon > ( ) . To < DecoratedCustomizableWeapon > ( ) ;
331+ this . kernel . Bind < ICustomizableWeapon > ( ) . To < CustomizableSword > ( ) . WhenInjectedExactlyInto < DecoratedCustomizableWeapon > ( ) ;
332+ this . kernel . Bind < IWeaponFactory > ( ) . ToFactory ( ) ;
333+
334+ var weapon = this . kernel . Get < IWeaponFactory > ( ) . CreateCustomizableWeapon ( Length , Name , Width ) ;
335+ var decoratedWeapon = weapon as DecoratedCustomizableWeapon ;
336+
337+ weapon . Should ( ) . BeOfType < DecoratedCustomizableWeapon > ( ) ;
338+ decoratedWeapon . WeaponToBeDecorated . Should ( ) . BeOfType < CustomizableSword > ( ) ;
339+ weapon . Name . Should ( ) . Be ( Name ) ;
340+ weapon . Length . Should ( ) . Be ( Length ) ;
341+ weapon . Width . Should ( ) . Be ( Width ) ;
342+ }
343+
308344 private class CustomInstanceProvider : StandardInstanceProvider
309345 {
310346 protected override string GetName ( System . Reflection . MethodInfo methodInfo , object [ ] arguments )
0 commit comments