十二. 其他协助类测试代码
这里就简单写一下对DependencyObjectTypeTest的测试代码:
1: using System;
2: using System.Windows;
3: using NUnit.Framework;
4:
5: namespace TDDDependencyTest.System.Windows
6: {
7: [TestFixture]
8: public class DependencyObjectTypeTest
9: {
10:
11: [Test]
12: void Accessors()
13: {
14: DependencyObjectType t = DependencyObjectType.FromSystemType(typeof(TestDepObj));
15: Assert.AreEqual("TestDepObj",t.Name);
16: Assert.AreEqual(typeof(TestDepObj),t.SystemType);
17: Assert.AreEqual(typeof(DependencyObject),t.BaseType.SystemType);
18: }
19:
20: [Test]
21: void IsInstanceOfType()
22: {
23: DependencyObjectType t = DependencyObjectType.FromSystemType(typeof(TestDepObj));
24: DependencyObjectType t2 = DependencyObjectType.FromSystemType(typeof(TestSubclass));
25: Assert.IsTrue(t.IsInstanceOfType(new TestSubclass()));
26: Assert.IsTrue(t2.IsSubclassOf(t));
27: Assert.IsFalse(t.IsSubclassOf(t2));
28: }
29:
30: [Test]
31: void TestCache()
32: {
33: DependencyObjectType t = DependencyObjectType.FromSystemType(typeof(TestDepObj));
34: DependencyObjectType t2 = DependencyObjectType.FromSystemType(typeof(TestDepObj));
35: Assert.AreSame(t,t2);
36: }
37: }
38: }
十三. 其他协助类的实现代码
LocalValueEnumerator:手动实现一个IEnumerator来方便访问LocalValue
using System.Collections.Generic;
using System.Linq;
4: using System.Text;
using System.Collections;
6:
7: namespace System.Windows
8: {
9: //手动实现一个IEnumerator来方便访问LocalValue
10: struct LocalValueEnumerator : IEnumerator
11: {
private IDictionaryEnumerator propertyEnumerator;
13: private Dictionary<DependencyProperty,object> properties;
14:
15: private int count;
16:
17: internal LocalValueEnumerator(Dictionary<DependencyProperty,255);">object> properties)
18: {
19: this.count = properties.Count;
20: this.properties = properties;
21: this.propertyEnumerator = properties.GetEnumerator();
22: }
23:
24: int Count
25: {
26: get { return count; }
27: }
28:
29: //获取当前LocalValue
30: public LocalValueEntry Current
31: {
32: get
33: {
34: return new LocalValueEntry((DependencyProperty)propertyEnumerator.Key,
35: propertyEnumerator.Value);
36: }
37: }
38:
39: object IEnumerator.Current
40: {
41: get { this.Current; }
@H_213_403@ 42: }
43:
44:
45: bool MoveNext()
46: {
47: return propertyEnumerator.MoveNext();
48: }
49:
50: //重置propertyEnumerator
51: void Reset()
52: {
53: propertyEnumerator.Reset();
54: }
55:
56: static bool operator !=(LocalValueEnumerator obj1,LocalValueEnumerator obj2)
57: {
58: throw new NotImplementedException();
59: }
60:
61: operator ==(LocalValueEnumerator obj1,LocalValueEnumerator obj2)
62: {
63: new NotImplementedException();
64: }
65:
66: override bool Equals(object obj)
67: {
68: new NotImplementedException();
69: }
70:
71: int GetHashCode()
72: {
73: new NotImplementedException();
74: }
75: }
76:
77: //LocalValue实体类
78: struct LocalValueEntry
79: {
80: private DependencyProperty property;
81: object value;
82:
83: internal LocalValueEntry(DependencyProperty property,255);">value)
84: {
85: this.property = property;
86: this.value = value;
87: }
88:
89: public DependencyProperty Property
90: {
91: get { return property; }
92: }
93:
94: object Value
95: {
96: get { value; }
97: }
98:
99: operator !=(LocalValueEntry obj1,LocalValueEntry obj2)
100: {
101: new NotImplementedException();
102: }
103:
104: operator ==(LocalValueEntry obj1,LocalValueEntry obj2)
105: {
106: new NotImplementedException();
107: }
108:
109: object obj)
110: {
111: new NotImplementedException();
112: }
113:
114: int GetHashCode()
115: {
116: new NotImplementedException();
117: }
118: }
@H_301_790@ 119: }
120: