9using System.Collections.Generic;
11using System.Threading.Tasks;
15using 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 p.NotUndoable =
"something";
47 p.NotUndoable =
"something else";
52 Assert.AreEqual(
"something else", p.NotUndoable);
54 Assert.AreEqual(
"data", p.Data);
74 Assert.AreEqual(
"element_1", nvList[1].Value);
93 Assert.AreEqual(
"Executed", obj.AProperty);
102 root = CreateGenRootInstance();
103 Assert.IsNotNull(root);
104 Assert.AreEqual(
"<new>", root.
Data);
106 Assert.AreEqual(
true, root.IsNew);
107 Assert.AreEqual(
false, root.IsDeleted);
108 Assert.AreEqual(
true, root.IsDirty);
117 root = CreateGenRootInstance();
123 root = CreateGenRootInstance();
135 root = CreateRootInstance();
136 Assert.IsNotNull(root);
137 Assert.AreEqual(
"<new>", root.
Data);
139 Assert.AreEqual(
true, root.IsNew);
140 Assert.AreEqual(
false, root.IsDeleted);
141 Assert.AreEqual(
true, root.
IsDirty);
149 Root root = CreateRootInstance();
151 Assert.AreEqual(1, root.
Children.Count);
152 Assert.AreEqual(
"1", root.
Children[0].Data);
160 Root root = CreateRootInstance();
163 Assert.AreEqual(0, root.
Children.Count);
171 Root root = CreateRootInstance();
179 Assert.AreEqual(1, root.
Children.Count);
180 Assert.AreEqual(
"1", root.
Children[0].Data);
188 Root root = CreateRootInstance();
201 Root root = CreateRootInstance();
214 Root root = CreateRootInstance();
219 Assert.AreEqual(0, root.
Children.Count,
"Count should be 0");
228 Root root = CreateRootInstance();
238 Assert.AreEqual(3, root.
Children.Count);
246 Root root = CreateRootInstance();
254 Assert.AreEqual(
true, root.
Children.Contains(childC),
"Child should be in collection");
258 Assert.AreEqual(
false, root.
Children.Contains(childC),
"Child should not be in collection");
261 Assert.AreEqual(
false, root.
Children.
ContainsDeleted(childC),
"Deleted child should not be in deleted collection after first applyedit");
263 Assert.AreEqual(
false, root.
Children.
ContainsDeleted(childC),
"Deleted child should not be in deleted collection after ApplyEdit");
265 Assert.AreEqual(0, root.
Children.Count,
"No children should remain");
266 Assert.AreEqual(
false, root.
Children.
ContainsDeleted(childC),
"Deleted child should not be in deleted collection after third applyedit");
274 Root r1 = CreateRootInstance();
276 Assert.AreEqual(
true, r1.Equals(r1),
"objects should be equal on instance compare");
277 Assert.AreEqual(
true, Equals(r1, r1),
"objects should be equal on static compare");
280 Root r2 = CreateRootInstance();
282 Assert.AreEqual(
false, r1.Equals(r2),
"objects should not be equal");
283 Assert.AreEqual(
false, Equals(r1, r2),
"objects should not be equal");
285 Assert.AreEqual(
false, r1.Equals(
null),
"Objects should not be equal");
286 Assert.AreEqual(
false, Equals(r1,
null),
"Objects should not be equal");
287 Assert.AreEqual(
false, Equals(
null, r2),
"Objects should not be equal");
295 Root root = CreateRootInstance();
304 Assert.AreEqual(
true, c1.
Equals(c1),
"objects should be equal");
305 Assert.AreEqual(
true, Equals(c1, c1),
"objects should be equal");
307 Assert.AreEqual(
false, c1.
Equals(c2),
"objects should not be equal");
308 Assert.AreEqual(
false, Equals(c1, c2),
"objects should not be equal");
310 Assert.AreEqual(
false, c1.
Equals(
null),
"objects should not be equal");
311 Assert.AreEqual(
false, Equals(c1,
null),
"objects should not be equal");
312 Assert.AreEqual(
false, Equals(
null, c2),
"objects should not be equal");
314 Assert.AreEqual(
true, root.
Children.Contains(c1),
"Collection should contain c1");
315 Assert.AreEqual(
true, root.
Children.Contains(c2),
"collection should contain c2");
316 Assert.AreEqual(
false, root.
Children.Contains(c3),
"collection should not contain c3");
325 Root root = CreateRootInstance();
338 Assert.AreEqual(2, deleted.Count);
339 Assert.AreEqual(
"1", deleted[0].Data);
340 Assert.AreEqual(
"2", deleted[1].Data);
341 Assert.AreEqual(1, root.
Children.Count);
349 Root root = CreateRootInstance();
361 Assert.AreEqual(2, deleted.Count);
362 Assert.AreEqual(
"1", deleted[0].Data);
363 Assert.AreEqual(
"2", deleted[1].Data);
364 Assert.AreEqual(1, root.
Children.Count);
370 Assert.AreEqual(0, deleted.Count);
371 Assert.AreEqual(3, root.
Children.Count);
380 bool changed =
false;
382 obj.ListChanged += (o, e) =>
388 Assert.IsTrue(obj.RaiseListChangedEvents);
389 using (obj.SuppressListChangedEvents)
391 Assert.IsFalse(obj.RaiseListChangedEvents);
395 Assert.IsFalse(changed,
"Should not raise ListChanged event");
396 Assert.IsTrue(obj.RaiseListChangedEvents);
397 Assert.AreEqual(child, obj[0]);
405 var list = await CreateRootListInstanceAsync();
408 var clone = (
RootList)((ICloneable)list).Clone();
417 var list = await CreateRootListInstanceAsync();
421 var clone = (
RootList)((ICloneable)list).Clone();
430 var obj = await CreateRootInstanceAsync(
new Root.
Criteria(
""));
431 Assert.AreEqual(
"", obj.Data);
436 Assert.AreEqual(
"2", obj.Data);
438 Assert.AreEqual(
"1", obj.Data);
441 Assert.AreEqual(2, obj.GetEditLevel());
442 var clone = obj.Clone();
443 Assert.AreEqual(2, clone.GetEditLevel());
444 Assert.AreEqual(
"2", clone.Data);
446 Assert.AreEqual(
"1", clone.Data);
448 Assert.AreEqual(
"", clone.Data);
457 private Root CreateRootInstance()
463 private async Task<Root> CreateRootInstanceAsync()
466 return await dataPortal.
CreateAsync(
new Root.Criteria());
469 private async Task<Root> CreateRootInstanceAsync(Root.Criteria criteria)
475 private async Task<RootList> CreateRootListInstanceAsync()
477 IDataPortal<RootList> dataPortal = _testDIContext.CreateDataPortal<RootList>();
478 return await dataPortal.CreateAsync();
481 private GenRoot CreateGenRootInstance()
483 IDataPortal<GenRoot> dataPortal = _testDIContext.CreateDataPortal<GenRoot>();
484 return dataPortal.Create(
new GenRootBase.Criteria());
490 return dataPortal.Create();
493 private NameValueListObj GetNameValueListObjInstance()
495 IDataPortal<NameValueListObj> dataPortal = _testDIContext.CreateDataPortal<NameValueListObj>();
496 return dataPortal.Fetch();
503 private readonly Core.BusinessBase _obj;
507 this._obj.
PropertyChanged +=
new System.ComponentModel.PropertyChangedEventHandler(Obj_IsDirtyChanged);
511 private void Obj_IsDirtyChanged(
object sender, System.ComponentModel.PropertyChangedEventArgs e)
518 private readonly Core.BusinessBase _obj;
T Clone()
Creates a clone of the object.
bool ContainsDeleted(C item)
Returns true if the internal deleted list contains the specified child object.
PropertyChangedEventHandler PropertyChanged
Implements a serialization-safe PropertyChanged event.
void NestedAddAcceptchild()
async Task ChildEditLevelDeleteClone()
static void ClassInitialize(TestContext context)
void DeletedListTestWithCancel()
void ClearContextsAfterEachTest()
void TestNotUndoableField()
void SuppressListChangedEventsDoNotRaiseCollectionChanged()
async Task UndoStateStack()
void NestedAddDeleteAcceptChild()
async Task ChildEditLevelClone()
void AddRemoveGrandChild()
override bool Equals(object obj)
GrandChildren GrandChildren
List< Child > GetDeletedList()
override bool IsDirty
start editing
void Obj_IsDirtyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
SerializableListener(Core.BusinessBase obj)
Static dictionary-like class that offers similar functionality to GlobalContext This is used in tests...
static void Reinitialise()
Reinitialise the dictionary, clearing any existing results, ready for the next test
static string GetResult(string key)
Get a result of an operation from the underlying results dictionary
Type to carry context information for DI in unit tests
Interface defining the members of the data portal type.
Task< object > CreateAsync(params object[] criteria)
Starts an asynchronous data portal operation to create a business object.
object Execute(object obj)
Called to execute a Command object on the server.
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...
@ Serializable
Prevents updating or inserting until the transaction is complete.