Index: Core/Common/src/Core.Common.Gui/Forms/ViewManager/ViewList.cs =================================================================== diff -u -r42ca97fdb85a553c6aac3bfdfe57c7be4af90821 -rd53a27a49d8db860ff0894554dab040a1b6204a5 --- Core/Common/src/Core.Common.Gui/Forms/ViewManager/ViewList.cs (.../ViewList.cs) (revision 42ca97fdb85a553c6aac3bfdfe57c7be4af90821) +++ Core/Common/src/Core.Common.Gui/Forms/ViewManager/ViewList.cs (.../ViewList.cs) (revision d53a27a49d8db860ff0894554dab040a1b6204a5) @@ -165,7 +165,7 @@ clearing = false; ActiveView = null; - FireCollectionChangedEvent(NotifyCollectionChangeAction.Reset, -1, null); + FireCollectionChangedEvent(NotifyCollectionChangeEventArgs.CreateCollectionResetArgs()); } public void Clear(IView viewToKeep) @@ -353,7 +353,7 @@ views.Remove(view); - FireCollectionChangedEvent(NotifyCollectionChangeAction.Remove, oldIndex, view); + FireCollectionChangedEvent(NotifyCollectionChangeEventArgs.CreateCollectionRemoveArgs(view, oldIndex)); // remove from docking manager dockingManager.Remove(view, removeTabFromDockingManager); @@ -410,11 +410,11 @@ } } - private void FireCollectionChangedEvent(NotifyCollectionChangeAction notifyCollectionChangeAction, int index, IView item) + private void FireCollectionChangedEvent(NotifyCollectionChangeEventArgs eventArgs) { if (CollectionChanged != null) { - CollectionChanged(this, new NotifyCollectionChangeEventArgs(notifyCollectionChangeAction, item, index, -1)); + CollectionChanged(this, eventArgs); } } @@ -436,7 +436,7 @@ dockingManager.Add(view, viewLocation); - FireCollectionChangedEvent(NotifyCollectionChangeAction.Add, index, view); + FireCollectionChangedEvent(NotifyCollectionChangeEventArgs.CreateCollectionAddArgs(view, index)); ActiveView = view; } Index: Core/Common/src/Core.Common.Utils/Events/EventArgs.cs =================================================================== diff -u -rfa33f7c078c5d17f92f6a519f147a0a371593944 -rd53a27a49d8db860ff0894554dab040a1b6204a5 --- Core/Common/src/Core.Common.Utils/Events/EventArgs.cs (.../EventArgs.cs) (revision fa33f7c078c5d17f92f6a519f147a0a371593944) +++ Core/Common/src/Core.Common.Utils/Events/EventArgs.cs (.../EventArgs.cs) (revision d53a27a49d8db860ff0894554dab040a1b6204a5) @@ -2,13 +2,24 @@ namespace Core.Common.Utils.Events { + /// + /// Event arguments with a particular value. + /// + /// Type of the attached class instance. public class EventArgs : EventArgs { + /// + /// Initializes a new instance of the class. + /// + /// The attached instance. public EventArgs(T t) { Value = t; } - public T Value { get; set; } + /// + /// Gets or sets the attached instance. + /// + public T Value { get; private set; } } } \ No newline at end of file Index: Core/Common/src/Core.Common.Utils/Events/INotifyCollectionChanged.cs =================================================================== diff -u -rfa33f7c078c5d17f92f6a519f147a0a371593944 -rd53a27a49d8db860ff0894554dab040a1b6204a5 --- Core/Common/src/Core.Common.Utils/Events/INotifyCollectionChanged.cs (.../INotifyCollectionChanged.cs) (revision fa33f7c078c5d17f92f6a519f147a0a371593944) +++ Core/Common/src/Core.Common.Utils/Events/INotifyCollectionChanged.cs (.../INotifyCollectionChanged.cs) (revision d53a27a49d8db860ff0894554dab040a1b6204a5) @@ -1,7 +1,14 @@ namespace Core.Common.Utils.Events { + /// + /// Interface for defining collections that fire an event when a collection has changed. + /// public interface INotifyCollectionChanged { + /// + /// Occurs when the collection has been changed (such as an element has been added, + /// removed, inserted, replaced or the collection has completely been changed). + /// event NotifyCollectionChangedEventHandler CollectionChanged; } } \ No newline at end of file Index: Core/Common/src/Core.Common.Utils/Events/NotifyCollectionChangeAction.cs =================================================================== diff -u -rfa33f7c078c5d17f92f6a519f147a0a371593944 -rd53a27a49d8db860ff0894554dab040a1b6204a5 --- Core/Common/src/Core.Common.Utils/Events/NotifyCollectionChangeAction.cs (.../NotifyCollectionChangeAction.cs) (revision fa33f7c078c5d17f92f6a519f147a0a371593944) +++ Core/Common/src/Core.Common.Utils/Events/NotifyCollectionChangeAction.cs (.../NotifyCollectionChangeAction.cs) (revision d53a27a49d8db860ff0894554dab040a1b6204a5) @@ -1,13 +1,25 @@ namespace Core.Common.Utils.Events { /// - /// Action for changes to a collection such as add, remove. + /// Marks the type of action that has been performed on a collection. /// public enum NotifyCollectionChangeAction { + /// + /// An element has been added (or inserted at a specific index). + /// Add, + /// + /// An element has been removed. + /// Remove, + /// + /// An element has been replaced by another. + /// Replace, + /// + /// The collection as a whole as changed. + /// Reset } } \ No newline at end of file Index: Core/Common/src/Core.Common.Utils/Events/NotifyCollectionChangeEventArgs.cs =================================================================== diff -u -rfa33f7c078c5d17f92f6a519f147a0a371593944 -rd53a27a49d8db860ff0894554dab040a1b6204a5 --- Core/Common/src/Core.Common.Utils/Events/NotifyCollectionChangeEventArgs.cs (.../NotifyCollectionChangeEventArgs.cs) (revision fa33f7c078c5d17f92f6a519f147a0a371593944) +++ Core/Common/src/Core.Common.Utils/Events/NotifyCollectionChangeEventArgs.cs (.../NotifyCollectionChangeEventArgs.cs) (revision d53a27a49d8db860ff0894554dab040a1b6204a5) @@ -3,45 +3,101 @@ namespace Core.Common.Utils.Events { /// - /// EventArgs for a collection that include the item and the action. - /// - /// Note: for performance reasons we use fields here instead of properties. + /// for collection changes. /// public class NotifyCollectionChangeEventArgs : CancelEventArgs { /// - /// Indicate what operation took place such as add, remove etc... + /// Initializes a new instance of the class. /// - public NotifyCollectionChangeAction Action; + /// The action that has been reformed on the collection. + /// The item affected by the action. + /// The current index of . + /// The previous index of . + public NotifyCollectionChangeEventArgs(NotifyCollectionChangeAction action, object item, int index, int oldIndex) + { + Action = action; + Item = item; + OldItem = null; + Index = index; + OldIndex = oldIndex; + } /// - /// When inserting, this is the position where the item is inserted. + /// Initializes a new instance of the class. /// - public int Index; - - /// - /// Previous index (if changed). TODO: remove it. This is the index at which the insert was intent - /// - public int OldIndex; - - public NotifyCollectionChangeEventArgs(NotifyCollectionChangeAction action, object item, int index, int oldIndex) + /// The action that has been reformed on the collection. + /// The item affected by the action. + /// The current index of . + /// The previous index of . + /// The previous value of the effected element that is now replaced with . + public NotifyCollectionChangeEventArgs(NotifyCollectionChangeAction action, object item, int index, int oldIndex, object oldItem) { Action = action; Item = item; + OldItem = oldItem; Index = index; OldIndex = oldIndex; } - public NotifyCollectionChangeEventArgs() {} + /// + /// The operation took place. + /// + public NotifyCollectionChangeAction Action { get; private set; } /// - /// The item added, removed or replaced. On replace the new item is given + /// The location where the element now resides. /// - public virtual object Item { get; set; } + public int Index { get; private set; } /// - /// Item that is replaced. (only filled out on replace) + /// The location where the element used to reside. /// - public virtual object OldItem { get; set; } + public int OldIndex { get; private set; } + + /// + /// The value of the element for which the event was generated. + /// + public object Item { get; private set; } + + /// + /// The value of the element before it was replaced. + /// + public object OldItem { get; private set; } + + #region Factory methods + + /// + /// Creates and initializes an new instance of the + /// class for when the collection has completely been reset. + /// + public static NotifyCollectionChangeEventArgs CreateCollectionResetArgs() + { + return new NotifyCollectionChangeEventArgs(NotifyCollectionChangeAction.Reset, null, -1, -1); + } + + /// + /// Creates and initializes an new instance of the + /// class for when an element has been added to the collection. + /// + /// The element that has been added to the collection. + /// The index where has been added. + public static NotifyCollectionChangeEventArgs CreateCollectionAddArgs(object addedElement, int currentIndex) + { + return new NotifyCollectionChangeEventArgs(NotifyCollectionChangeAction.Add, addedElement, currentIndex, -1); + } + + /// + /// Creates and initializes an new instance of the + /// class for when an element has been removed from the collection. + /// + /// The element that has been removed from the collection. + /// The index where was removed. + public static NotifyCollectionChangeEventArgs CreateCollectionRemoveArgs(object removedElement, int originalIndex) + { + return new NotifyCollectionChangeEventArgs(NotifyCollectionChangeAction.Remove, removedElement, originalIndex, -1); + } + + #endregion } } \ No newline at end of file Index: Core/Common/src/Core.Common.Utils/Events/NotifyCollectionChangedEventHandler.cs =================================================================== diff -u -rfa33f7c078c5d17f92f6a519f147a0a371593944 -rd53a27a49d8db860ff0894554dab040a1b6204a5 --- Core/Common/src/Core.Common.Utils/Events/NotifyCollectionChangedEventHandler.cs (.../NotifyCollectionChangedEventHandler.cs) (revision fa33f7c078c5d17f92f6a519f147a0a371593944) +++ Core/Common/src/Core.Common.Utils/Events/NotifyCollectionChangedEventHandler.cs (.../NotifyCollectionChangedEventHandler.cs) (revision d53a27a49d8db860ff0894554dab040a1b6204a5) @@ -1,4 +1,9 @@ namespace Core.Common.Utils.Events { + /// + /// Defines the event delegate for . + /// + /// The sender of the event. + /// The instance containing the event data. public delegate void NotifyCollectionChangedEventHandler(object sender, NotifyCollectionChangeEventArgs e); } \ No newline at end of file Index: Core/Common/test/Core.Common.Controls.TreeView.Test/TreeViewControllerTest.cs =================================================================== diff -u -rd7da4fd9051547085f0cbbec790eda9cb8ca7f14 -rd53a27a49d8db860ff0894554dab040a1b6204a5 --- Core/Common/test/Core.Common.Controls.TreeView.Test/TreeViewControllerTest.cs (.../TreeViewControllerTest.cs) (revision d7da4fd9051547085f0cbbec790eda9cb8ca7f14) +++ Core/Common/test/Core.Common.Controls.TreeView.Test/TreeViewControllerTest.cs (.../TreeViewControllerTest.cs) (revision d53a27a49d8db860ff0894554dab040a1b6204a5) @@ -296,7 +296,7 @@ // Collection changed is bubbled to nodePresenter => expect 1 call during parent.Children.Remove(child2); // not that in some cases Full refresh can be called - Expect.Call(() => childNodePresenter.OnCollectionChanged(parent, new NotifyCollectionChangeEventArgs())).IgnoreArguments().Repeat.Any(); + Expect.Call(() => childNodePresenter.OnCollectionChanged(parent, new NotifyCollectionChangeEventArgs(NotifyCollectionChangeAction.Add, null, 0, 0))).IgnoreArguments().Repeat.Any(); mocks.ReplayAll(); Index: Core/Common/test/Core.Common.Test/Gui/ViewListTest.cs =================================================================== diff -u -rb824d24e9f2698cfd0ba7f253ffd037266c16dc4 -rd53a27a49d8db860ff0894554dab040a1b6204a5 --- Core/Common/test/Core.Common.Test/Gui/ViewListTest.cs (.../ViewListTest.cs) (revision b824d24e9f2698cfd0ba7f253ffd037266c16dc4) +++ Core/Common/test/Core.Common.Test/Gui/ViewListTest.cs (.../ViewListTest.cs) (revision d53a27a49d8db860ff0894554dab040a1b6204a5) @@ -10,6 +10,8 @@ using NUnit.Framework; +using Rhino.Mocks; + namespace Core.Common.Test.Gui { [TestFixture] @@ -27,6 +29,8 @@ Text = @"text" }; + toolWindowViewManager.Add(view); + var senders = new List(); var actions = new List(); var items = new List(); @@ -39,28 +43,23 @@ indexes.Add(e.Index); }; - toolWindowViewManager.Add(view); toolWindowViewManager.Remove(view); // asserts Assert.AreEqual(new[] { - toolWindowViewManager, toolWindowViewManager }, senders); Assert.AreEqual(new[] { - NotifyCollectionChangeAction.Add, NotifyCollectionChangeAction.Remove }, actions); Assert.AreEqual(new[] { - view, view }, items); Assert.AreEqual(new[] { - 0, 0 }, indexes); } @@ -213,5 +212,328 @@ Assert.AreEqual(data, view.Data); Assert.AreEqual(typeof(TestViewDerivative), view.GetType()); } + + [Test] + public void Clear_WithoutViews_FireResetCollectionChanged() + { + // Setup + using (var viewList = new ViewList(new TestDockingManager(), ViewLocation.Document)) + { + viewList.CollectionChanged += (sender, args) => + { + Assert.AreSame(viewList, sender); + Assert.AreEqual(NotifyCollectionChangeAction.Reset, args.Action); + Assert.AreEqual(-1, args.Index); + Assert.AreEqual(-1, args.OldIndex); + Assert.IsNull(args.Item); + Assert.IsNull(args.OldItem); + Assert.IsFalse(args.Cancel); + }; + + // Call + viewList.Clear(); + + // Assert + Assert.IsNull(viewList.ActiveView); + CollectionAssert.IsEmpty(viewList); + } + } + + [Test] + public void Clear_WithViews_FireResetCollectionChangedAndRemoveCollectionChangePerView() + { + // Setup + var mocks = new MockRepository(); + var view = mocks.Stub(); + mocks.ReplayAll(); + + using (var viewList = new ViewList(new TestDockingManager(), ViewLocation.Document)) + { + viewList.Add(view); + + viewList.CollectionChanged += (sender, args) => + { + Assert.AreSame(viewList, sender); + + if (args.Action == NotifyCollectionChangeAction.Remove) + { + Assert.AreEqual(0, args.Index); + Assert.AreEqual(-1, args.OldIndex); + Assert.AreSame(view, args.Item); + Assert.IsNull(args.OldItem); + Assert.IsFalse(args.Cancel); + } + else if (args.Action == NotifyCollectionChangeAction.Reset) + { + Assert.AreEqual(-1, args.Index); + Assert.AreEqual(-1, args.OldIndex); + Assert.IsNull(args.Item); + Assert.IsNull(args.OldItem); + Assert.IsFalse(args.Cancel); + } + else + { + Assert.Fail("Unexpected collection change event."); + } + }; + + // Call + viewList.Clear(); + + // Assert + Assert.IsNull(viewList.ActiveView); + CollectionAssert.IsEmpty(viewList); + } + mocks.VerifyAll(); + } + + [Test] + public void Clear_WithViewsAndKeepingOne_FireResetCollectionChangedAndRemoveCollectionChangePerRemovedView() + { + // Setup + var mocks = new MockRepository(); + var view = mocks.Stub(); + var viewToKeep = mocks.Stub(); + mocks.ReplayAll(); + + using (var viewList = new ViewList(new TestDockingManager(), ViewLocation.Document)) + { + viewList.Add(viewToKeep); + viewList.Add(view); + + viewList.CollectionChanged += (sender, args) => + { + Assert.AreSame(viewList, sender); + + if (args.Action == NotifyCollectionChangeAction.Remove) + { + Assert.AreEqual(1, args.Index); + Assert.AreEqual(-1, args.OldIndex); + Assert.AreSame(view, args.Item); + Assert.IsNull(args.OldItem); + Assert.IsFalse(args.Cancel); + } + else if (args.Action == NotifyCollectionChangeAction.Reset) + { + Assert.AreEqual(-1, args.Index); + Assert.AreEqual(-1, args.OldIndex); + Assert.IsNull(args.Item); + Assert.IsNull(args.OldItem); + Assert.IsFalse(args.Cancel); + } + else + { + Assert.Fail("Unexpected collection change event."); + } + }; + + // Call + viewList.Clear(viewToKeep); + + // Assert + Assert.AreSame(viewToKeep, viewList.ActiveView); + Assert.AreEqual(1, viewList.Count); + } + mocks.VerifyAll(); + } + + [Test] + [TestCase(0)] + [TestCase(2)] + public void Add_ViewWithoutViewLocation_FireAddCollectionChange(int alreadyAddedViews) + { + // Setup + var mocks = new MockRepository(); + var view = mocks.Stub(); + var viewsToPreadd = new[] + { + mocks.Stub(), + mocks.Stub() + }; + mocks.ReplayAll(); + + using (var viewList = new ViewList(new TestDockingManager(), ViewLocation.Document)) + { + for (int i = 0; i < alreadyAddedViews; i++) + { + viewList.Add(viewsToPreadd[i]); + } + + viewList.CollectionChanged += (sender, args) => + { + Assert.AreSame(viewList, sender); + Assert.AreEqual(NotifyCollectionChangeAction.Add, args.Action); + Assert.AreEqual(alreadyAddedViews, args.Index); + Assert.AreEqual(-1, args.OldIndex); + Assert.AreSame(view, args.Item); + Assert.IsNull(args.OldItem); + Assert.IsFalse(args.Cancel); + }; + // Call + viewList.Add(view); + + // Assert + Assert.AreEqual(alreadyAddedViews+1, viewList.Count); + Assert.AreSame(view, viewList.ActiveView); + } + + mocks.VerifyAll(); + } + + [Test] + [TestCase(0)] + [TestCase(2)] + public void Add_ViewWithViewLocation_FireAddCollectionChange(int alreadyAddedViews) + { + // Setup + var mocks = new MockRepository(); + var view = mocks.Stub(); + var viewsToPreadd = new[] + { + mocks.Stub(), + mocks.Stub() + }; + mocks.ReplayAll(); + + using (var viewList = new ViewList(new TestDockingManager(), ViewLocation.Bottom)) + { + for (int i = 0; i < alreadyAddedViews; i++) + { + viewList.Add(viewsToPreadd[i]); + } + + viewList.CollectionChanged += (sender, args) => + { + Assert.AreSame(viewList, sender); + Assert.AreEqual(NotifyCollectionChangeAction.Add, args.Action); + Assert.AreEqual(alreadyAddedViews, args.Index); + Assert.AreEqual(-1, args.OldIndex); + Assert.AreSame(view, args.Item); + Assert.IsNull(args.OldItem); + Assert.IsFalse(args.Cancel); + }; + // Call + viewList.Add(view, ViewLocation.Document); + + // Assert + Assert.AreEqual(alreadyAddedViews + 1, viewList.Count); + Assert.AreSame(view, viewList.ActiveView); + } + + mocks.VerifyAll(); + } + + [Test] + [TestCase(0)] + [TestCase(2)] + public void Insert_ViewWithoutViewLocation_FireAddCollectionChange(int alreadyAddedViews) + { + // Setup + var mocks = new MockRepository(); + var view = mocks.Stub(); + var viewsToPreadd = new[] + { + mocks.Stub(), + mocks.Stub() + }; + mocks.ReplayAll(); + + using (var viewList = new ViewList(new TestDockingManager(), ViewLocation.Document)) + { + for (int i = 0; i < alreadyAddedViews; i++) + { + viewList.Add(viewsToPreadd[i]); + } + + viewList.CollectionChanged += (sender, args) => + { + Assert.AreSame(viewList, sender); + Assert.AreEqual(NotifyCollectionChangeAction.Add, args.Action); + Assert.AreEqual(0, args.Index); + Assert.AreEqual(-1, args.OldIndex); + Assert.AreSame(view, args.Item); + Assert.IsNull(args.OldItem); + Assert.IsFalse(args.Cancel); + }; + // Call + viewList.Insert(0, view); + + // Assert + Assert.AreEqual(alreadyAddedViews + 1, viewList.Count); + Assert.AreSame(view, viewList.ActiveView); + } + + mocks.VerifyAll(); + } + + [Test] + public void Remove_RemovingAddedView_FireRemoveCollectionChange() + { + // Setup + var mocks = new MockRepository(); + var view = mocks.Stub(); + mocks.ReplayAll(); + + using (var viewList = new ViewList(new TestDockingManager(), ViewLocation.Document)) + { + viewList.Add(view); + + viewList.CollectionChanged += (sender, args) => + { + Assert.AreSame(viewList, sender); + Assert.AreEqual(NotifyCollectionChangeAction.Remove, args.Action); + Assert.AreEqual(0, args.Index); + Assert.AreEqual(-1, args.OldIndex); + Assert.AreSame(view, args.Item); + Assert.IsNull(args.OldItem); + Assert.IsFalse(args.Cancel); + }; + + // Call + var removeResult = viewList.Remove(view); + + // Assert + Assert.IsTrue(removeResult); + CollectionAssert.IsEmpty(viewList); + Assert.IsNull(viewList.ActiveView); + } + mocks.VerifyAll(); + } + + [Test] + public void RemoveAt_RemovingAddedView_FireRemoveCollectionChange() + { + // Setup + var mocks = new MockRepository(); + var view = mocks.Stub(); + var anotherView = mocks.Stub(); + mocks.ReplayAll(); + + using (var viewList = new ViewList(new TestDockingManager(), ViewLocation.Document)) + { + viewList.Add(anotherView); + viewList.Add(view); + + var index = 1; + viewList.CollectionChanged += (sender, args) => + { + Assert.AreSame(viewList, sender); + Assert.AreEqual(NotifyCollectionChangeAction.Remove, args.Action); + Assert.AreEqual(index, args.Index); + Assert.AreEqual(-1, args.OldIndex); + Assert.AreSame(view, args.Item); + Assert.IsNull(args.OldItem); + Assert.IsFalse(args.Cancel); + }; + + // Call + viewList.RemoveAt(index); + + // Assert + Assert.AreEqual(1, viewList.Count); + Assert.AreEqual(anotherView, viewList.ActiveView); + } + mocks.VerifyAll(); + } } } \ No newline at end of file Index: Core/Common/test/Core.Common.Utils.Test/Core.Common.Utils.Test.csproj =================================================================== diff -u -r632b9c8cd36e7663a17e53320d3bfedb873889e0 -rd53a27a49d8db860ff0894554dab040a1b6204a5 --- Core/Common/test/Core.Common.Utils.Test/Core.Common.Utils.Test.csproj (.../Core.Common.Utils.Test.csproj) (revision 632b9c8cd36e7663a17e53320d3bfedb873889e0) +++ Core/Common/test/Core.Common.Utils.Test/Core.Common.Utils.Test.csproj (.../Core.Common.Utils.Test.csproj) (revision d53a27a49d8db860ff0894554dab040a1b6204a5) @@ -95,6 +95,8 @@ + + Index: Core/Common/test/Core.Common.Utils.Test/Events/EventArgsTest.cs =================================================================== diff -u --- Core/Common/test/Core.Common.Utils.Test/Events/EventArgsTest.cs (revision 0) +++ Core/Common/test/Core.Common.Utils.Test/Events/EventArgsTest.cs (revision d53a27a49d8db860ff0894554dab040a1b6204a5) @@ -0,0 +1,33 @@ +using Core.Common.Utils.Events; + +using NUnit.Framework; + +namespace Core.Common.Utils.Test.Events +{ + [TestFixture] + public class EventArgsTest + { + [Test] + public void ParameteredConstructor_PassingNull_ValueIsNull() + { + // Call + var args = new EventArgs(null); + + // Assert + Assert.IsNull(args.Value); + } + + [Test] + public void ParameteredConstructor_PassingObject_ValueIsSet() + { + // Setup + var obj = new object(); + + // Call + var args = new EventArgs(obj); + + // Assert + Assert.AreSame(obj, args.Value); + } + } +} \ No newline at end of file Index: Core/Common/test/Core.Common.Utils.Test/Events/NotifyCollectionChangeEventArgsTest.cs =================================================================== diff -u --- Core/Common/test/Core.Common.Utils.Test/Events/NotifyCollectionChangeEventArgsTest.cs (revision 0) +++ Core/Common/test/Core.Common.Utils.Test/Events/NotifyCollectionChangeEventArgsTest.cs (revision d53a27a49d8db860ff0894554dab040a1b6204a5) @@ -0,0 +1,87 @@ +using Core.Common.Utils.Events; + +using NUnit.Framework; + +namespace Core.Common.Utils.Test.Events +{ + [TestFixture] + public class NotifyCollectionChangeEventArgsTest + { + [Test] + public void ParameteredConstructor_PassArgumentValuesNotPassingOldElementValue_EventArgsPropertiesSet() + { + // Setup + var changeAction = NotifyCollectionChangeAction.Remove; + var elementValue = new object(); + var currentIndex = 1; + var previousIndex = 2; + + // Call + var args = new NotifyCollectionChangeEventArgs(changeAction, elementValue, currentIndex, previousIndex); + + // Assert + Assert.AreEqual(changeAction, args.Action); + Assert.AreEqual(currentIndex, args.Index); + Assert.AreEqual(elementValue, args.Item); + Assert.AreEqual(previousIndex, args.OldIndex); + Assert.IsNull(args.OldItem); + Assert.IsFalse(args.Cancel); + } + + [Test] + public void ParameteredConstructor_PassArgumentValuesWithOldElementValue_EventArgsPropertiesSet() + { + // Setup + var changeAction = NotifyCollectionChangeAction.Remove; + var elementValue = new object(); + var oldElementValue = new object(); + var currentIndex = 1; + var previousIndex = 2; + + // Call + var args = new NotifyCollectionChangeEventArgs(changeAction, elementValue, currentIndex, previousIndex, oldElementValue); + + // Assert + Assert.AreEqual(changeAction, args.Action); + Assert.AreEqual(currentIndex, args.Index); + Assert.AreEqual(elementValue, args.Item); + Assert.AreEqual(previousIndex, args.OldIndex); + Assert.AreEqual(oldElementValue, args.OldItem); + Assert.IsFalse(args.Cancel); + } + + [Test] + public void CreateCollectionResetArgs_ReturnInitializedEventArguments() + { + // Call + var args = NotifyCollectionChangeEventArgs.CreateCollectionResetArgs(); + + // Assert + Assert.AreEqual(NotifyCollectionChangeAction.Reset, args.Action); + Assert.AreEqual(-1, args.Index); + Assert.IsNull(args.Item); + Assert.AreEqual(-1, args.OldIndex); + Assert.IsNull(args.OldItem); + Assert.IsFalse(args.Cancel); + } + + [Test] + public void CreateCollectionAddArgs_ReturnInitializedEventArguments() + { + // Setup + var element = new object(); + var index = 1; + + // Call + var args = NotifyCollectionChangeEventArgs.CreateCollectionAddArgs(element, index); + + // Assert + Assert.AreEqual(NotifyCollectionChangeAction.Add, args.Action); + Assert.AreEqual(index, args.Index); + Assert.AreSame(element, args.Item); + Assert.AreEqual(-1, args.OldIndex); + Assert.IsNull(args.OldItem); + Assert.IsFalse(args.Cancel); + } + } +} \ No newline at end of file Index: Core/GIS/src/Core.GIS.SharpMap.Api/Collections/EventedList.cs =================================================================== diff -u -rfa33f7c078c5d17f92f6a519f147a0a371593944 -rd53a27a49d8db860ff0894554dab040a1b6204a5 --- Core/GIS/src/Core.GIS.SharpMap.Api/Collections/EventedList.cs (.../EventedList.cs) (revision fa33f7c078c5d17f92f6a519f147a0a371593944) +++ Core/GIS/src/Core.GIS.SharpMap.Api/Collections/EventedList.cs (.../EventedList.cs) (revision d53a27a49d8db860ff0894554dab040a1b6204a5) @@ -400,10 +400,7 @@ { if (CollectionChanged != null) { - var args = new NotifyCollectionChangeEventArgs(action, item, index, -1) - { - OldItem = oldItem - }; + var args = new NotifyCollectionChangeEventArgs(action, item, index, -1, oldItem); CollectionChanged(this, args); } } Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/NodePresenters/RingtoetsNodePresenterBaseTest.cs =================================================================== diff -u -rb326158bd228dc407858ba620a437a175baf0190 -rd53a27a49d8db860ff0894554dab040a1b6204a5 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/NodePresenters/RingtoetsNodePresenterBaseTest.cs (.../RingtoetsNodePresenterBaseTest.cs) (revision b326158bd228dc407858ba620a437a175baf0190) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/NodePresenters/RingtoetsNodePresenterBaseTest.cs (.../RingtoetsNodePresenterBaseTest.cs) (revision d53a27a49d8db860ff0894554dab040a1b6204a5) @@ -305,7 +305,7 @@ { // Setup var dataMock = mockRepository.StrictMock(); - var eventArgsMock = mockRepository.StrictMock(); + var eventArgsMock = mockRepository.StrictMock(NotifyCollectionChangeAction.Add, null, 0, 0); var contextMenuBuilderProviderMock = mockRepository.StrictMock(); mockRepository.ReplayAll(); Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/NodePresenters/AssessmentSectionBaseNodePresenterTest.cs =================================================================== diff -u -rb326158bd228dc407858ba620a437a175baf0190 -rd53a27a49d8db860ff0894554dab040a1b6204a5 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/NodePresenters/AssessmentSectionBaseNodePresenterTest.cs (.../AssessmentSectionBaseNodePresenterTest.cs) (revision b326158bd228dc407858ba620a437a175baf0190) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/NodePresenters/AssessmentSectionBaseNodePresenterTest.cs (.../AssessmentSectionBaseNodePresenterTest.cs) (revision d53a27a49d8db860ff0894554dab040a1b6204a5) @@ -322,7 +322,7 @@ // Setup var mocks = new MockRepository(); var dataMock = mocks.StrictMock(); - var eventArgsMock = mocks.StrictMock(); + var eventArgsMock = mocks.StrictMock(NotifyCollectionChangeAction.Add, null, 0, 0); var contextMenuBuilderProviderMock = mockRepository.StrictMock(); mocks.ReplayAll(); Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/NodePresenters/PipingCalculationContextNodePresenterTest.cs =================================================================== diff -u -r844b6342be08ffe7faa053883960c09f6e46fafa -rd53a27a49d8db860ff0894554dab040a1b6204a5 --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/NodePresenters/PipingCalculationContextNodePresenterTest.cs (.../PipingCalculationContextNodePresenterTest.cs) (revision 844b6342be08ffe7faa053883960c09f6e46fafa) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/NodePresenters/PipingCalculationContextNodePresenterTest.cs (.../PipingCalculationContextNodePresenterTest.cs) (revision d53a27a49d8db860ff0894554dab040a1b6204a5) @@ -491,7 +491,7 @@ public void OnCollectionChange_Always_DoNothing() { // Setup - var eventArgsMock = mockRepository.StrictMock(); + var eventArgsMock = mockRepository.StrictMock(NotifyCollectionChangeAction.Add, null, 0, 0); var contextMenuBuilderProvider = mockRepository.StrictMock(); mockRepository.ReplayAll(); Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/NodePresenters/PipingFailureMechanismNodePresenterTest.cs =================================================================== diff -u -r1c8c1345e29a2f154544922268ef07e03dc7bbb4 -rd53a27a49d8db860ff0894554dab040a1b6204a5 --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/NodePresenters/PipingFailureMechanismNodePresenterTest.cs (.../PipingFailureMechanismNodePresenterTest.cs) (revision 1c8c1345e29a2f154544922268ef07e03dc7bbb4) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/NodePresenters/PipingFailureMechanismNodePresenterTest.cs (.../PipingFailureMechanismNodePresenterTest.cs) (revision d53a27a49d8db860ff0894554dab040a1b6204a5) @@ -338,7 +338,7 @@ // Setup var contextMenuBuilderProviderMock = mockRepository.StrictMock(); var dataMock = mockRepository.StrictMock(); - var eventArgsMock = mockRepository.StrictMock(); + var eventArgsMock = mockRepository.StrictMock(NotifyCollectionChangeAction.Add, null, 0, 0); mockRepository.ReplayAll(); var nodePresenter = new PipingFailureMechanismNodePresenter(contextMenuBuilderProviderMock); Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/NodePresenters/PipingSurfaceLineCollectionNodePresenterTest.cs =================================================================== diff -u -rb326158bd228dc407858ba620a437a175baf0190 -rd53a27a49d8db860ff0894554dab040a1b6204a5 --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/NodePresenters/PipingSurfaceLineCollectionNodePresenterTest.cs (.../PipingSurfaceLineCollectionNodePresenterTest.cs) (revision b326158bd228dc407858ba620a437a175baf0190) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/NodePresenters/PipingSurfaceLineCollectionNodePresenterTest.cs (.../PipingSurfaceLineCollectionNodePresenterTest.cs) (revision d53a27a49d8db860ff0894554dab040a1b6204a5) @@ -348,7 +348,7 @@ { // Setup var dataMock = mockRepository.StrictMock>(); - var eventArgsMock = mockRepository.StrictMock(); + var eventArgsMock = mockRepository.StrictMock(NotifyCollectionChangeAction.Add, null, 0, 0); var contextMenuBuilderProviderMock = mockRepository.StrictMock(); mockRepository.ReplayAll();