public void BuildUpAnExistingObjectAndInjectOnlyPropertiesWithAttributes() { IContainer container = CreateTarget(); container.Register <IDemo>(new Demo(222)); var injectionTarget = new PropertyInjection(); container.BuildUp(injectionTarget); // Normal property injection injectionTarget.Attribute.Should().NotBeNull(); injectionTarget.Attribute.GetId().Should().Be(222); injectionTarget.NoAttribute.Should().BeNull(); injectionTarget.PrivateAttribute.Should().BeNull(); // Again with other selection strategy container = new Container { Options = new ContainerOptions { PropertySelectionStrategy = PropertySelectionStrategies.AllWithDepencencyAttribute } }; container.Register <IDemo>(new Demo(666)); container.BuildUp(injectionTarget); // Normal property injection injectionTarget.Attribute.Should().NotBeNull(); injectionTarget.Attribute.GetId().Should().Be(666); injectionTarget.NoAttribute.Should().BeNull(); // Now also privates were injected injectionTarget.PrivateAttribute.Should().NotBeNull(); injectionTarget.Attribute.GetId().Should().Be(666); }
static void Main(string[] args) { PropertyInjection cs = new PropertyInjection(new DependencyInjectionCtorExample()); cs.print(); Console.ReadKey(); }
public void InjectProperties_Should_Skip_UnresolvableDependencies() { var customDependency = new TestService(); var obj = new PropertyInjection {Service = customDependency}; Container.Kernel.InjectProperties(obj, this.propertyCache); obj.Service.Should().BeSameAs(customDependency); }
public void InjectProperties_Should_Inject_ResolvableDependencies() { Container.Register(Component.For<ITestService>().ImplementedBy<TestService>()); var obj = new PropertyInjection(); Container.Kernel.InjectProperties(obj, this.propertyCache); obj.Service.Should().NotBeNull(); }
public void InjectProperties_Should_Inject_ResolvableDependencies() { Container.Register(Component.For <ITestService>().ImplementedBy <TestService>()); var obj = new PropertyInjection(); Container.Kernel.InjectProperties(obj, this.propertyCache); obj.Service.Should().NotBeNull(); }
public void InjectProperties_Should_Skip_UnresolvableDependencies() { var customDependency = new TestService(); var obj = new PropertyInjection { Service = customDependency }; Container.Kernel.InjectProperties(obj, this.propertyCache); obj.Service.Should().BeSameAs(customDependency); }
public void CleanupInjectableProperties_Should_NullProperties() { Container.Register(Component.For<ITestService>().ImplementedBy<TestService>()); var obj = new PropertyInjection(); Container.Kernel.InjectProperties(obj, this.propertyCache); Container.Kernel.CleanupInjectableProperties(obj, this.propertyCache); obj.Service.Should().BeNull(); }
public void CleanupInjectableProperties_Should_NullProperties() { Container.Register(Component.For <ITestService>().ImplementedBy <TestService>()); var obj = new PropertyInjection(); Container.Kernel.InjectProperties(obj, this.propertyCache); Container.Kernel.CleanupInjectableProperties(obj, this.propertyCache); obj.Service.Should().BeNull(); }
public void PropertyInjectionTest() { InMemoryTraceSource _TraceSource = new InMemoryTraceSource(); PropertyInjection _ConstructorInjection = new PropertyInjection() { TraceSource = _TraceSource }; _ConstructorInjection.Alpha(); Assert.AreEqual<int>(1, _TraceSource._callStack.Count); _ConstructorInjection.Bravo(); Assert.AreEqual<int>(2, _TraceSource._callStack.Count); _ConstructorInjection.Charlie(); Assert.AreEqual<int>(3, _TraceSource._callStack.Count); _ConstructorInjection.Delta(); Assert.AreEqual<int>(4, _TraceSource._callStack.Count); _TraceSource.CheckConsistency(); _ConstructorInjection.TraceSource = new DoNothingTraceSource(); _ConstructorInjection.Alpha(); _ConstructorInjection.Bravo(); _ConstructorInjection.Charlie(); _ConstructorInjection.Delta(); Assert.AreEqual<int>(4, _TraceSource._callStack.Count); }
public void PropertyInjectionTest() { InMemoryTraceSource _TraceSource = new InMemoryTraceSource(); PropertyInjection _ConstructorInjection = new PropertyInjection() { TraceSource = _TraceSource }; _ConstructorInjection.Alpha(); Assert.AreEqual <int>(1, _TraceSource._callStack.Count); _ConstructorInjection.Bravo(); Assert.AreEqual <int>(2, _TraceSource._callStack.Count); _ConstructorInjection.Charlie(); Assert.AreEqual <int>(3, _TraceSource._callStack.Count); _ConstructorInjection.Delta(); Assert.AreEqual <int>(4, _TraceSource._callStack.Count); _TraceSource.CheckConsistency(); _ConstructorInjection.TraceSource = new DoNothingTraceSource(); _ConstructorInjection.Alpha(); _ConstructorInjection.Bravo(); _ConstructorInjection.Charlie(); _ConstructorInjection.Delta(); Assert.AreEqual <int>(4, _TraceSource._callStack.Count); }
public void NoTracerDefinedTestMethod() { PropertyInjection _PropertyInjection = new PropertyInjection(); _PropertyInjection.Alpha(); }
public void AfterCreationStateTestMethod() { PropertyInjection _PropertyInjection = new PropertyInjection(); Assert.IsNull(_PropertyInjection.TraceSource); }
public void NoTracerDefinedTestMethod() { PropertyInjection _PropertyInjection = new PropertyInjection(); _PropertyInjection.Alpha(); }
public void AfterCreationStateTestMethod() { PropertyInjection _PropertyInjection = new PropertyInjection(); Assert.IsNull(_PropertyInjection.TraceSource); }