9using System.Collections.Generic;
14using Microsoft.VisualStudio.TestTools.UnitTesting;
17using TestClass = NUnit.Framework.TestFixtureAttribute;
18using TestInitialize = NUnit.Framework.SetUpAttribute;
19using TestCleanup = NUnit.Framework.TearDownAttribute;
20using TestMethod = NUnit.Framework.TestAttribute;
26 public class BasicTests
33 _testDIContext = TestDIContextFactory.CreateDefaultContext();
39 IDataPortal<DataBinding.ParentEntity> dataPortal = _testDIContext.CreateDataPortal<DataBinding.ParentEntity>();
44 p.NotUndoable =
"something";
47 p.NotUndoable =
"something else";
52 Assert.AreEqual(
"something else", p.NotUndoable);
54 Assert.AreEqual(
"data", p.Data);
72 Assert.AreEqual(
"element_1", nvList[1].Value);
91 Assert.AreEqual(
"Executed", obj.
AProperty);
100 Assert.IsNotNull(root);
101 Assert.AreEqual(
"<new>", root.
Data);
103 Assert.AreEqual(
true, root.IsNew);
104 Assert.AreEqual(
false, root.IsDeleted);
105 Assert.AreEqual(
true, root.IsDirty);
131 Assert.IsNotNull(root);
132 Assert.AreEqual(
"<new>", root.
Data);
134 Assert.AreEqual(
true, root.IsNew);
135 Assert.AreEqual(
false, root.IsDeleted);
136 Assert.AreEqual(
true, root.
IsDirty);
145 Root root = NewRoot();
147 Assert.AreEqual(1, root.
Children.Count);
148 Assert.AreEqual(
"1", root.
Children[0].Data);
157 Root root = NewRoot();
160 Assert.AreEqual(0, root.
Children.Count);
169 Root root = NewRoot();
177 Assert.AreEqual(1, root.
Children.Count);
178 Assert.AreEqual(
"1", root.
Children[0].Data);
187 Root root = NewRoot();
201 Root root = NewRoot();
240 Root root = NewRoot();
245 Assert.AreEqual(0, root.
Children.Count,
"Count should be 0");
255 Root root = NewRoot();
265 Assert.AreEqual(3, root.
Children.Count);
274 Root root = NewRoot();
282 Assert.AreEqual(
true, root.
Children.Contains(childC),
"Child should be in collection");
286 Assert.AreEqual(
false, root.
Children.Contains(childC),
"Child should not be in collection");
289 Assert.AreEqual(
false, root.
Children.
ContainsDeleted(childC),
"Deleted child should not be in deleted collection after first applyedit");
291 Assert.AreEqual(
false, root.
Children.
ContainsDeleted(childC),
"Deleted child should not be in deleted collection after ApplyEdit");
293 Assert.AreEqual(0, root.
Children.Count,
"No children should remain");
294 Assert.AreEqual(
false, root.
Children.
ContainsDeleted(childC),
"Deleted child should not be in deleted collection after third applyedit");
303 Assert.AreEqual(
true, r1.Equals(r1),
"objects should be equal on instance compare");
304 Assert.AreEqual(
true, Equals(r1, r1),
"objects should be equal on static compare");
309 Assert.AreEqual(
false, r1.Equals(r2),
"objects should not be equal");
310 Assert.AreEqual(
false, Equals(r1, r2),
"objects should not be equal");
312 Assert.AreEqual(
false, r1.Equals(
null),
"Objects should not be equal");
313 Assert.AreEqual(
false, Equals(r1,
null),
"Objects should not be equal");
314 Assert.AreEqual(
false, Equals(
null, r2),
"Objects should not be equal");
323 Root root = NewRoot();
332 Assert.AreEqual(
true, c1.
Equals(c1),
"objects should be equal");
333 Assert.AreEqual(
true, Equals(c1, c1),
"objects should be equal");
335 Assert.AreEqual(
false, c1.
Equals(c2),
"objects should not be equal");
336 Assert.AreEqual(
false, Equals(c1, c2),
"objects should not be equal");
338 Assert.AreEqual(
false, c1.
Equals(
null),
"objects should not be equal");
339 Assert.AreEqual(
false, Equals(c1,
null),
"objects should not be equal");
340 Assert.AreEqual(
false, Equals(
null, c2),
"objects should not be equal");
342 Assert.AreEqual(
true, root.
Children.Contains(c1),
"Collection should contain c1");
343 Assert.AreEqual(
true, root.
Children.Contains(c2),
"collection should contain c2");
344 Assert.AreEqual(
false, root.
Children.Contains(c3),
"collection should not contain c3");
354 Root root = NewRoot();
365 var deleted = (List<Child>)(root.
Children.GetType().GetProperty(
"DeletedList", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.IgnoreCase).GetValue(copy.
Children,
null));
367 Assert.AreEqual(2, deleted.Count);
368 Assert.AreEqual(
"1", deleted[0].Data);
369 Assert.AreEqual(
"2", deleted[1].Data);
370 Assert.AreEqual(1, root.
Children.Count);
379 Root root = NewRoot();
389 List<Child> deleted = (List<Child>)(root.
Children.GetType().GetProperty(
"DeletedList", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.IgnoreCase).GetValue(copy.
Children,
null));
391 Assert.AreEqual(2, deleted.Count);
392 Assert.AreEqual(
"1", deleted[0].Data);
393 Assert.AreEqual(
"2", deleted[1].Data);
394 Assert.AreEqual(1, root.
Children.Count);
398 deleted = (List<Child>)(root.
Children.GetType().GetProperty(
"DeletedList", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.IgnoreCase).GetValue(root.
Children,
null));
400 Assert.AreEqual(0, deleted.Count);
401 Assert.AreEqual(3, root.
Children.Count);
408 bool changed =
false;
410 obj.ListChanged += (o, e) =>
416 Assert.IsTrue(obj.RaiseListChangedEvents);
417 using (obj.SuppressListChangedEvents)
419 Assert.IsFalse(obj.RaiseListChangedEvents);
423 Assert.IsFalse(changed,
"Should not raise ListChanged event");
424 Assert.IsTrue(obj.RaiseListChangedEvents);
425 Assert.AreEqual(child, obj[0]);
434 private Root NewRoot()
440 private GenRoot NewGenRoot()
443 return dataPortal.
Create(
new GenRoot.Criteria());
447 public class FormSimulator
449 private Core.BusinessBase _obj;
453 this._obj.
PropertyChanged +=
new System.ComponentModel.PropertyChangedEventHandler(obj_IsDirtyChanged);
457 private void obj_IsDirtyChanged(
object sender, System.ComponentModel.PropertyChangedEventArgs e)
462 public class SerializableListener
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.
BusinessBase()
Creates an instance of the type.
void NestedAddAcceptchild()
static void ClassInitialize(TestContext context)
void DeletedListTestWithCancel()
void ClearContextsAfterEachTest()
void TestNotUndoableField()
void SuppressListChangedEventsDoNotRaiseCollectionChanged()
void NestedAddDeleteAcceptChild()
void AddRemoveGrandChild()
remarks>"the non-generic method AreEqual cannot be used with type arguments" - though it is used with...
override bool Equals(object obj)
GrandChildren GrandChildren
override bool IsDirty
start editing
SerializableListener(Core.BusinessBase obj)
void obj_IsDirtyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
ParentEntity()
DO NOT USE in UI - use the factory method instead
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.
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 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.