public void TestRemoveList()
        {
            semibinding.constraint = BindingConstraintType.MANY;

            ClassWithConstructorParameters o  = new ClassWithConstructorParameters(42, "abc");
            ClassWithConstructorParameters o1 = new ClassWithConstructorParameters(43, "def");
            ClassWithConstructorParameters o2 = new ClassWithConstructorParameters(44, "ghi");

            ClassWithConstructorParameters[] list = new ClassWithConstructorParameters[3] {
                o, o1, o2
            };
            semibinding.Add(list);

            object[] before = semibinding.value as object[];
            Assert.AreEqual(3, before.Length);
            ClassWithConstructorParameters beforeValue = before [2] as ClassWithConstructorParameters;

            Assert.AreEqual(o2, beforeValue);
            Assert.AreEqual(44, beforeValue.intValue);

            ClassWithConstructorParameters[] removalList = new ClassWithConstructorParameters[2] {
                o, o2
            };
            semibinding.Remove(removalList);

            object[] after = semibinding.value as object[];
            Assert.AreEqual(1, after.Length);
            ClassWithConstructorParameters afterValue = after [0] as ClassWithConstructorParameters;

            Assert.AreEqual(o1, afterValue);
            Assert.AreEqual(43, afterValue.intValue);
        }
Beispiel #2
0
		public void TestObject ()
		{
			ClassWithConstructorParameters o = new ClassWithConstructorParameters (42, "abc");
			semibinding.Add (o);
			Assert.AreEqual (o, semibinding.value);
			Assert.AreEqual (42, o.intValue);
		}
Beispiel #3
0
        public void TestRemoveFromMultiSemibinding()
        {
            semibinding.constraint = BindingConstraintType.MANY;

            ClassWithConstructorParameters o = new ClassWithConstructorParameters(42, "abc");

            semibinding.Add(o);
            ClassWithConstructorParameters o1 = new ClassWithConstructorParameters(43, "def");

            semibinding.Add(o1);
            ClassWithConstructorParameters o2 = new ClassWithConstructorParameters(44, "ghi");

            semibinding.Add(o2);

            object[] before = semibinding.value as object[];
            Assert.AreEqual(3, before.Length);
            ClassWithConstructorParameters beforeValue = before [2] as ClassWithConstructorParameters;

            Assert.AreEqual(o2, beforeValue);
            Assert.AreEqual(44, beforeValue.intValue);

            semibinding.Remove(o1);

            object[] after = semibinding.value as object[];
            Assert.AreEqual(2, after.Length);
            ClassWithConstructorParameters afterValue = after [1] as ClassWithConstructorParameters;

            Assert.AreEqual(o2, afterValue);
            Assert.AreEqual(44, afterValue.intValue);
        }
Beispiel #4
0
        public void TestObject()
        {
            ClassWithConstructorParameters o = new ClassWithConstructorParameters(42, "abc");

            semibinding.Add(o);
            Assert.AreEqual(o, semibinding.value);
            Assert.AreEqual(42, o.intValue);
        }
Beispiel #5
0
		public void TestOverwriteSingleSemibinding ()
		{
			ClassWithConstructorParameters o = new ClassWithConstructorParameters (42, "abc");
			semibinding.Add (o);
			ClassWithConstructorParameters o1 = new ClassWithConstructorParameters (43, "def");
			semibinding.Add (o1);
			ClassWithConstructorParameters o2 = new ClassWithConstructorParameters (44, "ghi");
			semibinding.Add (o2);
			Assert.AreNotEqual (o, semibinding.value);
			Assert.AreEqual (o2, semibinding.value);
			Assert.AreEqual (44, o2.intValue);
		}
Beispiel #6
0
        public void TestTaggedConstructor()
        {
            binder.Bind <ClassWithConstructorParameters> ().To <ClassWithConstructorParameters> ();
            binder.Bind <int> ().ToValue(42);
            binder.Bind <string> ().ToValue("Liberator");
            ClassWithConstructorParameters instance =
                binder.GetInstance <ClassWithConstructorParameters> () as ClassWithConstructorParameters;

            Assert.IsNotNull(instance);
            Assert.AreEqual(42, instance.intValue);
            Assert.AreEqual("Liberator", instance.stringValue);
        }
        public void TestOneToOneConstrainedBinding()
        {
            ClassWithConstructorParameters test1 = new ClassWithConstructorParameters(1, "abc");
            ClassWithConstructorParameters test2 = new ClassWithConstructorParameters(2, "def");
            ClassWithConstructorParameters test3 = new ClassWithConstructorParameters(3, "ghi");

            binding.valueConstraint = BindingConstraintType.ONE;
            binding.Key <ISimpleInterface> ().To(test1).To(test2).To(test3);
            Assert.That(binding.key == typeof(ISimpleInterface));
            Assert.That(binding.value is ClassWithConstructorParameters);
            Assert.That((binding.value as ClassWithConstructorParameters).intValue == 3);

            //Clean up
            binding.valueConstraint = BindingConstraintType.MANY;
        }
