9using System.Collections.Generic;
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();
42 var obj = CreateRootList();
43 Assert.IsNotNull(obj);
45 var obj2 = CreateRoot();
46 Assert.IsNotNull(obj2.Children);
53 var obj = CreateRootList();
54 obj.CollectionChanged += (o, e) =>
58 var child = obj.AddNew();
59 Assert.IsTrue(changed);
60 Assert.AreEqual(child, obj[0]);
67 bool childChanged =
false;
69 var obj = CreateRoot();
70 obj.ChildChanged += (o, e) =>
74 obj.Children.CollectionChanged += (o, e) =>
78 var child = obj.Children.AddNew();
79 Assert.IsTrue(childChanged,
"ChildChanged should be true");
80 Assert.IsTrue(changed,
"Collection changed should be true");
81 Assert.AreEqual(child, obj.Children[0]);
87 var oldSetting = Configuration.ConfigurationManager.AppSettings[
"CslaSerializationFormatter"];
90 Configuration.ConfigurationManager.AppSettings.Set(
"CslaSerializationFormatter",
"MobileFormatter");
92 var rootList = CreateRootList();
94 var child = rootList.AddNew();
96 rootList = rootList.Clone();
100 Assert.IsTrue(rootList.IsDirty);
101 rootList = rootList.Save();
102 Assert.IsFalse(rootList.IsDirty);
106 Configuration.ConfigurationManager.AppSettings.Set(
"CslaSerializationFormatter", oldSetting);
113 var obj = CreateRootList();
118 Assert.IsTrue(obj.IsDirty);
121 Assert.IsFalse(obj.IsDirty);
127 var obj = CreateRootList();
130 Assert.IsTrue(obj.IsDirty);
131 Assert.AreEqual(1, obj.Count);
135 Assert.IsFalse(obj.IsDirty);
136 Assert.AreEqual(0, obj.Count);
142 var obj = CreateRoot();
144 obj.Children.AddNew();
147 Assert.IsTrue(obj.Children.IsDirty);
150 Assert.IsFalse(obj.Children.IsDirty);
156 var obj = CreateRoot();
158 obj.Children.AddNew();
159 Assert.IsTrue(obj.Children.IsDirty);
160 Assert.AreEqual(1, obj.Children.Count);
164 Assert.IsFalse(obj.Children.IsDirty);
165 Assert.AreEqual(0, obj.Children.Count);
172 bool changed =
false;
173 var obj = CreateChildList();
174 obj.CollectionChanged += (o, e) =>
178 var child = CreateChild();
179 obj.Insert(0, child);
180 Assert.IsTrue(changed);
181 Assert.AreEqual(child, obj[0]);
185 [ExpectedException(typeof(InvalidOperationException))]
188 bool changed =
false;
189 var obj = CreateChildList();
190 obj.CollectionChanged += (o, e) =>
194 var nonChild =
new Child();
195 obj.Insert(0, nonChild);
196 Assert.IsTrue(changed);
197 Assert.AreEqual(nonChild, obj[0]);
204 bool changed =
false;
205 var obj = CreateChildList();
206 obj.CollectionChanged += (o, e) =>
210 var child = CreateChild();
212 Assert.IsTrue(obj.RaiseListChangedEvents);
213 using (obj.SuppressListChangedEvents)
215 Assert.IsFalse(obj.RaiseListChangedEvents);
217 obj.Insert(0, child);
219 Assert.IsFalse(changed,
"Should not raise ListChanged event");
220 Assert.IsTrue(obj.RaiseListChangedEvents);
221 Assert.AreEqual(child, obj[0]);
224 private Root CreateRoot()
228 return dataPortal.
Create();
231 private RootList CreateRootList()
235 return dataPortal.
Create();
238 private ChildList CreateChildList()
245 private Child CreateChild()
247 IChildDataPortal<Child> childDataPortal = _testDIContext.CreateChildDataPortal<Child>();
249 return childDataPortal.CreateChild();
void UndoChildCancelAdd()
void SuppressListChangedEventsDoNotRaiseCollectionChanged()
void AcceptChangesAndSaveAfterCloneUsingMobileFormatter()
static void ClassInitialize(TestContext context)
void UndoChildAcceptAdd()
void InsertNonChildFails()
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 Create(params object[] criteria)
Called by a factory method in a business class to create a new object, which is loaded with default v...