public void CanClearItems() { var c = new CollectionEx<int>(); c.Add(1); c.Add(2); c.Clear(); Assert.AreEqual(0, c.Count); }
public void CanAddItem() { var c = new CollectionEx<int>(); c.Add(1); c.Add(2); Assert.IsTrue(c[0] == 1); Assert.IsTrue(c[1] == 2); Assert.AreEqual(2, c.Count); }
public void CanReplaceItems() { var c = new CollectionEx<int>(); c.Add(1); c.Add(2); c.Replace(1, 3); Assert.IsTrue(c[0] == 3); Assert.IsTrue(c[1] == 2); Assert.AreEqual(2, c.Count); }
public void BulkUpdate__IndividualOperationsDoNotTriggerVersionChanged__EndingBulkUpdateTriggersVersionChanged() { var c = new CollectionEx<int>(); var eventCalled = false; var lastVersion = c.Version; c.VersionChanged += (s, e) => { eventCalled = true; }; using (var bulkUpdate = c.BeginBulkUpdate()) { c.Add(13); c.AddRange(new int[] { 1, 2, 3, 4, 5 }); c.Move(1, 0); c.Remove(1); c.RemoveAt(0); c.RemoveRange(0, 2); c.Replace(5, 6); c.Reset(new int[] { 11, 12, 13 }); c[0] = 5; Assert.IsFalse(eventCalled); Assert.AreEqual(lastVersion, c.Version); } // event and version should be updated now as bulkUpdate finished Assert.IsTrue(eventCalled); Assert.AreNotEqual(lastVersion, c.Version); }
/// <summary> /// Заполнение данных реальных объектов с БД. /// </summary> public void FillData <T, TReal>(XPCollection xpCollection, CollectionEx <TReal> realCollection) { realCollection.Clear(); foreach (T server in xpCollection) { realCollection.Add((TReal)Activator.CreateInstance(typeof(TReal), server, ItemRealCollection)); } }
public void Move__TriggersVersionChangedEvent() { var c = new CollectionEx<int>(); c.Add(13); c.Add(7); var eventCalled = false; var lastVersion = c.Version; c.VersionChanged += (s, e) => { eventCalled = true; }; c.Move(1, 0); Assert.IsTrue(eventCalled); Assert.AreNotEqual(lastVersion, c.Version); Assert.AreEqual(7, c[0]); Assert.AreEqual(13, c[1]); }
public void VersionChanged__CanCallGetSnapshot() { var c = new CollectionEx<int>(); c.VersionChanged += (s, e) => { var _c = (CollectionEx<int>)s; _c.GetSnapshot(); }; c.Add(1); }
public void Add__TriggersVersionChanged() { var c = new CollectionEx<int>(); var eventCalled = false; var lastVersion = c.Version; c.VersionChanged += (s, e) => { eventCalled = true; }; c.Add(13); Assert.IsTrue(eventCalled); Assert.AreNotEqual(lastVersion, c.Version); }
public void Clear__TriggersVersionChangedEvent() { var c = new CollectionEx<int>(); c.Add(13); c.Add(7); var eventCalled = false; var lastVersion = c.Version; c.VersionChanged += (s, e) => { if (eventCalled) Assert.Fail("VersionChanged should be triggered only once during bulk updates"); eventCalled = true; }; c.Clear(); Assert.IsTrue(eventCalled); Assert.AreNotEqual(lastVersion, c.Version); Assert.AreEqual(0, c.Count); }
public void IndexerGet__DoesNotTriggerVersionChangedEvent() { var c = new CollectionEx<int>(); c.Add(13); var eventCalled = false; var lastVersion = c.Version; c.VersionChanged += (s, e) => { eventCalled = true; }; var x = c[0]; Assert.IsFalse(eventCalled); Assert.AreEqual(lastVersion, c.Version); }
public void IndexerSet__TriggersVersionChangedEvent() { var c = new CollectionEx<int>(); c.Add(13); var eventCalled = false; var lastVersion = c.Version; c.VersionChanged += (s, e) => { eventCalled = true; }; c[0] = 7; Assert.IsTrue(eventCalled); Assert.AreNotEqual(lastVersion, c.Version); Assert.AreEqual(7, c[0]); Assert.AreEqual(1, c.Count); }
public void Replace__TriggersVersionChangedEvent() { var c = new CollectionEx<int>(); c.Add(13); c.Add(7); var eventCalled = false; var lastVersion = c.Version; c.VersionChanged += (s, e) => { eventCalled = true; }; c.Replace(13, 99); Assert.IsTrue(eventCalled); Assert.AreNotEqual(lastVersion, c.Version); Assert.AreEqual(2, c.Count); }
public void IsReadonly_Add_ThrowsException() { var c = new CollectionEx<int>(new int[] { 1, 2 }); c.Add(3); }