/// <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); } }
/// <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); } }
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()); }
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); }
/// <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>(); } }
/// <summary> /// Executes construct directly one million times. /// </summary> public void ExecuteConstructDirectly() { MockIClassWithoutAttributes instance = null; for (int i = 0; i < 1000000; i++) { instance = new MockIClassWithoutAttributes(); } }
/// <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(); } }
/// <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(); } }
/// <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); } }
/// <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); } }
/// <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); } }
/// <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); } }
/// <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); } }
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); }
/// <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(); } }
/// <summary> /// Executes construct directly one million times. /// </summary> public void ExecuteConstructDirectly() { MockIClassWithoutAttributes instance = null; for (int i = 0; i < 1000000; i++) { instance = new MockIClassWithoutAttributes(); } }
/// <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); } }
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()); }