0
|
1 using System;
|
|
2
|
|
3 using NUnit.Framework;
|
|
4
|
|
5 using BLToolkit.EditableObjects;
|
|
6 using BLToolkit.TypeBuilder;
|
|
7
|
|
8 namespace EditableObjects
|
|
9 {
|
|
10 [TestFixture]
|
|
11 public class EditableObjectT
|
|
12 {
|
|
13 public abstract class TestObject: EditableObject<TestObject>
|
|
14 {
|
|
15 public abstract int ID { get; set; }
|
|
16 public abstract string Name { get; set; }
|
|
17 public abstract InnerObject Inner { get; set; }
|
|
18
|
|
19 public abstract class InnerObject: EditableObject<InnerObject>
|
|
20 {
|
|
21 public abstract int Some { get; set; }
|
|
22 }
|
|
23 }
|
|
24
|
|
25 [Test]
|
|
26 public void CloneTest()
|
|
27 {
|
|
28 TestObject o = TestObject.CreateInstance();
|
|
29
|
|
30 o.ID = 1;
|
|
31 o.Name = "str";
|
|
32 o.Inner.Some = 2;
|
|
33
|
|
34 TestObject clone = o.Clone();
|
|
35
|
|
36 // Make sure this one is cloned, not copied.
|
|
37 //
|
|
38 o.Inner.Some = 3;
|
|
39
|
|
40 Assert.AreEqual(o.ID, clone.ID);
|
|
41 Assert.AreEqual(o.Name, clone.Name);
|
|
42
|
|
43 Assert.AreNotEqual(o.Inner.Some, clone.Inner.Some);
|
|
44 Assert.IsFalse(o.Equals(clone));
|
|
45
|
|
46 // Now make it the same as original value.
|
|
47 //
|
|
48 clone.Inner = o.Inner.Clone();
|
|
49
|
|
50 Assert.AreEqual(o.Inner.Some, clone.Inner.Some);
|
|
51 }
|
|
52
|
|
53 [Test]
|
|
54 public void IsDirtyTest()
|
|
55 {
|
|
56 TestObject o = TestObject.CreateInstance();
|
|
57
|
|
58 o.ID = 1;
|
|
59 o.Name = "str";
|
|
60 o.Inner.Some = 2;
|
|
61 o.AcceptChanges();
|
|
62
|
|
63 TestObject clone = o.Clone();
|
|
64
|
|
65 Assert.IsFalse(o.IsDirty);
|
|
66 Assert.IsFalse(clone.IsDirty);
|
|
67 }
|
|
68 }
|
|
69 }
|