Exemplo n.º 1
0
		/// <summary>
		/// Executes method call by reflection one million times.
		/// </summary>
		public void ExecuteCallMethodByReflection() {
			var instance = new MockIClassWithoutAttributes();
			var method = instance.GetType().GetMethod(CLASS_METHOD);
			for (int i = 0; i < 1000000; i++) {
				method.Invoke(instance, null);
			}
		}
Exemplo n.º 2
0
		/// <summary>
		/// Executes a method call by IL one million times.
		/// </summary>
		public void ExecuteCallMethodByIL() {
			var instance = new MockIClassWithoutAttributes();
			var method = ReflectionUtils.CreateMethod<MockIClassWithoutAttributes>(CLASS_METHOD);
			for (int i = 0; i < 1000000; i++) {
				method(instance);
			}
		}
Exemplo n.º 3
0
        public void TestBeforeResolveStop()
        {
            var eventCalled = false;

            IReflectionCache cache    = new ReflectionCache();
            IBinder          binder   = new Binder();
            IInjector        injector = new Injector(cache, binder, ResolutionMode.ALWAYS_RESOLVE);

            injector.beforeResolve += delegate(
                IInjector source,
                Type type,
                InjectionMember member,
                object parentInstance,
                object identifier,
                ref object resolutionInstance) {
                Assert.AreEqual(injector, source);
                Assert.AreEqual(typeof(IMockInterface), type);
                Assert.AreEqual(InjectionMember.None, member);
                Assert.IsNull(parentInstance);
                Assert.IsNull(identifier);
                Assert.IsNull(resolutionInstance);

                resolutionInstance = new MockIClassWithoutAttributes();

                eventCalled = true;

                return(false);
            };

            binder.Bind <IMockInterface>().To <MockIClass>();
            var instance = injector.Resolve <IMockInterface>();

            Assert.IsTrue(eventCalled);
            Assert.AreEqual(typeof(MockIClassWithoutAttributes), instance.GetType());
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Executes construct by activator one million times.
        /// </summary>
        public void ExecuteConstructByActivator()
        {
            MockIClassWithoutAttributes instance = null;

            for (int i = 0; i < 1000000; i++)
            {
                instance = Activator.CreateInstance <MockIClassWithoutAttributes>();
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Executes construct directly one million times.
        /// </summary>
        public void ExecuteConstructDirectly()
        {
            MockIClassWithoutAttributes instance = null;

            for (int i = 0; i < 1000000; i++)
            {
                instance = new MockIClassWithoutAttributes();
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Executes a directly method call one million times.
        /// </summary>
        public void ExecuteCallMethodDirectly()
        {
            var instance = new MockIClassWithoutAttributes();

            for (int i = 0; i < 1000000; i++)
            {
                instance.SomeMethod1();
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Executes construct by IL one million times.
        /// </summary>
        public void ExecuteConstructByIL()
        {
            MockIClassWithoutAttributes instance = null;
            var constructor = ReflectionUtils.CreateConstructor <MockIClassWithoutAttributes>();

            for (int i = 0; i < 1000000; i++)
            {
                instance = constructor();
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Executes a method call by IL one million times.
        /// </summary>
        public void ExecuteCallMethodByIL()
        {
            var instance = new MockIClassWithoutAttributes();
            var method   = ReflectionUtils.CreateMethod <MockIClassWithoutAttributes>(CLASS_METHOD);

            for (int i = 0; i < 1000000; i++)
            {
                method(instance);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Executes method call by reflection one million times.
        /// </summary>
        public void ExecuteCallMethodByReflection()
        {
            var instance = new MockIClassWithoutAttributes();
            var method   = instance.GetType().GetMethod(CLASS_METHOD);

            for (int i = 0; i < 1000000; i++)
            {
                method.Invoke(instance, null);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Executes construct directly one million times.
        /// </summary>
        public void ExecuteConstructWithParamsDirectly()
        {
            MockIClassWithoutAttributes instance = null;
            var dependency = new MockClassToDepend();

            for (int i = 0; i < 1000000; i++)
            {
                instance = new MockIClassWithoutAttributes(dependency);
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Executes construct by reflection one million times.
        /// </summary>
        public void ExecuteConstructByReflection()
        {
            MockIClassWithoutAttributes instance = null;
            var constructor = typeof(MockIClassWithoutAttributes).GetConstructors(
                BindingFlags.FlattenHierarchy |
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.InvokeMethod)[0];

            for (int i = 0; i < 1000000; i++)
            {
                instance = (MockIClassWithoutAttributes)constructor.Invoke(null);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Executes construct by reflection one million times.
        /// </summary>
        public void ExecuteConstructWithParamsByReflection()
        {
            MockIClassWithoutAttributes instance = null;
            var constructorInfo = typeof(MockIClassWithoutAttributes).GetConstructors(
                BindingFlags.FlattenHierarchy |
                BindingFlags.Public |
                BindingFlags.Instance |
                BindingFlags.InvokeMethod)[1];
            var dependency = new MockClassToDepend();

            object[] parameters = new object[1] {
                dependency
            };

            for (int i = 0; i < 1000000; i++)
            {
                instance = (MockIClassWithoutAttributes)constructorInfo.Invoke(parameters);
            }
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
0
		/// <summary>
		/// Executes a directly method call one million times.
		/// </summary>
		public void ExecuteCallMethodDirectly() {
			var instance = new MockIClassWithoutAttributes();
			for (int i = 0; i < 1000000; i++) {
				instance.SomeMethod1();
			}
		}
Exemplo n.º 16
0
		/// <summary>
		/// Executes construct directly one million times.
		/// </summary>
		public void ExecuteConstructDirectly() {
			MockIClassWithoutAttributes instance = null;
			for (int i = 0; i < 1000000; i++) {
				instance = new MockIClassWithoutAttributes();
			}
		}
Exemplo n.º 17
0
		/// <summary>
		/// Executes construct directly one million times.
		/// </summary>
		public void ExecuteConstructWithParamsDirectly() {
			MockIClassWithoutAttributes instance = null;
			var dependency = new MockClassToDepend();
			for (int i = 0; i < 1000000; i++) {
				instance = new MockIClassWithoutAttributes(dependency);
			}
		}
Exemplo n.º 18
0
        public void TestBeforeResolveStop()
        {
            var eventCalled = false;

            IReflectionCache cache = new ReflectionCache();
            IBinder binder = new Binder();
            IInjector injector = new Injector(cache, binder);

            injector.beforeResolve += delegate(
                IInjector source,
                Type type,
                InjectionMember member,
                object parentInstance,
                object identifier,
                ref object resolutionInstance) {
                Assert.AreEqual(injector, source);
                Assert.AreEqual(typeof(IMockInterface), type);
                Assert.AreEqual(InjectionMember.None, member);
                Assert.IsNull(parentInstance);
                Assert.IsNull(identifier);
                Assert.IsNull(resolutionInstance);

                resolutionInstance = new MockIClassWithoutAttributes();

                eventCalled = true;

                return false;
            };

            binder.Bind<IMockInterface>().To<MockIClass>();
            var instance = injector.Resolve<IMockInterface>();

            Assert.IsTrue(eventCalled);
            Assert.AreEqual(typeof(MockIClassWithoutAttributes), instance.GetType());
        }