9using System.Collections.Generic;
12using System.Threading.Tasks;
18using TestClass = NUnit.Framework.TestFixtureAttribute;
19using TestInitialize = NUnit.Framework.SetUpAttribute;
20using TestCleanup = NUnit.Framework.TearDownAttribute;
21using TestMethod = NUnit.Framework.TestAttribute;
23using Microsoft.VisualStudio.TestTools.UnitTesting;
36 _testDIContext = TestDIContextFactory.CreateDefaultContext();
45 var obj = dataPortal.
Create();
47 var cloned = obj.Clone();
52 obj.PropertyChanged += (o, e) => { changed =
true; };
55 merger.MergeGraph(obj, cloned);
56 Assert.AreEqual(cloned.Name, obj.Name);
57 Assert.AreEqual(cloned.IsDirty, obj.IsDirty);
58 Assert.AreEqual(cloned.IsNew, obj.IsNew);
59 Assert.IsFalse(obj.IsNew);
60 Assert.IsFalse(obj.IsDirty);
61 Assert.IsFalse(obj.IsValid);
62 Assert.IsTrue(changed);
71 var obj = dataPortal.
Create();
74 var cloned = obj.Clone();
79 obj.PropertyChanged += (o, e) => { changed =
true; };
82 merger.MergeGraph(obj, cloned);
83 Assert.AreEqual(cloned.Name, obj.Name);
84 Assert.AreEqual(cloned.IsDirty, obj.IsDirty);
85 Assert.AreEqual(cloned.IsNew, obj.IsNew);
86 Assert.IsFalse(obj.IsDirty);
87 Assert.IsFalse(obj.IsValid);
88 Assert.IsTrue(changed);
97 var obj = dataPortal.
Create();
100 var cloned = obj.Clone();
102 cloned.MockUpdated();
105 obj.PropertyChanged += (o, e) => { changed =
true; };
108 merger.MergeGraph(obj, cloned);
109 Assert.AreEqual(cloned.Name, obj.Name);
110 Assert.AreEqual(cloned.IsDirty, obj.IsDirty);
111 Assert.AreEqual(cloned.IsNew, obj.IsNew);
112 Assert.IsFalse(obj.IsDirty);
113 Assert.IsTrue(obj.IsValid);
114 Assert.IsTrue(changed);
120 ApplicationContext applicationContext = _testDIContext.CreateTestApplicationContext();
123 var obj = dataPortal.
Create();
127 var cloned = obj.Clone();
129 cloned.MockDeleted();
132 obj.PropertyChanged += (o, e) => { changed =
true; };
135 merger.MergeGraph(obj, cloned);
136 Assert.AreEqual(cloned.Name, obj.Name);
137 Assert.IsTrue(obj.IsNew,
"obj.IsTrue");
138 Assert.IsFalse(obj.IsDeleted,
"obj.IsDeleted");
139 Assert.AreEqual(cloned.IsDeleted, obj.IsDeleted,
"IsDeleted equal");
140 Assert.AreEqual(cloned.IsDirty, obj.IsDirty);
141 Assert.AreEqual(cloned.IsNew, obj.IsNew);
142 Assert.IsFalse(obj.IsValid);
143 Assert.IsTrue(changed);
149 ApplicationContext applicationContext = _testDIContext.CreateTestApplicationContext();
152 var obj = dataPortal.
Create();
154 obj.AddChild(dataPortal);
155 obj.Child.Name =
"42";
156 var cloned = obj.Clone();
158 cloned.Child.Name =
"43";
159 cloned.MockUpdated();
162 obj.PropertyChanged += (o, e) => { changed =
true; };
165 merger.MergeGraph(obj, cloned);
166 Assert.IsFalse(ReferenceEquals(obj.Child, cloned.Child),
"ref");
167 Assert.AreEqual(cloned.Child.Name, obj.Child.Name,
"name");
168 Assert.AreEqual(cloned.Child.IsDirty, obj.Child.IsDirty,
"isdirty");
169 Assert.AreEqual(cloned.Child.IsNew, obj.Child.IsNew,
"isnew");
170 Assert.IsFalse(obj.Child.IsNew,
"isnew false");
171 Assert.IsFalse(obj.Child.IsDirty,
"isdirty false");
172 Assert.IsTrue(obj.Child.IsValid,
"isvalid true");
173 Assert.IsTrue(changed,
"changed");
179 ApplicationContext applicationContext = _testDIContext.CreateTestApplicationContext();
182 var obj = dataPortal.
Create();
184 obj.AddChild(dataPortal);
185 obj.Child.Name =
"42";
187 var cloned = obj.Clone();
189 cloned.Child.Name =
"2";
190 cloned.MockUpdated();
193 obj.PropertyChanged += (o, e) => { changed =
true; };
196 merger.MergeGraph(obj, cloned);
197 Assert.IsFalse(ReferenceEquals(obj.Child, cloned.Child),
"ref");
198 Assert.AreEqual(cloned.Child.Name, obj.Child.Name,
"name");
199 Assert.AreEqual(cloned.Child.IsDirty, obj.Child.IsDirty,
"isdirty");
200 Assert.AreEqual(cloned.Child.IsNew, obj.Child.IsNew,
"isnew");
201 Assert.IsFalse(obj.Child.IsNew,
"isnew false");
202 Assert.IsFalse(obj.Child.IsDirty,
"isdirty false");
203 Assert.IsFalse(obj.Child.IsValid,
"isvalid false");
204 Assert.IsTrue(changed,
"changed");
210 ApplicationContext applicationContext = _testDIContext.CreateTestApplicationContext();
213 var obj = dataPortal.
Create();
216 var cloned = obj.Clone();
217 cloned.AddChild(dataPortal);
218 cloned.Child.Name =
"42";
219 cloned.MockUpdated();
223 Assert.IsTrue(ReferenceEquals(obj.Child, cloned.Child),
"ref");
224 Assert.IsTrue(ReferenceEquals(obj, obj.Child.Parent));
230 ApplicationContext applicationContext = _testDIContext.CreateTestApplicationContext();
233 var obj = dataPortal.
Create();
235 obj.AddChild(dataPortal);
236 obj.Child.Name =
"42";
239 var cloned = obj.Clone();
241 cloned.Child.Name =
"43";
242 cloned.MockDeleted();
245 obj.PropertyChanged += (o, e) => { changed =
true; };
248 merger.MergeGraph(obj, cloned);
249 Assert.IsFalse(ReferenceEquals(obj.Child, cloned.Child),
"ref");
250 Assert.AreEqual(cloned.Child.Name, obj.Child.Name,
"name");
251 Assert.AreEqual(cloned.Child.IsDirty, obj.Child.IsDirty,
"isdirty");
252 Assert.AreEqual(cloned.Child.IsNew, obj.Child.IsNew,
"isnew");
253 Assert.IsTrue(obj.Child.IsNew,
"isnew true");
254 Assert.IsTrue(obj.Child.IsDirty,
"isdirty true");
255 Assert.IsTrue(obj.Child.IsValid,
"isvalid true");
256 Assert.IsTrue(changed,
"changed");
263 ApplicationContext applicationContext = _testDIContext.CreateTestApplicationContext();
266 var obj = dataPortal.
Create();
267 obj.AddNew().Name =
"existing";
268 obj[0].MockUpdated();
269 obj.AddNew().Name =
"to be deleted";
271 obj.AddNew().Name =
"new";
272 obj.AddNew().Name =
"remove in clone";
273 Assert.AreEqual(3, obj.Count,
"preclone count");
274 var cloned = obj.Clone();
275 Assert.AreEqual(3, cloned.Count,
"postclone count");
276 cloned.Remove(cloned.Where(_ => _.Name ==
"remove in clone").First());
277 Assert.AreEqual(2, cloned.Count,
"postclone count after removed obj");
278 Assert.AreEqual(cloned[0].Name, obj[0].Name,
"postclone [0]");
279 Assert.AreEqual(cloned[1].Name, obj[1].Name,
"postclone [1]");
280 cloned[0].Name =
"existing (cloned)";
281 cloned[1].Name =
"new (cloned)";
282 cloned.AddNew().Name =
"new in clone";
283 cloned.MockUpdated();
286 merger.MergeBusinessListGraph<
FooList,
Foo>(obj, cloned);
287 Assert.AreEqual(cloned.Count, obj.Count,
"count");
288 Assert.AreEqual(3, obj.Count,
"count 3");
289 Assert.AreEqual(cloned[0].Name, obj[0].Name,
"[0]");
290 Assert.AreEqual(cloned[1].Name, obj[1].Name,
"[1]");
291 Assert.AreEqual(cloned[2].Name, obj[2].Name,
"[2]");
292 Assert.AreEqual(cloned.IsDirty, obj.IsDirty);
293 Assert.IsFalse(obj.IsDirty);
299 ApplicationContext applicationContext = _testDIContext.CreateTestApplicationContext();
302 var obj = dataPortal.
Create();
304 var newChild = obj.AddNew();
305 newChild.Name =
"new";
308 Assert.IsTrue(bo.Identity >= 0,
"bo needs identity");
310 var saved = obj.Save();
313 Assert.IsTrue(!ReferenceEquals(obj[0], saved[0]),
"saved object is not original");
321 Assert.AreEqual(obj[0].IsNew, saved[0].IsNew);
323 Assert.IsFalse(ReferenceEquals(original, saved));
324 Assert.IsTrue(ReferenceEquals(original, obj));
326 Assert.IsTrue(ReferenceEquals(original[0], obj[0]));
327 Assert.IsTrue(ReferenceEquals(newChild, obj[0]));
329 obj[0].
Name =
"changed";
330 Assert.AreEqual(original[0].Name, obj[0].Name);
336 ApplicationContext applicationContext = _testDIContext.CreateTestApplicationContext();
339 var obj = dataPortal.
Create();
340 obj.ChildList.AddNew();
341 obj.ChildList[0].Name =
"1";
342 obj.ChildList.AddNew();
343 obj.ChildList[1].Name =
"12";
345 var cloned = obj.Clone();
346 cloned.ChildList[0].Name =
"2";
347 cloned.ChildList.RemoveAt(1);
348 cloned.ChildList.AddNew();
349 cloned.ChildList[1].Name =
"42";
350 cloned.MockUpdated();
353 merger.MergeGraph(obj, cloned);
354 Assert.IsFalse(ReferenceEquals(obj.ChildList, cloned.ChildList),
"ref");
355 Assert.AreEqual(2, obj.ChildList.Count,
"count");
356 Assert.IsFalse(obj.ChildList[0].IsValid,
"[0] isvalid");
357 Assert.IsTrue(obj.ChildList[1].IsValid,
"[1] isvalid");
358 Assert.IsFalse(obj.ChildList.IsValid,
"isvalid");
359 Assert.AreEqual(
"2", obj.ChildList[0].Name,
"[0] name");
360 Assert.AreEqual(
"42", obj.ChildList[1].Name,
"[1] name");
361 Assert.IsFalse(ReferenceEquals(obj.ChildList[0], cloned.ChildList[0]),
"[0] ref");
362 Assert.IsTrue(ReferenceEquals(obj.ChildList[1], cloned.ChildList[1]),
"[1] ref");
363 Assert.IsTrue(ReferenceEquals(obj.ChildList, obj.ChildList[1].Parent),
"parent ref");
Provides consistent context information between the client and server DataPortal objects.
Implements behavior to merge one object graph into a clone of itself (typically post-serialization).
void MergeGraph(IEditableBusinessObject target, IEditableBusinessObject source)
Merges state from source graph into target graph.
void MergeNewChildUpdate()
static void ClassInitialize(TestContext context)
Type to carry context information for DI in unit tests
This is the core interface implemented by all CSLA .NET base classes.
Interface defining the members of the data portal type.
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...