Beispiel #8
0
        public void TestOverwriteSingleSemibinding()
        {
            ClassWithConstructorParameters o = new ClassWithConstructorParameters(42, "abc");

            semibinding.Add(o);
            ClassWithConstructorParameters o1 = new ClassWithConstructorParameters(43, "def");

            semibinding.Add(o1);
            ClassWithConstructorParameters o2 = new ClassWithConstructorParameters(44, "ghi");

            semibinding.Add(o2);
            Assert.AreNotEqual(o, semibinding.value);
            Assert.AreEqual(o2, semibinding.value);
            Assert.AreEqual(44, o2.intValue);
        }
Beispiel #9
0
		public void TestRemoveFromSingleSemibinding ()
		{
			semibinding.constraint = BindingConstraintType.ONE;

			ClassWithConstructorParameters o = new ClassWithConstructorParameters (42, "abc");
			semibinding.Add (o);

			ClassWithConstructorParameters value = semibinding.value as ClassWithConstructorParameters;

			Assert.AreEqual (o, value);
			Assert.AreEqual (42, value.intValue);

			semibinding.Remove (o);

			Assert.IsNull (semibinding.value);
		}
Beispiel #10
0
        public void TestRemoveFromSingleSemibinding()
        {
            semibinding.constraint = BindingConstraintType.ONE;

            ClassWithConstructorParameters o = new ClassWithConstructorParameters(42, "abc");

            semibinding.Add(o);

            ClassWithConstructorParameters value = semibinding.value as ClassWithConstructorParameters;

            Assert.AreEqual(o, value);
            Assert.AreEqual(42, value.intValue);

            semibinding.Remove(o);

            Assert.IsNull(semibinding.value);
        }
Beispiel #11
0
		public void TestMultiSemibinding ()
		{
			semibinding.constraint = BindingConstraintType.MANY;

			ClassWithConstructorParameters o = new ClassWithConstructorParameters (42, "abc");
			semibinding.Add (o);
			ClassWithConstructorParameters o1 = new ClassWithConstructorParameters (43, "def");
			semibinding.Add (o1);
			ClassWithConstructorParameters o2 = new ClassWithConstructorParameters (44, "ghi");
			semibinding.Add (o2);

			object[] values = semibinding.value as object[];
			Assert.AreEqual (3, values.Length);
			ClassWithConstructorParameters value = values [2] as ClassWithConstructorParameters;
			Assert.AreEqual (o2, value);
			Assert.AreEqual (44, value.intValue);
		}
Beispiel #12
0
        public void TestTaggedConstructor()
        {
            IReflectedClass reflected = reflector.Get <ClassWithConstructorParameters> ();

            Assert.AreEqual(2, reflected.ConstructorParameters.Length);

            ConstructorInfo constructor = reflected.Constructor;

            object[] parameters = new object[2];
            parameters [0] = 42;
            parameters [1] = "Zaphod";
            ClassWithConstructorParameters instance = constructor.Invoke(parameters) as ClassWithConstructorParameters;

            Assert.IsNotNull(instance);
            Assert.AreEqual(42, instance.intValue);
            Assert.AreEqual("Zaphod", instance.stringValue);
        }
        public void TestKeyToWithMultipleChainedValues()
        {
            ClassWithConstructorParameters test1 = new ClassWithConstructorParameters(1, "abc");
            ClassWithConstructorParameters test2 = new ClassWithConstructorParameters(2, "def");
            ClassWithConstructorParameters test3 = new ClassWithConstructorParameters(3, "ghi");

            binding.Key <ISimpleInterface> ().To(test1).To(test2).To(test3);
            Assert.That(binding.key == typeof(ISimpleInterface));

            object[] values = binding.value as object[];
            Assert.IsNotNull(values);
            Assert.That(values.Length == 3);
            for (int a = 0; a < values.Length; a++)
            {
                ISimpleInterface value = values [a] as ISimpleInterface;
                Assert.IsNotNull(value);
                Assert.That(value.intValue == a + 1);
            }
        }
        public void TestAddList()
        {
            semibinding.constraint = BindingConstraintType.MANY;

            ClassWithConstructorParameters o  = new ClassWithConstructorParameters(42, "abc");
            ClassWithConstructorParameters o1 = new ClassWithConstructorParameters(43, "def");
            ClassWithConstructorParameters o2 = new ClassWithConstructorParameters(44, "ghi");

            ClassWithConstructorParameters[] list = new ClassWithConstructorParameters[3] {
                o, o1, o2
            };
            semibinding.Add(list);

            object[] values = semibinding.value as object[];
            Assert.AreEqual(3, values.Length);
            ClassWithConstructorParameters value = values [2] as ClassWithConstructorParameters;

            Assert.AreEqual(o2, value);
            Assert.AreEqual(44, value.intValue);
        }
