public void TestOverrideInjections() { binder.Bind <ExtendedInheritanceOverride>().ToSingleton(); ISimpleInterface simple = new SimpleInterfaceImplementer(); IExtendedInterface extended = new ExtendedInterfaceImplementer(); binder.Bind <ISimpleInterface>().ToValue(simple); binder.Bind <IExtendedInterface>().ToValue(extended); ExtendedInheritanceOverride overridingInjectable = binder.GetInstance <ExtendedInheritanceOverride>(); Assert.NotNull(overridingInjectable); Assert.NotNull(overridingInjectable.MyInterface); Assert.AreEqual(overridingInjectable.MyInterface, extended); }
public void TestShortestConstructor () { IReflectedClass reflected = reflector.Get<MultipleConstructorsUntagged> (); Assert.AreEqual (3, reflected.ConstructorParameters.Length); ISimpleInterface simple = new SimpleInterfaceImplementer (); simple.intValue = 11001001; ConstructorInfo constructor = reflected.Constructor; object[] parameters = new object[3]; parameters [0] = simple; parameters [1] = 42; parameters [2] = "Zaphod"; MultipleConstructorsUntagged instance = constructor.Invoke(parameters) as MultipleConstructorsUntagged; Assert.IsNotNull (instance); Assert.AreEqual (simple.intValue, instance.simple.intValue); Assert.AreEqual (42, instance.intValue); Assert.AreEqual ("Zaphod", instance.stringValue); }
public void TestRuntimeInjectionBindToSelf() { string jsonString = "[{\"Bind\":\"strange.unittests.SimpleInterfaceImplementer\"}]"; binder.ConsumeBindings(jsonString); IBinding binding = binder.GetBinding <SimpleInterfaceImplementer> (); Assert.NotNull(binding); Assert.AreEqual((binding as IInjectionBinding).type, InjectionBindingType.DEFAULT); SimpleInterfaceImplementer instance = binder.GetInstance(typeof(SimpleInterfaceImplementer)) as SimpleInterfaceImplementer; Assert.IsInstanceOf <SimpleInterfaceImplementer> (instance); ISimpleInterface instance2 = binder.GetInstance(typeof(SimpleInterfaceImplementer)) as ISimpleInterface; Assert.AreNotSame(instance, instance2); }
public void TestWeakBindings() { SimpleInterfaceImplementer one = new SimpleInterfaceImplementer(); SimpleInterfaceImplementerTwo two = new SimpleInterfaceImplementerTwo(); IBinding binding = binder.Bind <ISimpleInterface>().To(one).Weak(); binding.valueConstraint = BindingConstraintType.ONE; TestDelegate testDelegate = delegate { binder.Bind <ISimpleInterface>().To(two).valueConstraint = BindingConstraintType.ONE; IBinding retrievedBinding = binder.GetBinding <ISimpleInterface>(); Assert.NotNull(retrievedBinding); Assert.NotNull(retrievedBinding.value); Console.WriteLine(retrievedBinding.value); Assert.AreEqual(retrievedBinding.value, two); }; Assert.DoesNotThrow(testDelegate); //Second binding "two" overrides weak binding "one" }
public void TestShortestConstructor() { IReflectedClass reflected = reflector.Get <MultipleConstructorsUntagged> (); Assert.AreEqual(3, reflected.ConstructorParameters.Length); ISimpleInterface simple = new SimpleInterfaceImplementer(); simple.intValue = 11001001; ConstructorInfo constructor = reflected.Constructor; object[] parameters = new object[3]; parameters [0] = simple; parameters [1] = 42; parameters [2] = "Zaphod"; MultipleConstructorsUntagged instance = constructor.Invoke(parameters) as MultipleConstructorsUntagged; Assert.IsNotNull(instance); Assert.AreEqual(simple.intValue, instance.simple.intValue); Assert.AreEqual(42, instance.intValue); Assert.AreEqual("Zaphod", instance.stringValue); }
public void TestWeakBindings() { SimpleInterfaceImplementer one = new SimpleInterfaceImplementer(); SimpleInterfaceImplementerTwo two = new SimpleInterfaceImplementerTwo(); IBinding binding = binder.Bind<ISimpleInterface>().To(one).Weak(); binding.valueConstraint = BindingConstraintType.ONE; TestDelegate testDelegate = delegate { binder.Bind<ISimpleInterface>().To(two).valueConstraint = BindingConstraintType.ONE; IBinding retrievedBinding = binder.GetBinding<ISimpleInterface>(); Assert.NotNull(retrievedBinding); Assert.NotNull(retrievedBinding.value); Console.WriteLine(retrievedBinding.value); Assert.AreEqual(retrievedBinding.value, two); }; Assert.DoesNotThrow(testDelegate); //Second binding "two" overrides weak binding "one" }
private void cb(SimpleInterfaceImplementer instance) { instanceList.Add (instance); }
private void cb(SimpleInterfaceImplementer instance) { instanceList.Add(instance); }