9using System.Collections.Generic;
14using Microsoft.VisualStudio.TestTools.UnitTesting;
18using TestClass = NUnit.Framework.TestFixtureAttribute;
19using TestInitialize = NUnit.Framework.SetUpAttribute;
20using TestCleanup = NUnit.Framework.TearDownAttribute;
21using TestMethod = NUnit.Framework.TestAttribute;
34 _testDIContext = TestDIContextFactory.CreateDefaultContext();
44 root.Child.Data =
"b";
46 Assert.IsTrue(root.IsDirty,
"Root should be dirty");
47 Assert.IsTrue(root.Child.IsNew,
"Child should be new");
48 Assert.IsTrue(root.Child.IsDirty,
"Child should be dirty");
49 Assert.AreEqual(
"Created", root.Child.Status,
"Child status incorrect after create");
53 Assert.IsFalse(root.IsDirty,
"Root should not be dirty");
54 Assert.IsFalse(root.IsNew,
"Root should not be new");
55 Assert.IsFalse(root.Child.IsDirty,
"Child should not be dirty");
56 Assert.IsFalse(root.Child.IsNew,
"Child should not be new");
57 Assert.AreEqual(
"Inserted", root.Child.Status,
"Child status incorrect after Save");
67 root.Child.DeleteChild();
68 Assert.IsTrue(root.Child.IsDeleted,
"Child should be marked for deletion");
69 Assert.IsTrue(root.Child.IsDirty,
"Child should be dirty");
73 Assert.IsTrue(root.IsDirty,
"Root should be dirty after Save");
74 Assert.IsFalse(root.IsNew,
"Root should not be new");
75 Assert.IsTrue(root.Child.IsDirty,
"Child should be dirty");
76 Assert.IsTrue(root.Child.IsNew,
"Child should be new");
77 Assert.AreEqual(
"Created", root.Child.Status,
"Child status incorrect");
86 Root root = dataPortal.Create();
89 Assert.IsFalse(root.Child.IsNew,
"Child should not be new");
90 Assert.IsFalse(root.Child.IsDirty,
"Child should not be dirty");
91 Assert.AreEqual(
"Fetched", root.Child.Status,
"Child status incorrect after fetch");
93 root.Child.Data =
"b";
95 Assert.IsTrue(root.Child.IsDirty,
"Child should be dirty");
99 Assert.IsFalse(root.IsDirty,
"Root should not be dirty");
100 Assert.IsFalse(root.IsNew,
"Root should not be new");
101 Assert.IsFalse(root.Child.IsDirty,
"Child should not be dirty");
102 Assert.IsFalse(root.Child.IsNew,
"Child should not be new");
103 Assert.AreEqual(
"Updated", root.Child.Status,
"Child status incorrect after Save");
112 Root root = dataPortal.Create();
115 Assert.IsFalse(root.Child.IsNew,
"Child should not be new");
116 Assert.IsFalse(root.Child.IsDirty,
"Child should not be dirty");
117 Assert.AreEqual(
"Fetched", root.Child.Status,
"Child status incorrect after fetch");
119 root.Child.DeleteChild();
120 Assert.IsTrue(root.Child.IsDeleted,
"Child should be marked for deletion");
121 Assert.IsTrue(root.Child.IsDirty,
"Child should be dirty");
125 Assert.IsTrue(root.IsDirty,
"Root should be dirty after Save");
126 Assert.IsFalse(root.IsNew,
"Root should not be new");
127 Assert.IsTrue(root.Child.IsDirty,
"Child should be dirty after Save");
128 Assert.IsTrue(root.Child.IsNew,
"Child should be new after Save");
129 Assert.AreEqual(
"Deleted", root.Child.Status,
"Child status incorrect after Save");
138 var list = root.ChildList;
139 Assert.IsFalse(root.ChildList.IsDirty,
"Child list should not be dirty");
140 Assert.AreEqual(
"Fetched", root.ChildList.Status,
"Child list status incorrect after fetch");
142 list.Add(NewChild());
144 Assert.IsTrue(root.ChildList.IsDirty,
"Child list should be dirty after add");
145 Assert.IsTrue(root.ChildList[0].IsDirty,
"Child should be dirty after add");
146 Assert.IsTrue(root.ChildList[0].IsNew,
"Child should be new after add");
150 Assert.IsFalse(root.IsDirty,
"Root should not be dirty after Save");
151 Assert.IsFalse(root.IsNew,
"Root should not be new");
152 Assert.IsFalse(root.ChildList.IsDirty,
"Child should not be dirty after Save");
153 Assert.AreEqual(
"Updated", root.ChildList.Status,
"Child list status incorrect after Save");
154 Assert.IsFalse(root.ChildList[0].IsDirty,
"Child should not be dirty after Save");
155 Assert.IsFalse(root.ChildList[0].IsNew,
"Child should not be new after Save");
156 Assert.AreEqual(
"Inserted", root.ChildList[0].Status,
"Child status incorrect after Save");
166 var oneChild = root.Child;
167 oneChild.Data =
"random";
169 var list = root.ChildList;
170 Assert.IsFalse(root.ChildList.IsDirty,
"Child list should not be dirty");
171 Assert.AreEqual(
"Fetched", root.ChildList.Status,
"Child list status incorrect after fetch");
175 list.Add(NewChild());
177 Assert.IsTrue(root.ChildList.IsDirty,
"Child list should be dirty after add");
178 Assert.IsTrue(root.ChildList[0].IsDirty,
"Child should be dirty after add");
179 Assert.IsTrue(root.ChildList[0].IsNew,
"Child should be new after add");
183 Assert.IsFalse(root.IsDirty,
"Root should not be dirty after Save");
184 Assert.IsFalse(root.IsNew,
"Root should not be new");
185 Assert.IsFalse(root.ChildList.IsDirty,
"Child should not be dirty after Save");
186 Assert.AreEqual(
"Updated", root.ChildList.Status,
"Child list status incorrect after Save");
187 Assert.IsFalse(root.ChildList[0].IsDirty,
"Child should not be dirty after Save");
188 Assert.IsFalse(root.ChildList[0].IsNew,
"Child should not be new after Save");
189 Assert.AreEqual(
"Inserted", root.ChildList[0].Status,
"Child status incorrect after Save");
191 Assert.AreEqual(
"root", root.ChildList[0].RootData,
"Parent data is not correct after Save in the list");
192 Assert.AreEqual(
"root", root.Child.RootData,
"Parent data is not correct after Save in one child");
195 private Child NewChild()
void FetchAndSaveChildList()
void CreateAndSaveChild()
static void ClassInitialize(TestContext context)
void CreateAndDeleteChild()
void FetchAndSaveChildListVerifyParent()
void FetchAndDeleteChild()
void FetchChild(IChildDataPortal< Child > childDataPortal)
Type to carry context information for DI in unit tests
Interface defining the members of the child data portal type.
object CreateChild(params object[] criteria)
Called by a factory method in a business class to create a new object, which is loaded with default v...
Interface defining the members of the data portal type.
object Fetch(params object[] criteria)
Called by a factory method in a business class to retrieve an object, which is loaded with values fro...
object Create(params object[] criteria)
Called by a factory method in a business class to create a new object, which is loaded with default v...