Beispiel #15
0
        public void TestKeyToWithMultipleChainedValues()
        {
            ClassWithConstructorParameters test1 = new ClassWithConstructorParameters (1, "abc");
            ClassWithConstructorParameters test2 = new ClassWithConstructorParameters (2, "def");
            ClassWithConstructorParameters test3 = new ClassWithConstructorParameters (3, "ghi");

            binding.Key<ISimpleInterface> ().To (test1).To (test2).To (test3);
            Assert.That (binding.key == typeof(ISimpleInterface));

            object[] values = binding.value as object[];
            Assert.IsNotNull (values);
            Assert.That (values.Length == 3);
            for(int a = 0; a < values.Length; a++)
            {
                ISimpleInterface value = values [a] as ISimpleInterface;
                Assert.IsNotNull (value);
                Assert.That (value.intValue == a + 1);
            }
        }
Beispiel #16
0
		public void TestRemoveFromMultiSemibinding ()
		{
			semibinding.constraint = BindingConstraintType.MANY;

			ClassWithConstructorParameters o = new ClassWithConstructorParameters (42, "abc");
			semibinding.Add (o);
			ClassWithConstructorParameters o1 = new ClassWithConstructorParameters (43, "def");
			semibinding.Add (o1);
			ClassWithConstructorParameters o2 = new ClassWithConstructorParameters (44, "ghi");
			semibinding.Add (o2);

			object[] before = semibinding.value as object[];
			Assert.AreEqual (3, before.Length);
			ClassWithConstructorParameters beforeValue = before [2] as ClassWithConstructorParameters;
			Assert.AreEqual (o2, beforeValue);
			Assert.AreEqual (44, beforeValue.intValue);

			semibinding.Remove (o1);

			object[] after = semibinding.value as object[];
			Assert.AreEqual (2, after.Length);
			ClassWithConstructorParameters afterValue = after [1] as ClassWithConstructorParameters;
			Assert.AreEqual (o2, afterValue);
			Assert.AreEqual (44, afterValue.intValue);
		}
Beispiel #17
0
        public void TestOneToOneConstrainedBinding()
        {
            ClassWithConstructorParameters test1 = new ClassWithConstructorParameters (1, "abc");
            ClassWithConstructorParameters test2 = new ClassWithConstructorParameters (2, "def");
            ClassWithConstructorParameters test3 = new ClassWithConstructorParameters (3, "ghi");

            binding.valueConstraint = BindingConstraintType.ONE;
            binding.Key<ISimpleInterface> ().To (test1).To (test2).To (test3);
            Assert.That (binding.key == typeof(ISimpleInterface));
            Assert.That (binding.value is ClassWithConstructorParameters);
            Assert.That ((binding.value as ClassWithConstructorParameters).intValue == 3);

            //Clean up
            binding.valueConstraint = BindingConstraintType.MANY;
        }
Beispiel #18
0
		public void TestRemoveList()
		{
			semibinding.constraint = BindingConstraintType.MANY;

			ClassWithConstructorParameters o = new ClassWithConstructorParameters (42, "abc");
			ClassWithConstructorParameters o1 = new ClassWithConstructorParameters (43, "def");
			ClassWithConstructorParameters o2 = new ClassWithConstructorParameters (44, "ghi");
			ClassWithConstructorParameters[] list = new ClassWithConstructorParameters[3]{o, o1, o2};
			semibinding.Add (list);

			object[] before = semibinding.value as object[];
			Assert.AreEqual (3, before.Length);
			ClassWithConstructorParameters beforeValue = before [2] as ClassWithConstructorParameters;
			Assert.AreEqual (o2, beforeValue);
			Assert.AreEqual (44, beforeValue.intValue);

			ClassWithConstructorParameters[] removalList = new ClassWithConstructorParameters[2]{o, o2};
			semibinding.Remove (removalList);

			object[] after = semibinding.value as object[];
			Assert.AreEqual (1, after.Length);
			ClassWithConstructorParameters afterValue = after [0] as ClassWithConstructorParameters;
			Assert.AreEqual (o1, afterValue);
			Assert.AreEqual (43, afterValue.intValue);
		}