예제 #1
0
        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);
        }
예제 #2
0
		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);
		}
예제 #3
0
        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);
        }
예제 #4
0
        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"
        }
예제 #5
0
        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);
        }
예제 #6
0
		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"

		}
예제 #7
0
		private void cb(SimpleInterfaceImplementer instance)
		{
			instanceList.Add (instance);
		}
예제 #8
0
 private void cb(SimpleInterfaceImplementer instance)
 {
     instanceList.Add(instance);
 }