comparison UnitTests/CS/EditableObjects/NestedObjectTest.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f990fcb411a9
1 using System;
2
3 using NUnit.Framework;
4
5 using BLToolkit.EditableObjects;
6 using BLToolkit.TypeBuilder;
7 using BLToolkit.Reflection;
8
9 namespace EditableObjects
10 {
11 [TestFixture]
12 public class NestedObjectTest
13 {
14 public abstract class AbstractNestedObject : EditableObject
15 {
16 public AbstractNestedObject(InitContext ic)
17 {
18 if (ic.MemberParameters != null && ic.MemberParameters.Length > 0)
19 ID = Convert.ToInt32(ic.MemberParameters[0]);
20 }
21
22 public abstract int ID { get; set; }
23 }
24
25 public class NestedObject : EditableObject
26 {
27 public NestedObject()
28 {
29 }
30
31 public NestedObject(int n)
32 {
33 ID = n;
34 }
35
36 public int ID;
37 }
38
39 public abstract class MasterObject : EditableObject
40 {
41 public abstract int ID { get; set; }
42 public abstract AbstractNestedObject Object1 { get; set; }
43 public abstract NestedObject Object2 { get; set; }
44
45 [Parameter(100)]
46 public abstract AbstractNestedObject Object3 { get; set; }
47 [Parameter(200)]
48 public abstract NestedObject Object4 { get; set; }
49
50 public string ChangedProperty;
51
52 protected override void OnPropertyChanged(string propertyName)
53 {
54 base.OnPropertyChanged(propertyName);
55
56 ChangedProperty = propertyName;
57 }
58 }
59
60 [Test]
61 public void Test()
62 {
63 MasterObject obj = (MasterObject)TypeAccessor.CreateInstance(typeof(MasterObject));
64
65 Assert.IsNotNull(obj.Object1);
66 Assert.IsNotNull(obj.Object2);
67
68 Assert.AreEqual(100, obj.Object3.ID);
69 Assert.AreEqual(200, obj.Object4.ID);
70
71 obj.Object1.ID = 50;
72
73 Assert.AreEqual("Object1.ID", obj.ChangedProperty);
74 }
75 }
76 }