10using System.Collections.ObjectModel;
11using System.Collections.Generic;
12using System.Collections;
20using TestClass = NUnit.Framework.TestFixtureAttribute;
21using TestInitialize = NUnit.Framework.SetUpAttribute;
22using TestCleanup = NUnit.Framework.TearDownAttribute;
23using TestMethod = NUnit.Framework.TestAttribute;
24using TestSetup = NUnit.Framework.SetUpAttribute;
26using Microsoft.VisualStudio.TestTools.UnitTesting;
43 _testDIContext = TestDIContextFactory.CreateDefaultContext();
52 var source = dataPortal.
Create();
53 var synced = source.ToSyncList(c => c.Id > 100);
54 Assert.AreEqual(3, synced.Count);
63 var source = dataPortal.
Create();
64 var synced = source.ToSyncList(from r in source
67 Assert.AreEqual(3, synced.Count);
75 var source = dataPortal.
Create();
76 var synced = source.ToSyncList(from r in source
79 Assert.AreEqual(453, synced[0].Id);
80 Assert.AreEqual(123, synced[3].Id);
88 var source = dataPortal.
Create();
89 var synced = (from r in source
91 select r).ToSyncList(source);
92 Assert.AreEqual(3, synced.Count);
101 var source = dataPortal.
Create();
102 var query = from r in source
105 var synced = source.ToSyncList(query);
107 var newItem = childDataPortal.FetchChild(432,
"New item");
110 Assert.AreEqual(4, synced.Count,
"synced should have item");
111 Assert.AreEqual(5, source.Count,
"source should have item");
112 Assert.IsTrue(synced.Contains(newItem),
"synced should contain new item");
113 Assert.IsTrue(source.Contains(newItem),
"source should contain new item");
121 var source = dataPortal.
Create();
122 var query = from r in source
125 var synced = source.ToSyncList(query);
127 var oldItem = synced[0];
130 Assert.AreEqual(2, synced.Count,
"synced count wrong");
131 Assert.AreEqual(3, source.Count,
"source count wrong");
132 Assert.IsFalse(synced.Contains(oldItem),
"synced should not contain item");
133 Assert.IsFalse(source.Contains(oldItem),
"source should not contain item");
141 var source = dataPortal.
Create();
142 var query = from r in source
145 var synced = source.ToSyncList(query);
147 foreach (var item
in synced)
149 Assert.AreEqual(3, count,
"Calculated count wrong (br)");
150 Assert.AreEqual(3, synced.Count,
"Synced count wrong (br)");
151 Assert.AreEqual(4, source.Count,
"source count wrong (br)");
152 Assert.AreEqual(0, synced.Where(_ => _.Id == 12).Count(),
"synced contains 12");
157 foreach (var item
in synced)
160 Assert.AreEqual(3, count,
"Calculated count wrong");
161 Assert.AreEqual(3, synced.Count,
"Synced count wrong");
162 Assert.AreEqual(3, source.Count,
"source count wrong");
163 Assert.AreEqual(0, synced.Where(_ => _.Id == 12).Count(),
"synced contains 12");
169 var source =
new ObservableCollection<string>() {
"a",
"b",
"c" };
170 var query = from r in source
174 Assert.IsNotNull(obj);
175 Assert.AreEqual(1, obj.Count);
176 Assert.AreEqual(
"b", obj[0]);
182 var source =
new ObservableCollection<string>() {
"a",
"b",
"c" };
183 var query = from r in source
188 bool sourceChanged =
false;
189 bool objChanged =
false;
190 source.CollectionChanged += (o, e) =>
192 sourceChanged =
true;
194 obj.CollectionChanged += (o, e) =>
199 Assert.IsTrue(sourceChanged,
"SourceChanged");
200 Assert.IsTrue(objChanged,
"objChanged");
201 Assert.AreEqual(4, source.Count);
202 Assert.AreEqual(2, obj.Count);
203 Assert.AreEqual(
"z", source[3]);
204 Assert.AreEqual(
"z", obj[1]);
206 sourceChanged =
false;
209 Assert.IsTrue(sourceChanged,
"SourceChanged");
210 Assert.IsTrue(objChanged,
"objChanged");
211 Assert.AreEqual(5, source.Count);
212 Assert.AreEqual(3, obj.Count);
213 Assert.AreEqual(
"x", source[4]);
214 Assert.AreEqual(
"x", obj[2]);
220 var source =
new ObservableCollection<string>() {
"a",
"b",
"c" };
221 var query = from r in source
226 bool sourceChanged =
false;
227 bool objChanged =
false;
228 source.CollectionChanged += (o, e) =>
230 sourceChanged =
true;
232 obj.CollectionChanged += (o, e) =>
236 source.Insert(1,
"z");
237 Assert.IsTrue(sourceChanged,
"SourceChanged");
238 Assert.IsTrue(objChanged,
"objChanged");
239 Assert.AreEqual(4, source.Count);
240 Assert.AreEqual(2, obj.Count);
241 Assert.AreEqual(
"z", source[1]);
242 Assert.AreEqual(
"z", obj[1]);
244 sourceChanged =
false;
247 Assert.IsTrue(sourceChanged,
"SourceChanged");
248 Assert.IsTrue(objChanged,
"objChanged");
249 Assert.AreEqual(5, source.Count);
250 Assert.AreEqual(3, obj.Count);
251 Assert.AreEqual(
"x", source[1]);
252 Assert.AreEqual(
"x", obj[1]);
258 var source =
new ObservableCollection<string>() {
"a",
"b",
"c",
"bb" };
259 var query = from r in source
264 bool sourceChanged =
false;
265 bool objChanged =
false;
266 source.CollectionChanged += (o, e) =>
268 sourceChanged =
true;
270 obj.CollectionChanged += (o, e) =>
275 Assert.IsTrue(sourceChanged,
"SourceChanged");
276 Assert.IsTrue(objChanged,
"objChanged");
277 Assert.AreEqual(3, source.Count);
278 Assert.AreEqual(1, obj.Count);
279 Assert.AreEqual(
"c", source[1]);
280 Assert.AreEqual(
"bb", obj[0]);
282 sourceChanged =
false;
285 Assert.IsTrue(sourceChanged,
"SourceChanged");
286 Assert.IsTrue(objChanged,
"objChanged");
287 Assert.AreEqual(2, source.Count);
288 Assert.AreEqual(0, obj.Count);
289 Assert.AreEqual(
"a", source[0]);
290 Assert.AreEqual(
"c", source[1]);
296 var source =
new ObservableCollection<string>() {
"a",
"b",
"c",
"bb" };
297 var query = from r in source
302 bool sourceChanged =
false;
303 bool objChanged =
false;
304 source.CollectionChanged += (o, e) =>
306 sourceChanged =
true;
308 obj.CollectionChanged += (o, e) =>
313 Assert.IsTrue(sourceChanged,
"SourceChanged");
314 Assert.IsTrue(objChanged,
"objChanged");
315 Assert.AreEqual(3, source.Count);
316 Assert.AreEqual(1, obj.Count);
317 Assert.AreEqual(
"c", source[1]);
318 Assert.AreEqual(
"bb", obj[0]);
320 sourceChanged =
false;
323 Assert.IsTrue(sourceChanged,
"SourceChanged");
324 Assert.IsTrue(objChanged,
"objChanged");
325 Assert.AreEqual(2, source.Count);
326 Assert.AreEqual(0, obj.Count);
327 Assert.AreEqual(
"a", source[0]);
328 Assert.AreEqual(
"c", source[1]);
334 var source =
new ObservableCollection<string>() {
"a",
"b",
"c" };
335 var query = from r in source
340 bool sourceChanged =
false;
341 bool objChanged =
false;
342 source.CollectionChanged += (o, e) =>
344 sourceChanged =
true;
346 obj.CollectionChanged += (o, e) =>
351 Assert.IsTrue(sourceChanged,
"SourceChanged");
352 Assert.IsFalse(objChanged,
"objChanged");
353 Assert.AreEqual(3, source.Count);
354 Assert.AreEqual(1, obj.Count);
355 Assert.AreEqual(
"z", source[0]);
358 Assert.IsTrue(sourceChanged,
"SourceChanged");
359 Assert.IsTrue(objChanged,
"objChanged");
360 Assert.AreEqual(3, source.Count);
361 Assert.AreEqual(1, obj.Count);
362 Assert.AreEqual(
"x", source[1]);
363 Assert.AreEqual(
"x", obj[0]);
366 Assert.IsTrue(sourceChanged,
"SourceChanged");
367 Assert.IsTrue(objChanged,
"objChanged");
368 Assert.AreEqual(3, source.Count);
369 Assert.AreEqual(1, obj.Count);
370 Assert.AreEqual(
"r", source[1]);
371 Assert.AreEqual(
"r", obj[0]);
377 var source =
new ObservableCollection<string>() {
"a",
"b",
"c" };
378 var query = from r in source
383 bool sourceChanged =
false;
384 bool objChanged =
false;
385 source.CollectionChanged += (o, e) =>
387 sourceChanged =
true;
389 obj.CollectionChanged += (o, e) =>
394 Assert.IsTrue(sourceChanged,
"SourceChanged");
395 Assert.IsFalse(objChanged,
"objChanged");
396 Assert.AreEqual(3, source.Count);
397 Assert.AreEqual(1, obj.Count);
398 Assert.AreEqual(
"b", obj[0]);
399 Assert.AreEqual(
"b", source[2]);
400 Assert.AreEqual(
"c", source[1]);
406 var source =
new ObservableCollection<string>() {
"a",
"b",
"c" };
407 var query = from r in source
412 bool sourceChanged =
false;
413 bool objChanged =
false;
414 source.CollectionChanged += (o, e) =>
416 sourceChanged =
true;
418 obj.CollectionChanged += (o, e) =>
423 Assert.IsTrue(sourceChanged,
"SourceChanged");
424 Assert.IsTrue(objChanged,
"objChanged");
425 Assert.AreEqual(0, source.Count);
426 Assert.AreEqual(0, obj.Count);
432 var source =
new ObservableCollection<string>() {
"a",
"b",
"c" };
433 var query = from r in source
438 bool sourceChanged =
false;
439 bool objChanged =
false;
440 source.CollectionChanged += (o, e) =>
442 sourceChanged =
true;
444 obj.CollectionChanged += (o, e) =>
449 Assert.IsTrue(sourceChanged,
"SourceChanged");
450 Assert.IsTrue(objChanged,
"objChanged");
451 Assert.AreEqual(2, source.Count);
452 Assert.AreEqual(0, obj.Count);
453 Assert.AreEqual(
"a", source[0]);
454 Assert.AreEqual(
"c", source[1]);
467 return dataPortal.
Create();
473 Add(childDataPortal.FetchChild(123,
"Zebra has stripes"));
474 Add(childDataPortal.FetchChild(2233,
"Software is neat"));
475 Add(childDataPortal.FetchChild(453,
"Run, the sky is falling"));
476 Add(childDataPortal.FetchChild(12,
"What is new?"));
497 private void Child_Fetch(
int id,
string name)
499 using (BypassPropertyChecks)
This is the base class from which most business objects will be derived.
This is the base class from which most business collections or lists will be derived.
Synchronized view over a source list, filtered, sorted and ordered based on a query result.
Maintains metadata about a property.
This is a test class for LinqObservableCollectionTest and is intended to contain all LinqObservableCo...
void Blb2Loc_RemoveOriginal()
static void ClassInitialize(TestContext context)
void Blb2Loc_ResultToSync()
static PropertyInfo< int > IdProperty
static PropertyInfo< string > NameProperty
static TestList NewTestList(IDataPortal< TestList > dataPortal)
Type to carry context information for DI in unit tests
Interface defining the members of the child data portal type.
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...
@ Serializable
Prevents updating or inserting until the transaction is complete.