1 // this is a template for making NUnit version 2 tests. Text enclosed in curly
2 // brackets (and the brackets themselves) should be replaced by appropriate
5 // DependencyObject.cs - NUnit Test Cases for attached properties
7 // Iain McCoy (iain@mccoy.id.au)
9 // (C) iain@mccoy.id.au
12 using NUnit.Framework;
16 // all test namespaces start with "MonoTests." Append the Namespace that
17 // contains the class you are testing, e.g. MonoTests.System.Collections
18 namespace MonoTests.System.Windows
22 public static readonly DependencyProperty AProperty = DependencyProperty.RegisterAttached("A", typeof(int), typeof(X));
23 public static void SetA(DependencyObject obj, int value)
25 obj.SetValue(AProperty, value);
27 public static int GetA(DependencyObject obj)
29 return (int)obj.GetValue(AProperty);
32 public static readonly DependencyProperty BProperty = DependencyProperty.RegisterAttached("B", typeof(string), typeof(X));
33 public static void SetB(DependencyObject obj, string value)
35 obj.SetValue(BProperty, value);
37 public static string GetB(DependencyObject obj)
39 return (string)obj.GetValue(BProperty);
44 class Y : DependencyObject {
48 public class DependencyObjectTest {
51 public void GetReady() {}
54 public void Clean() {}
57 public void TestAttachedProperty()
61 Assert.AreEqual(2, X.GetA(y1));
65 public void Test2AttachedProperties()
71 Assert.AreEqual(2, X.GetA(y1));
72 Assert.AreEqual(3, X.GetA(y2));
76 public void TestEnumerationOfAttachedProperties()
83 LocalValueEnumerator e = y.GetLocalValueEnumerator();
84 while (e.MoveNext()) {
86 if (e.Current.Property == X.AProperty)
87 Assert.AreEqual(e.Current.Value, 2);
88 else if (e.Current.Property == X.BProperty)
89 Assert.AreEqual(e.Current.Value, "Hi");
91 Assert.Fail("Wrong sort of property" + e.Current.Property);
95 Assert.AreEqual(2, count);
98 // An nice way to test for exceptions the class under test should
102 [ExpectedException(typeof(ArgumentNullException))]
103 public void OnValid() {
104 ConcreteCollection myCollection;
105 myCollection = new ConcreteCollection();
107 AssertEquals ("#UniqueID", expected, actual);