示例#1
0
 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);
 }
示例#2
0
 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);
 }
示例#3
0
        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));
        }
示例#4
0
        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));
        }
示例#5
0
 public void Insert_RepeatValue()
 {
     var people = new EntitySet<Person>();
     var p = new Person { FirstName = "A", LastName = "B" };
     people.Add(p);
     people.Insert(0, p);
 }
示例#6
0
 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);
 }
示例#7
0
 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);
 }