public void SetItems_NotEmpty() { var coll = new IrcUserModeCollection(); var firstPair = new IrcUserChannelModePair(this._network.GetUser("charles"), IrcChannelUserModes.Normal); var pairs = new[] { new IrcUserChannelModePair(this._network.GetUser("alice"), IrcChannelUserModes.Admin), new IrcUserChannelModePair(this._network.GetUser("bob"), IrcChannelUserModes.Op) }; int firedCount = 0, firedUsersCount = 0; ((INotifyCollectionChanged)coll).CollectionChanged += (s, e) => { firedCount++; }; ((INotifyCollectionChanged)coll.Users).CollectionChanged += (s, e) => { firedUsersCount++; }; coll.Add(firstPair); coll.SetItems(pairs); Assert.AreEqual(pairs.Length, coll.Count); foreach (var pair in pairs) { Assert.IsTrue(coll.Contains(pair)); } Assert.IsFalse(coll.Contains(firstPair)); Assert.AreEqual(2, firedCount); Assert.AreEqual(2, firedUsersCount); }
public void Remove_NotEmpty() { var user1 = this._network.GetUser("alice"); var pair1 = new IrcUserChannelModePair(user1, IrcChannelUserModes.Op); var user2 = this._network.GetUser("bob"); var pair2 = new IrcUserChannelModePair(user2, IrcChannelUserModes.Admin); var coll = new IrcUserModeCollection(); int firedCount = 0, firedUsersCount = 0; ((INotifyCollectionChanged)coll).CollectionChanged += (s, e) => { firedCount++; }; ((INotifyCollectionChanged)coll.Users).CollectionChanged += (s, e) => { firedUsersCount++; }; coll.Add(pair1); coll.Add(pair2); coll.Remove(pair1); Assert.AreEqual(1, coll.Count); Assert.IsTrue(coll.Contains(pair2)); Assert.AreEqual(3, firedCount); Assert.AreEqual(3, firedUsersCount); }
public void Add() { var user = this._network.GetUser("alice"); var pair = new IrcUserChannelModePair(user, IrcChannelUserModes.Op); var coll = new IrcUserModeCollection(); bool fired = false, firedUsers = false; ((INotifyCollectionChanged)coll).CollectionChanged += (s, e) => { fired = true; }; ((INotifyCollectionChanged)coll.Users).CollectionChanged += (s, e) => { firedUsers = true; }; coll.Add(pair); Assert.AreEqual(1, coll.Count); Assert.IsTrue(coll.Contains(pair)); Assert.IsTrue(fired); Assert.IsTrue(firedUsers); }