예제 #1
0
		public void Register_HuhTest1 ()
		{
			DependencyPropertyInfo info = new DependencyPropertyInfo ("Custom", typeof (InkPresenter), typeof (int), true);
			DependencyProperty property = info.Property;
			Canvas canvas = new Canvas ();

			canvas.GetValue (property); // This should throw, the property doesn't exist on the canvas.

			Assert.Throws (delegate { canvas.GetValue (InkPresenter.StrokesProperty); }, typeof (Exception)); // And this throws a catastrophic error.
		}
예제 #2
0
		public void Register_FrameworkElement_Height_double ()
		{
			FrameworkElement_Height_double = new DependencyPropertyInfo ("Height", typeof (FrameworkElement), typeof (double), true);
		}
예제 #3
0
		public void Register_FrameworkElement_Height_CustomClass ()
		{
			FrameworkElement_Height_CustomClass = new DependencyPropertyInfo ("Height", typeof (FrameworkElement), typeof (CustomClass), true);
		}
예제 #4
0
		public void Register_CustomCanvasType_Height_CustomClassCtorB ()
		{
			CustomCanvasType_Height_CustomClassCtorB = new DependencyPropertyInfo ("Height", typeof (CustomCanvasType), typeof (CustomClassCtorB), true);
		}
예제 #5
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);
			}
		}
예제 #6
0
		public void Register_CustomCanvasType_Height_void ()
		{
			Assert.Throws (delegate { CustomCanvasType_Height_void = new DependencyPropertyInfo ("Height", typeof (CustomCanvasType), typeof (void), true); }, typeof (NotSupportedException));
		}
예제 #7
0
		public void Register_CustomCanvasType_Height_CustomDelegate ()
		{
			CustomCanvasType the_object = new CustomCanvasType ();
			CustomCanvasType custom_canvas = new CustomCanvasType ();
			Canvas canvas = new Canvas ();
			CustomStruct custom_struct_1 = new CustomStruct (1);
			CustomEnum custom_enum = CustomEnum.EnumValue1;
			CustomDelegate custom_delegate = delegate { };
			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 = null;
			int iterations = 0;
			int changes = 0;

			CustomCanvasType_Height_CustomDelegate = new DependencyPropertyInfo ("Height", typeof (CustomCanvasType), typeof (CustomDelegate), true);
			info = CustomCanvasType_Height_CustomDelegate;

			property = info.Property;

			Assert.AreEqual (null, the_object.GetValue (property), "Default value 1");
			Assert.AreEqual (null, ink.GetValue (property), "Default value 2");

			Assert.Throws (delegate { the_object.SetValue (property, 0); }, typeof (ArgumentException));
			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, new Canvas ()); }, typeof (ArgumentException));

			foreach (object expected_value in new CustomDelegate [] { null, delegate { }, delegate { }, custom_delegate, custom_delegate }) {
				iterations++;

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

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

				previous_expected_value = expected_value;

				Assert.AreEqual (expected_value, 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);
			}
		}
예제 #8
0
		public void Register_CustomClass_Height_CustomClass ()
		{
			CustomClass_Height_CustomClass = new DependencyPropertyInfo ("Height", typeof (CustomClass), typeof (CustomClass), true);
		}
예제 #9
0
		public void Register_Canvas_Height_CustomCanvasType ()
		{
			// Register a custom property with the same name (but not type) as an existing builtin AND another custom property
			Canvas_Height_CustomCanvasType = new DependencyPropertyInfo ("Height", typeof (Canvas), typeof (CustomCanvasType), true);
		}
예제 #10
0
		public void Register_Canvas_Height_double ()
		{
			// Register a custom property with the same name and type as an existing builtin property
			Canvas_Height_double = new DependencyPropertyInfo ("Height", typeof (Canvas), typeof (double), true);
		}
예제 #11
0
		public void Register_Canvas_Custom_CustomCanvasType ()
		{
			Canvas_Custom_CustomCanvasType = new DependencyPropertyInfo ("Custom", typeof (Canvas), typeof (CustomCanvasType), true);
		}
예제 #12
0
		public void Register_Canvas_Custom_Canvas ()
		{
			Canvas canvas = new Canvas ();
			CustomCanvasType custom_canvas = new CustomCanvasType ();
			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 = null;
			int iterations = 0;
			int changes = 0;

			Canvas_Custom_Canvas = new DependencyPropertyInfo ("Custom", typeof (Canvas), typeof (Canvas), true);
			info = Canvas_Custom_Canvas;

			property = info.Property;

			Assert.IsNull (canvas.GetValue (property));
			Assert.IsNull (ink.GetValue (property));

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

			foreach (object expected_value in new object [] { null, new Canvas (), null, canvas, canvas, null, new CustomCanvasType (), custom_canvas, custom_canvas, ink }) {
				iterations++;

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

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

				previous_expected_value = expected_value;

				Assert.AreSame (expected_value, 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);
			}
		}