public void Register_CustomCanvasType_Height_CustomInterface() { 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 { }; CustomInterface custom_interface_a = new CustomInterfaceImplA(); CustomInterface custom_interface_b = new CustomInterfaceImplB(); 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_CustomInterface = new DependencyPropertyInfo("Height", typeof(CustomCanvasType), typeof(CustomInterface), true); info = CustomCanvasType_Height_CustomInterface; 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)); Assert.Throws(delegate { the_object.SetValue(property, custom_enum); }, typeof(ArgumentException)); foreach (object expected_value in new object [] { null, custom_interface_a, null, custom_interface_b, custom_interface_b, null }) { 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_CustomCanvasType_Height_CustomInterface () { 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 { }; CustomInterface custom_interface_a = new CustomInterfaceImplA (); CustomInterface custom_interface_b = new CustomInterfaceImplB (); 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_CustomInterface = new DependencyPropertyInfo ("Height", typeof (CustomCanvasType), typeof (CustomInterface), true); info = CustomCanvasType_Height_CustomInterface; 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)); Assert.Throws (delegate { the_object.SetValue (property, custom_enum); }, typeof (ArgumentException)); foreach (object expected_value in new object [] { null, custom_interface_a, null, custom_interface_b, custom_interface_b, null }) { 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); } }