public void Add_IgnoreRepeats() { var people = new EntitySet<Person>(); var p = new Person { FirstName = "A", LastName = "B" }; people.Add(p); people.Add(p); Assert.AreEqual(1, people.Count); }
public void Contains_KillsDeferred() { var people = new EntitySet<Person>(); var p = new Person { FirstName = "A", LastName = "B" }; people.SetSource(new[]{ p }); Assert.IsTrue(people.IsDeferred); Assert.IsTrue(people.Contains(p)); Assert.IsFalse(people.IsDeferred); }
public void ListChanged_WithSource() { // When is ListChanged emitted? // It's not always when you think it would be. var people = new EntitySet<Person>(); var events = new List<ListChangedEventArgs>(); people.ListChanged += (o, e) => events.Add(e); // This is also true if Enumerable.Empty<Person>() is used here. people.SetSource(new[]{ new Person { FirstName = "(", LastName = ")" }, }); AssertEqual(events); Assert.IsTrue(people.IsDeferred); // *Initial* Add()/AddRange() is ignored. people.Add(new Person { FirstName = "A", LastName = "B" }); people.AddRange(new[]{ new Person { FirstName = "1", LastName = "2" }, new Person { FirstName = "<", LastName = ">" }, }); Assert.IsTrue(people.HasLoadedOrAssignedValues); Assert.IsTrue(people.IsDeferred); AssertEqual(events); events.Clear(); people.Clear(); AssertEqual(events, new ListChangedEventArgs(ListChangedType.ItemDeleted, 0, -1), new ListChangedEventArgs(ListChangedType.ItemDeleted, 0, -1), new ListChangedEventArgs(ListChangedType.ItemDeleted, 0, -1), new ListChangedEventArgs(ListChangedType.ItemDeleted, 0, -1), new ListChangedEventArgs(ListChangedType.Reset, 0, -1)); Assert.IsFalse(people.IsDeferred); // Add()/AddRange() after a Clear has events. events.Clear(); people.Add(new Person { FirstName = "A", LastName = "B" }); people.AddRange(new[]{ new Person { FirstName = "1", LastName = "2" }, new Person { FirstName = "<", LastName = ">" }, }); AssertEqual(events, new ListChangedEventArgs(ListChangedType.ItemAdded, 0, -1), new ListChangedEventArgs(ListChangedType.ItemAdded, 1, -1), new ListChangedEventArgs(ListChangedType.ItemAdded, 2, -1)); events.Clear(); var p = new Person { FirstName = "{", LastName = "}" }; people.Insert(1, p); AssertEqual(events, new ListChangedEventArgs(ListChangedType.ItemAdded, 1, -1)); events.Clear(); Assert.IsTrue(people.Remove(p)); AssertEqual(events, new ListChangedEventArgs(ListChangedType.ItemDeleted, 1, -1)); events.Clear(); people.RemoveAt(0); AssertEqual(events, new ListChangedEventArgs(ListChangedType.ItemDeleted, 0, -1)); events.Clear(); people[0] = p; AssertEqual(events, new ListChangedEventArgs(ListChangedType.ItemDeleted, 0, -1), new ListChangedEventArgs(ListChangedType.ItemAdded, 0, -1)); }
public void ListChanged_NoSource() { // When is ListChanged emitted? // It's not always when you think it would be. // It depends on whether there's a Source present. var people = new EntitySet<Person>(); var events = new List<ListChangedEventArgs> (); people.ListChanged += (o, e) => events.Add(e); people.Add(new Person { FirstName = "A", LastName = "B" }); AssertEqual(events); events.Clear(); people.Clear(); AssertEqual(events, new ListChangedEventArgs(ListChangedType.Reset, 0, -1)); events.Clear(); people.AddRange(new[]{ new Person { FirstName = "1", LastName = "2" }, new Person { FirstName = "<", LastName = ">" }, }); AssertEqual(events); events.Clear(); var p = new Person { FirstName = "{", LastName = "}" }; people.Insert(1, p); AssertEqual(events, new ListChangedEventArgs(ListChangedType.ItemAdded, 1, -1)); events.Clear(); Assert.IsTrue(people.Remove(p)); AssertEqual(events); events.Clear(); people.RemoveAt(0); AssertEqual(events, new ListChangedEventArgs(ListChangedType.ItemDeleted, 0, -1)); events.Clear(); people[0] = p; AssertEqual(events, new ListChangedEventArgs(ListChangedType.ItemDeleted, 0, -1), new ListChangedEventArgs(ListChangedType.ItemAdded, 0, -1)); }
public void Insert_RepeatValue() { var people = new EntitySet<Person>(); var p = new Person { FirstName = "A", LastName = "B" }; people.Add(p); people.Insert(0, p); }
public void IndexOf_KillsDeferred() { var people = new EntitySet<Person>(); var p = new Person { FirstName = "A", LastName = "B" }; people.SetSource(new[]{ p }); Assert.IsTrue(people.IsDeferred); Assert.AreEqual(0, people.IndexOf(p)); Assert.IsFalse(people.IsDeferred); }
public void IList_Add_DuplicateItem() { var people = new EntitySet<Person>(); var p = new Person { FirstName = "A", LastName = "B" }; people.Add(p); System.Collections.IList list = people; list.Add(p); }