Exemple #1
0
        public void Init()
        {
            this.injector = new InjectionContainer();
            this.binder   = this.injector as IBinder;

            //Binds some objects to use on tests.
            binder.Bind <IMockInterface>().To <MockIClassWithAttributes>();
            binder.Bind <MockIClassWithoutAttributes>().ToSingleton().As("singleton");
            binder.Bind <MockIClass>().ToSingleton();

            this.containerIdentifierTests = new InjectionContainer();
            var mockClass1 = new MockIClass()
            {
                property1 = "MockClass1"
            };
            var mockClass2 = new MockIClassWithoutAttributes()
            {
                property1 = "MockClass2"
            };
            var mockClass3 = new MockIClassWithAttributes()
            {
                property1 = "MockClass3"
            };

            this.containerIdentifierTests.Bind <MockIClass>().To(mockClass1).As(TestIdentifier.MockClass);
            this.containerIdentifierTests.Bind <MockIClassWithoutAttributes>().To(mockClass2).As(TestIdentifier.MockClass);
            this.containerIdentifierTests.Bind <MockIClassWithAttributes>().To(mockClass3).As(TestIdentifier.MockClass);
            this.containerIdentifierTests.Bind <IMockInterface>().To(mockClass1).As(TestIdentifier.MockClass1);
            this.containerIdentifierTests.Bind <IMockInterface>().To(mockClass2).As(TestIdentifier.MockClass2);
            this.containerIdentifierTests.Bind <IMockInterface>().To(mockClass3).As(TestIdentifier.MockClass3);
            this.containerIdentifierTests.Bind <IMockInterface>().To <MockIClass>().As(TestIdentifier.MockClassSingle);
        }
Exemple #2
0
        public object Create(InjectionContext context)
        {
            var obj = new MockIClassWithAttributes();

            obj.field1         =
                obj.field2     =
                    obj.field3 = "Created from a Factory";

            return(obj);
        }
        public void TestBindingToInstanceFromInterface()
        {
            var binder = new Binder();

            var instance = new MockIClassWithAttributes();
            binder.Bind<IMockInterface>().To<MockIClassWithAttributes>(instance);
            var bindings = binder.GetBindingsFor<IMockInterface>();

            Assert.AreEqual(1, bindings.Count);
            Assert.AreEqual(BindingInstance.Singleton, bindings[0].instanceType);
            Assert.AreEqual(typeof(IMockInterface), bindings[0].type);
            Assert.AreEqual(instance, bindings[0].value);
        }
Exemple #4
0
        public void TestBindingToInstanceFromInterface()
        {
            var binder = new Binder();

            var instance = new MockIClassWithAttributes();

            binder.Bind <IMockInterface>().To <MockIClassWithAttributes>(instance);
            var bindings = binder.GetBindingsFor <IMockInterface>();

            Assert.AreEqual(1, bindings.Count);
            Assert.AreEqual(BindingInstance.Singleton, bindings[0].instanceType);
            Assert.AreEqual(typeof(IMockInterface), bindings[0].type);
            Assert.AreEqual(instance, bindings[0].value);
        }
Exemple #5
0
        public void TestUnbindByInstance()
        {
            var binder = new Binder();

            var instance = new MockIClassWithAttributes();

            binder.Bind <MockClassToDepend>().ToSelf();
            binder.Bind <MockClassToDepend>().ToSelf().WhenIntoInstance(instance);
            binder.Bind <IMockInterface>().To(instance).As("Mock1");
            binder.UnbindInstance(instance);

            var bindings = binder.GetBindings();

            Assert.AreEqual(1, bindings.Count);
            Assert.AreEqual(typeof(MockClassToDepend), bindings[0].type);
        }
Exemple #6
0
        public void Init()
        {
            this.injector = new InjectionContainer();
            this.binder = this.injector as IBinder;

            //Binds some objects to use on tests.
            binder.Bind<IMockInterface>().To<MockIClassWithAttributes>();
            binder.Bind<MockIClassWithoutAttributes>().ToSingleton().As("singleton");
            binder.Bind<MockIClass>().ToSingleton();

            this.containerIdentifierTests = new InjectionContainer();
            var mockClass1 = new MockIClass() { property1 = "MockClass1" };
            var mockClass2 = new MockIClassWithoutAttributes() { property1 = "MockClass2" };
            var mockClass3 = new MockIClassWithAttributes() { property1 = "MockClass3" };
            this.containerIdentifierTests.Bind<MockIClass>().To(mockClass1).As(TestIdentifier.MockClass);
            this.containerIdentifierTests.Bind<MockIClassWithoutAttributes>().To(mockClass2).As(TestIdentifier.MockClass);
            this.containerIdentifierTests.Bind<MockIClassWithAttributes>().To(mockClass3).As(TestIdentifier.MockClass);
            this.containerIdentifierTests.Bind<IMockInterface>().To(mockClass1).As(TestIdentifier.MockClass1);
            this.containerIdentifierTests.Bind<IMockInterface>().To(mockClass2).As(TestIdentifier.MockClass2);
            this.containerIdentifierTests.Bind<IMockInterface>().To(mockClass3).As(TestIdentifier.MockClass3);
            this.containerIdentifierTests.Bind<IMockInterface>().To<MockIClass>().As(TestIdentifier.MockClassSingle);
        }
Exemple #7
0
        public object Create(InjectionContext context)
        {
            var obj = new MockIClassWithAttributes();
            obj.field1 =
                obj.field2 =
                    obj.field3 = "Created from a Factory";

            return obj;
        }