CSLA.NET 6.0.0
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
ChildChangedTests.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="ChildChangedTests.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>no summary</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Collections.Generic;
10using System.Text;
11using UnitDriven;
12using Csla.TestHelpers;
13
14#if NUNIT
15using NUnit.Framework;
16using TestClass = NUnit.Framework.TestFixtureAttribute;
17using TestInitialize = NUnit.Framework.SetUpAttribute;
18using TestCleanup = NUnit.Framework.TearDownAttribute;
19using TestMethod = NUnit.Framework.TestAttribute;
20using TestSetup = NUnit.Framework.SetUpAttribute;
21#elif MSTEST
22using Microsoft.VisualStudio.TestTools.UnitTesting;
23#endif
24
26{
27 [TestClass]
28 public class ChildChangedTests
29 {
30 private static TestDIContext _testDIContext;
32
34 public static void ClassInitialize(TestContext testContext)
35 {
36 _testDIContext = TestDIContextFactory.CreateDefaultContext();
37 }
38
39 [TestInitialize]
40 public void Initialize()
41 {
44 }
45
46 [TestCleanup]
47 public void Cleanup()
48 {
50 }
51
52 [TestMethod]
53 public void SingleRoot()
54 {
55 IDataPortal<SingleRoot> dataPortal = _testDIContext.CreateDataPortal<SingleRoot>();
56
57 bool pc = false;
58 bool cc = false;
59
60 var root = dataPortal.Fetch(false);
61 root.PropertyChanged += (o, e) =>
62 {
63 pc = true;
64 };
65 root.ChildChanged += (o, e) =>
66 {
67 cc = true;
68 };
69 root.Name = "abc";
70 Assert.IsTrue(pc, "PropertyChanged should have fired");
71 Assert.IsFalse(cc, "ChildChanged should not have fired");
72 }
73
74 [TestMethod]
75 public void SingleChild()
76 {
77 IDataPortal<SingleChild> dataPortal = _testDIContext.CreateDataPortal<SingleChild>();
78
79 bool pc = false;
80 bool cc = false;
81
82 var root = dataPortal.Fetch(false);
83 root.PropertyChanged += (o, e) =>
84 {
85 pc = true;
86 };
87 root.ChildChanged += (o, e) =>
88 {
89 cc = true;
90 };
91 root.Child.Name = "abc";
92 Assert.IsFalse(pc, "PropertyChanged should not have fired");
93 Assert.IsTrue(cc, "ChildChanged should have fired");
94 }
95
96 [TestMethod]
97 public void GrandChild()
98 {
99 IDataPortal<Grandchild> dataPortal = _testDIContext.CreateDataPortal<Grandchild>();
100
101 bool pc = false;
102 bool cc = false;
103 bool cpc = false;
104 bool ccc = false;
106
107 var root = dataPortal.Fetch();
108 root.PropertyChanged += (o, e) =>
109 {
110 pc = true;
111 };
112 root.ChildChanged += (o, e) =>
113 {
114 cc = true;
115 };
116 root.Child.PropertyChanged += (o, e) =>
117 {
118 cpc = true;
119 };
120 root.Child.ChildChanged += (o, e) =>
121 {
122 ccc = true;
123 cca = e;
124 };
125 root.Child.Child.Name = "abc";
126 Assert.IsFalse(cpc, "C PropertyChanged should not have fired");
127 Assert.IsTrue(ccc, "C ChildChanged should have fired");
128 Assert.IsFalse(pc, "PropertyChanged should not have fired");
129 Assert.IsTrue(cc, "ChildChanged should have fired");
130 Assert.IsTrue(ReferenceEquals(root.Child.Child, cca.ChildObject), "Ref should be equal");
131 }
132
133 [TestMethod]
134 public void SingleList()
135 {
136 IDataPortal<SingleList> listDataPortal = _testDIContext.CreateDataPortal<SingleList>();
137 IDataPortal<SingleRoot> dataPortal = _testDIContext.CreateDataPortal<SingleRoot>();
138
139 int lc = 0;
140 int cc = 0;
142
143 var root = listDataPortal.Fetch(false);
144 root.Add(dataPortal.Fetch(true));
145 System.ComponentModel.PropertyDescriptor lcp = null;
146 root.ListChanged += (o, e) =>
147 {
148 lc++;
149 lcp = e.PropertyDescriptor;
150 };
151 root.ChildChanged += (o, e) =>
152 {
153 cc++;
154 cca = e;
155 };
156 root[0].Name = "abc";
157 Assert.AreEqual(1, lc, "ListChanged should have fired");
158 Assert.IsNotNull(lcp, "PropertyDescriptor should be provided");
159 Assert.AreEqual("Name", lcp.Name, "PropertyDescriptor.Name should be Name");
160 Assert.AreEqual(1, cc, "ChildChanged should have fired");
161 Assert.IsTrue(ReferenceEquals(root[0], cca.ChildObject), "Ref should be equal");
162 }
163
164 [TestMethod]
166 {
167 IDataPortal<SingleList> listDataPortal = _testDIContext.CreateDataPortal<SingleList>();
168 IDataPortal<SingleRoot> dataPortal = _testDIContext.CreateDataPortal<SingleRoot>();
169
170 int lc = 0;
171 int cc = 0;
173
174 var root = listDataPortal.Fetch(false);
175 root.Add(dataPortal.Fetch(true));
176 root = root.Clone();
177
178 System.ComponentModel.PropertyDescriptor lcp = null;
179 root.ListChanged += (o, e) =>
180 {
181 lc++;
182 lcp = e.PropertyDescriptor;
183 };
184 root.ChildChanged += (o, e) =>
185 {
186 cc++;
187 cca = e;
188 };
189 root[0].Name = "abc";
190 Assert.AreEqual(1, lc, "ListChanged should have fired once");
191 Assert.IsNotNull(lcp, "PropertyDescriptor should be provided");
192 Assert.AreEqual("Name", lcp.Name, "PropertyDescriptor.Name should be Name");
193 Assert.AreEqual(1, cc, "ChildChanged should have fired");
194 Assert.IsTrue(ReferenceEquals(root[0], cca.ChildObject), "Ref should be equal");
195 }
196
197 [TestMethod]
198 public void ContainedList()
199 {
200 IDataPortal<ContainsList> listDataPortal = _testDIContext.CreateDataPortal<ContainsList>();
201 IDataPortal<SingleRoot> dataPortal = _testDIContext.CreateDataPortal<SingleRoot>();
202
203 int lc = 0;
204 int rcc = 0;
205 int cc = 0;
207
208 var root = listDataPortal.Fetch();
209 root.List.Add(dataPortal.Fetch(true));
210 root.PropertyChanged += (o, e) =>
211 {
212 Assert.IsTrue(false, "root.PropertyChanged should not fire");
213 };
214 root.ChildChanged += (o, e) =>
215 {
216 rcc++;
217 };
218 System.ComponentModel.PropertyDescriptor lcp = null;
219 root.List.ListChanged += (o, e) =>
220 {
221 lc++;
222 lcp = e.PropertyDescriptor;
223 };
224 root.List.ChildChanged += (o, e) =>
225 {
226 cc++;
227 cca = e;
228 };
229 root.List[0].Name = "abc";
230 Assert.AreEqual(1, lc, "ListChanged should have fired");
231 Assert.IsNotNull(lcp, "PropertyDescriptor should be provided");
232 Assert.AreEqual("Name", lcp.Name, "PropertyDescriptor.Name should be Name");
233 Assert.AreEqual(1, rcc, "root.ChildChanged should have fired");
234 Assert.AreEqual(1, cc, "list.ChildChanged should have fired");
235 Assert.IsTrue(ReferenceEquals(root.List[0], cca.ChildObject), "Ref should be equal");
236 }
237
238 [TestMethod]
240 {
241 IDataPortal<ContainsList> listDataPortal = _testDIContext.CreateDataPortal<ContainsList>();
242 IDataPortal<SingleRoot> dataPortal = _testDIContext.CreateDataPortal<SingleRoot>();
243
244 int lc = 0;
245 int rcc = 0;
246 int cc = 0;
248
249 var root = listDataPortal.Fetch();
250 root.List.Add(dataPortal.Fetch(true));
251 root = root.Clone();
252
253 root.PropertyChanged += (o, e) =>
254 {
255 Assert.IsTrue(false, "root.PropertyChanged should not fire");
256 };
257 root.ChildChanged += (o, e) =>
258 {
259 rcc++;
260 };
261 System.ComponentModel.PropertyDescriptor lcp = null;
262 root.List.ListChanged += (o, e) =>
263 {
264 lc++;
265 lcp = e.PropertyDescriptor;
266 };
267 root.List.ChildChanged += (o, e) =>
268 {
269 cc++;
270 cca = e;
271 };
272 root.List[0].Name = "abc";
273 Assert.AreEqual(1, lc, "ListChanged should have fired once");
274 Assert.IsNotNull(lcp, "PropertyDescriptor should be provided");
275 Assert.AreEqual("Name", lcp.Name, "PropertyDescriptor.Name should be Name");
276 Assert.AreEqual(1, rcc, "root.ChildChanged should have fired");
277 Assert.AreEqual(1, cc, "list.ChildChanged should have fired");
278 Assert.IsTrue(ReferenceEquals(root.List[0], cca.ChildObject), "Ref should be equal");
279 }
280
281 [TestMethod]
282 public void ListOfLists()
283 {
284 IDataPortal<ListContainerList> listContainerDataPortal = _testDIContext.CreateDataPortal<ListContainerList>();
285 IDataPortal<ContainsList> listDataPortal = _testDIContext.CreateDataPortal<ContainsList>();
286 IDataPortal<SingleRoot> dataPortal = _testDIContext.CreateDataPortal<SingleRoot>();
287
288 bool rcc = false;
289 bool ccc = false;
290 bool cc = false;
292
293 var root = listContainerDataPortal.Fetch();
294 var child = listDataPortal.Fetch(true);
295 root.Add(child);
296 child.List.Add(dataPortal.Fetch(true));
297 root.ChildChanged += (o, e) =>
298 {
299 rcc = true;
300 };
301 System.ComponentModel.PropertyDescriptor lcp = null;
302 root.ListChanged += (o, e) =>
303 {
304 Assert.Fail("root.ListChanged should not fire");
305 };
306 child.ChildChanged += (o, e) =>
307 {
308 ccc = true;
309 };
310 child.PropertyChanged += (o, e) =>
311 {
312 Assert.IsTrue(false, "child.PropertyChanged should not fire");
313 };
314 bool lc = false;
315 child.List.ListChanged += (o, e) =>
316 {
317 lc = true;
318 lcp = e.PropertyDescriptor;
319 };
320 child.List.ChildChanged += (o, e) =>
321 {
322 cc = true;
323 cca = e;
324 };
325 child.List[0].Name = "abc";
326 Assert.IsTrue(lc, "ListChanged should have fired");
327 Assert.IsNotNull(lcp, "PropertyDescriptor should be provided");
328 Assert.AreEqual("Name", lcp.Name, "PropertyDescriptor.Name should be Name");
329 Assert.IsTrue(rcc, "root.ChildChanged should have fired");
330 Assert.IsTrue(ccc, "child.ChildChanged should have fired");
331 Assert.IsTrue(cc, "list.ChildChanged should have fired");
332 Assert.IsTrue(ReferenceEquals(child.List[0], cca.ChildObject), "Ref should be equal");
333 }
334 }
335}
Provides consistent context information between the client and server DataPortal objects.
static PropertyChangedModes PropertyChangedMode
Gets or sets a value specifying how CSLA .NET should raise PropertyChanged events.
PropertyChangedModes
Enum representing the way in which CSLA .NET should raise PropertyChanged events.
Contains event data about the changed child object.
static void ClassInitialize(TestContext testContext)
Type to carry context information for DI in unit tests
Interface defining the members of the data portal type.
Definition: IDataPortalT.cs:17
object Fetch(params object[] criteria)
Called by a factory method in a business class to retrieve an object, which is loaded with values fro...