예제 #1
0
        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);
        }
예제 #2
0
            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();
        }
예제 #5
0
        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();
        }
예제 #6
0
        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();
        }
예제 #8
0
        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();
        }
예제 #9
0
 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);
 }
예제 #10
0
        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);
        }
예제 #11
0
 public void NoTracerDefinedTestMethod()
 {
     PropertyInjection _PropertyInjection = new PropertyInjection();
       _PropertyInjection.Alpha();
 }
예제 #12
0
 public void AfterCreationStateTestMethod()
 {
     PropertyInjection _PropertyInjection = new PropertyInjection();
       Assert.IsNull(_PropertyInjection.TraceSource);
 }
예제 #13
0
        public void NoTracerDefinedTestMethod()
        {
            PropertyInjection _PropertyInjection = new PropertyInjection();

            _PropertyInjection.Alpha();
        }
예제 #14
0
        public void AfterCreationStateTestMethod()
        {
            PropertyInjection _PropertyInjection = new PropertyInjection();

            Assert.IsNull(_PropertyInjection.TraceSource);
        }