Exemplo n.º 1
0
        public void Register_CustomCanvasType2_Height_double()
        {
            CustomCanvasType2      the_object    = new CustomCanvasType2();
            CustomCanvasType       custom_canvas = new CustomCanvasType();
            Canvas                 canvas        = new Canvas();
            DependencyProperty     property;
            DependencyPropertyInfo info;

            DependencyPropertyInfo.ChangedInfo changed_info;
            InkPresenter ink = new InkPresenter();              // The only builtin type derived from Canvas
            object       actual_value;
            object       previous_expected_value = (double)0;
            int          iterations = 0;
            int          changes    = 0;

            CustomCanvasType2_Height_double = new DependencyPropertyInfo("Height", typeof(CustomCanvasType2), typeof(double), true);
            info = CustomCanvasType2_Height_double;

            property = info.Property;

            Assert.AreEqual(0.0, (double)the_object.GetValue(property));
            Assert.AreEqual(0.0, (double)ink.GetValue(property));
            Assert.AreEqual(0.0, (double)custom_canvas.GetValue(property));

            Assert.Throws(delegate { the_object.SetValue(property, 1); }, typeof(ArgumentException));
            Assert.Throws(delegate { the_object.SetValue(property, ""); }, typeof(ArgumentException));
            Assert.Throws(delegate { the_object.SetValue(property, new CustomClass()); }, typeof(ArgumentException));
            Assert.Throws(delegate { the_object.SetValue(property, null); }, typeof(ArgumentException));
            Assert.Throws(delegate { the_object.SetValue(property, new Canvas()); }, typeof(ArgumentException));

            //Assert.Throws (delegate { custom_canvas.SetValue (property, 1.1); }, typeof (ArgumentException));

            foreach (object expected_value in new object [] { 1.1 })
            {
                iterations++;

                the_object.SetValue(property, expected_value);
                actual_value = the_object.GetValue(property);

                if ((double)expected_value != (double)previous_expected_value)
                {
                    changes++;
                    changed_info = info.Changes [info.Changes.Count - 1];
                    DependencyPropertyChangedEventArgs args = changed_info.args;
                    Assert.AreEqual((double)args.OldValue, (double)previous_expected_value);
                    Assert.AreEqual((double)args.NewValue, (double)expected_value);
                    Assert.AreSame(changed_info.obj, the_object);
                }

                previous_expected_value = expected_value;

                Assert.AreEqual((double)expected_value, (double)actual_value, "Iteration #{0}", iterations);
                Assert.AreEqual(changes, info.Changes.Count, "Iteration #{0} there should be {1} changes, but there were {2} changes", iterations, changes, info.Changes.Count);
            }
        }
Exemplo n.º 2
0
		public void Register_CustomCanvasType2_Height_double ()
		{
			CustomCanvasType2 the_object = new CustomCanvasType2 ();
			CustomCanvasType custom_canvas = new CustomCanvasType ();
			Canvas canvas = new Canvas ();
			DependencyProperty property;
			DependencyPropertyInfo info;
			DependencyPropertyInfo.ChangedInfo changed_info;
			InkPresenter ink = new InkPresenter (); // The only builtin type derived from Canvas
			object actual_value;
			object previous_expected_value = (double) 0;
			int iterations = 0;
			int changes = 0;

			CustomCanvasType2_Height_double = new DependencyPropertyInfo ("Height", typeof (CustomCanvasType2), typeof (double), true);
			info = CustomCanvasType2_Height_double;

			property = info.Property;

			Assert.AreEqual (0.0, (double) the_object.GetValue (property));
			Assert.AreEqual (0.0, (double) ink.GetValue (property));
			Assert.AreEqual (0.0, (double) custom_canvas.GetValue (property));

			Assert.Throws (delegate { the_object.SetValue (property, 1); }, typeof (ArgumentException));
			Assert.Throws (delegate { the_object.SetValue (property, ""); }, typeof (ArgumentException));
			Assert.Throws (delegate { the_object.SetValue (property, new CustomClass ()); }, typeof (ArgumentException));
			Assert.Throws (delegate { the_object.SetValue (property, null); }, typeof (ArgumentException));
			Assert.Throws (delegate { the_object.SetValue (property, new Canvas ()); }, typeof (ArgumentException));

			//Assert.Throws (delegate { custom_canvas.SetValue (property, 1.1); }, typeof (ArgumentException));

			foreach (object expected_value in new object [] { 1.1 }) {
				iterations++;

				the_object.SetValue (property, expected_value);
				actual_value = the_object.GetValue (property);

				if ((double) expected_value != (double) previous_expected_value) {
					changes++;
					changed_info = info.Changes [info.Changes.Count - 1];
					DependencyPropertyChangedEventArgs args = changed_info.args;
					Assert.AreEqual ((double) args.OldValue, (double) previous_expected_value);
					Assert.AreEqual ((double) args.NewValue, (double) expected_value);
					Assert.AreSame (changed_info.obj, the_object);
				}

				previous_expected_value = expected_value;

				Assert.AreEqual ((double) expected_value, (double) actual_value, "Iteration #{0}", iterations);
				Assert.AreEqual (changes, info.Changes.Count, "Iteration #{0} there should be {1} changes, but there were {2} changes", iterations, changes, info.Changes.Count);
			}
		}