コード例 #1
0
        public void TestBindWhenIntoByInstance()
        {
            var instance1 = new MockClassSimple();
            var instance2 = new MockClassVerySimple();

            var container = new InjectionContainer();

            container.Bind <IMockInterface>().To <MockIClassWithAttributes>().WhenIntoInstance(instance1);
            container.Bind <IMockInterface>().To <MockIClassWithoutAttributes>().WhenIntoInstance(instance2);

            container.Inject(instance1);
            container.Inject(instance2);

            Assert.AreEqual(typeof(MockIClassWithAttributes), instance1.field.GetType());
            Assert.AreEqual(typeof(MockIClassWithoutAttributes), instance2.field.GetType());
        }
コード例 #2
0
ファイル: ConditionsTests.cs プロジェクト: NotYours180/adic
        public void TestBindAsIdentifierWhenIntoByInstance()
        {
            var instance1 = new MockClassVerySimple();
            var instance2 = new MockClassSimple();

            var container = new InjectionContainer();

            container.Bind<IMockInterface>()
                .To<MockIClassWithAttributes>().WhenIntoInstance(instance1);
            container.Bind<IMockInterface>()
                .To<MockIClassWithoutAttributes>().WhenIntoInstance(instance2).As("singleton");
            container.Bind<IMockInterface>()
                .To<MockIClass>().WhenInto<MockClassSimple>().WhenIntoInstance(instance2).As("test");

            container.Inject(instance1);
            container.Inject(instance2);

            Assert.AreEqual(typeof(MockIClassWithAttributes), instance1.field.GetType());
            Assert.IsNull(instance2.field);
            Assert.AreEqual(typeof(MockIClassWithoutAttributes), instance2.property.GetType());
        }
コード例 #3
0
        public void TestBindAsIdentifierWhenIntoByInstance()
        {
            var instance1 = new MockClassVerySimple();
            var instance2 = new MockClassSimple();

            var container = new InjectionContainer();

            container.Bind <IMockInterface>()
            .To <MockIClassWithAttributes>().WhenIntoInstance(instance1);
            container.Bind <IMockInterface>()
            .To <MockIClassWithoutAttributes>().WhenIntoInstance(instance2).As("singleton");
            container.Bind <IMockInterface>()
            .To <MockIClass>().WhenInto <MockClassSimple>().WhenIntoInstance(instance2).As("test");

            container.Inject(instance1);
            container.Inject(instance2);

            Assert.AreEqual(typeof(MockIClassWithAttributes), instance1.field.GetType());
            Assert.IsNull(instance2.field);
            Assert.AreEqual(typeof(MockIClassWithoutAttributes), instance2.property.GetType());
        }
コード例 #4
0
        public void Inject_SomeClass_Correct()
        {
            //Arrange
            var         container = new InjectionContainer();
            someClass_c c         = new someClass_c();

            //Act
            container.Inject(c);
            //Assert
            Assert.AreEqual(
                true,
                c.b != null);
        }
コード例 #5
0
        public void TestBindWhenComplexConditionField()
        {
            var instance1 = new MockClassVerySimple();
            var instance2 = new MockClassSimple();
            var instance3 = new MockClassSimple();

            var container = new InjectionContainer();

            container.Bind <IMockInterface>().To <MockIClass>().When(context =>
                                                                     context.member.Equals(InjectionMember.Field) &&
                                                                     context.parentInstance.Equals(instance3)
                                                                     );

            container.Inject(instance1);
            container.Inject(instance2);
            container.Inject(instance3);

            Assert.IsNull(instance1.field);
            Assert.IsNull(instance2.field);
            Assert.IsNull(instance2.property);
            Assert.AreEqual(typeof(MockIClass), instance3.field.GetType());
            Assert.IsNull(instance3.property);
        }
コード例 #6
0
ファイル: ConditionsTests.cs プロジェクト: NotYours180/adic
        public void TestBindWhenComplexCondition()
        {
            var instance1 = new MockClassVerySimple();
            var instance2 = new MockClassSimple();
            var instance3 = new MockClassSimple();

            var container = new InjectionContainer();

            container.Bind<IMockInterface>().To<MockIClass>().When(context =>
                    context.member.Equals(InjectionMember.Field) &&
                    context.parentInstance.Equals(instance3)
                );

            container.Inject(instance1);
            container.Inject(instance2);
            container.Inject(instance3);

            Assert.IsNull(instance1.field);
            Assert.IsNull(instance2.field);
            Assert.IsNull(instance2.property);
            Assert.AreEqual(typeof(MockIClass), instance3.field.GetType());
            Assert.IsNull(instance3.property);
        }
コード例 #7
0
ファイル: ConditionsTests.cs プロジェクト: NotYours180/adic
        public void TestBindWhenIntoByInstance()
        {
            var instance1 = new MockClassSimple();
            var instance2 = new MockClassVerySimple();

            var container = new InjectionContainer();

            container.Bind<IMockInterface>().To<MockIClassWithAttributes>().WhenIntoInstance(instance1);
            container.Bind<IMockInterface>().To<MockIClassWithoutAttributes>().WhenIntoInstance(instance2);

            container.Inject(instance1);
            container.Inject(instance2);

            Assert.AreEqual(typeof(MockIClassWithAttributes), instance1.field.GetType());
            Assert.AreEqual(typeof(MockIClassWithoutAttributes), instance2.field.GetType());
        }