Move PresentationFramework
[mono.git] / mcs / class / WindowsBase / Test / AttachedProperties.cs
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
3 // code.
4
5 // DependencyObject.cs - NUnit Test Cases for attached properties
6 // 
7 // Iain McCoy (iain@mccoy.id.au)
8 //
9 // (C) iain@mccoy.id.au
10 // 
11
12 using NUnit.Framework;
13 using System;
14 using System.Windows;
15
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
19 {
20
21 class X {
22         public static readonly DependencyProperty AProperty = DependencyProperty.RegisterAttached("A", typeof(int), typeof(X));
23         public static void SetA(DependencyObject obj, int value)
24         {
25                 obj.SetValue(AProperty, value);
26         }
27         public static int GetA(DependencyObject obj)
28         {
29                 return (int)obj.GetValue(AProperty);
30         }
31
32         public static readonly DependencyProperty BProperty = DependencyProperty.RegisterAttached("B", typeof(string), typeof(X));
33         public static void SetB(DependencyObject obj, string value)
34         {
35                 obj.SetValue(BProperty, value);
36         }
37         public static string GetB(DependencyObject obj)
38         {
39                 return (string)obj.GetValue(BProperty);
40         }
41
42 }
43
44 class Y : DependencyObject {
45 }
46         
47 [TestFixture]
48 public class DependencyObjectTest {
49         
50         [SetUp]
51         public void GetReady() {}
52
53         [TearDown]
54         public void Clean() {}
55
56         [Test]
57         public void TestAttachedProperty()
58         {
59                 Y y1 = new Y();
60                 X.SetA(y1, 2);
61                 Assert.AreEqual(2, X.GetA(y1));
62         }
63         
64         [Test]
65         public void Test2AttachedProperties()
66         {
67                 Y y1 = new Y();
68                 Y y2 = new Y();
69                 X.SetA(y1, 2);
70                 X.SetA(y2, 3);
71                 Assert.AreEqual(2, X.GetA(y1));
72                 Assert.AreEqual(3, X.GetA(y2));
73         }
74         
75         [Test]
76         public void TestEnumerationOfAttachedProperties()
77         {
78                 int count = 0;
79                 Y y = new Y();
80                 X.SetA(y, 2);
81                 X.SetB(y, "Hi");
82
83                 LocalValueEnumerator e = y.GetLocalValueEnumerator();
84                 while (e.MoveNext()) {
85                         count++;
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");
90                         else
91                                 Assert.Fail("Wrong sort of property" + e.Current.Property);
92                 }
93
94                 
95                 Assert.AreEqual(2, count);
96         }
97
98         // An nice way to test for exceptions the class under test should 
99         // throw is:
100         /*
101         [Test]
102         [ExpectedException(typeof(ArgumentNullException))]
103         public void OnValid() {
104                 ConcreteCollection myCollection;
105                 myCollection = new ConcreteCollection();
106                 ....
107                 AssertEquals ("#UniqueID", expected, actual);
108                 ....
109                 Fail ("Message");
110         }
111         */
112
113 }
114 }