Exemple #1
0
		public void ClearValueTest()
		{
			object strokes, new_strokes, rlv_strokes;
			InkPresenter ink = new InkPresenter();
			
			// check initial value
			strokes = ink.ReadLocalValue(InkPresenter.StrokesProperty);
			Assert.AreEqual(DependencyProperty.UnsetValue, strokes, "initial strokes is not set");
			
			// now try ClearValue
			ink.ClearValue(InkPresenter.StrokesProperty);
			
			// check that ReadLocalValue returns unset
			rlv_strokes = ink.ReadLocalValue(InkPresenter.StrokesProperty);
			Assert.AreEqual(DependencyProperty.UnsetValue, rlv_strokes, "ReadLocalValue after ClearValue is unset");
			
			// check that GetValue returns a StrokeCollection
			new_strokes = ink.GetValue(InkPresenter.StrokesProperty);
			Assert.AreNotEqual(DependencyProperty.UnsetValue, new_strokes, "GetValue after a ClearValue is set");
			Assert.IsNotNull(new_strokes as StrokeCollection, "GetValue after a ClearValue does not return null");
			
			// check that ReadLocalValue still returns unset
			rlv_strokes = ink.ReadLocalValue(InkPresenter.StrokesProperty);
			Assert.AreEqual(DependencyProperty.UnsetValue, rlv_strokes, "ReadLocalValue after a GetValue still returns unset");
			
			// add a stroke
			strokes = new_strokes;
			((StrokeCollection) strokes).Add(new Stroke());
			
			// check that ReadLocalValue still returns unset
			rlv_strokes = ink.ReadLocalValue(InkPresenter.StrokesProperty);
			Assert.AreEqual(DependencyProperty.UnsetValue, rlv_strokes, "ReadLocalValue after adding a stroke still returns unset");
			
			// check that GetValue still returns the same StrokeCollection
			new_strokes = ink.GetValue(InkPresenter.StrokesProperty);
			Assert.AreEqual(strokes, new_strokes, "strokes are the same");
			
			// set the strokes to something
			strokes = ink.Strokes = new StrokeCollection();
			
			// check that ReadLocalValue doesn't return unset anymore
			rlv_strokes = ink.ReadLocalValue(InkPresenter.StrokesProperty);
			Assert.AreEqual(strokes, rlv_strokes, "ReadLocalValue returned the strokes we just set on it");
		}
		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);
			}
		}
		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);
			}
		}
		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);
			}
		}
Exemple #5
0
		public void ResetValueTest()
		{
			InkPresenter ink = new InkPresenter();
			StrokeCollection strokes;
			
			strokes = ink.GetValue(InkPresenter.StrokesProperty) as StrokeCollection;
			
			// does setting the value to null reset the collection?
			strokes.Add(new Stroke());
			ink.Strokes = null;
			strokes = ink.GetValue(InkPresenter.StrokesProperty) as StrokeCollection;
			Assert.AreEqual(0, strokes.Count, "Nulled strokes not empty as expected");
			
			// does clearing the value reset the collection?
			strokes.Add(new Stroke());
			ink.ClearValue(InkPresenter.StrokesProperty);
			strokes = ink.GetValue(InkPresenter.StrokesProperty) as StrokeCollection;
			Assert.AreEqual(0, strokes.Count, "Cleared strokes not empty as expected");
		}