Index: Core/Common/src/Core.Common.Gui/Forms/SplashScreen/SplashScreen.xaml.cs
===================================================================
diff -u -rfbb37872d09f1ded75ce2209e8e48a6b64d8a78f -r1e9f415cb615bf84526faeecb51f9a70498f9ffc
--- Core/Common/src/Core.Common.Gui/Forms/SplashScreen/SplashScreen.xaml.cs (.../SplashScreen.xaml.cs) (revision fbb37872d09f1ded75ce2209e8e48a6b64d8a78f)
+++ Core/Common/src/Core.Common.Gui/Forms/SplashScreen/SplashScreen.xaml.cs (.../SplashScreen.xaml.cs) (revision 1e9f415cb615bf84526faeecb51f9a70498f9ffc)
@@ -21,16 +21,14 @@
using System.Windows;
using System.Windows.Media;
-using log4net;
namespace Core.Common.Gui.Forms.SplashScreen
{
///
- /// Interaction logic for SplashScreen.xaml
+ /// Interaction logic for SplashScreen.xaml
///
public partial class SplashScreen
{
- private static readonly ILog log = LogManager.GetLogger(typeof(SplashScreen));
private string progressText;
private int progressValuePercent;
private string licenseText;
@@ -39,6 +37,10 @@
private string versionText;
private bool hasProgress;
+ ///
+ /// Initializes a new instance of the class with a progress
+ /// bar from 0 to 100%.
+ ///
public SplashScreen()
{
InitializeComponent();
@@ -71,7 +73,7 @@
}
///
- /// Version to be shown
+ /// Version to be shown.
///
public string VersionText
{
@@ -87,7 +89,7 @@
}
///
- /// Copyright owner to be shown
+ /// Copyright owner to be shown.
///
public string CopyrightText
{
@@ -103,7 +105,7 @@
}
///
- /// Registred company to be shown
+ /// Registred company to be shown.
///
public string CompanyText
{
@@ -119,7 +121,7 @@
}
///
- /// Type of the license, plain text
+ /// Type of the license, plain text.
///
public string LicenseText
{
@@ -151,7 +153,7 @@
}
///
- /// Text, as a current status of the progress
+ /// Text, as a current status of the progress.
///
public string ProgressText
{
@@ -166,16 +168,15 @@
}
}
+ ///
+ /// Shuts this instance down.
+ ///
public void Shutdown()
{
Focusable = false;
Close();
}
- ///
- /// When overridden in a derived class, participates in rendering operations that are directed by the layout system. The rendering instructions for this element are not used directly when this method is invoked, and are instead preserved for later asynchronous use by layout and drawing.
- ///
- /// The drawing instructions for a specific element. This context is provided to the layout system.
protected override void OnRender(DrawingContext drawingContext)
{
base.OnRender(drawingContext);
Index: Core/Common/src/Core.Common.Gui/Forms/ViewManager/ActiveViewChangeEventArgs.cs
===================================================================
diff -u -r0c64d8a6c718c0aa67403a16c94dd0c10f862455 -r1e9f415cb615bf84526faeecb51f9a70498f9ffc
--- Core/Common/src/Core.Common.Gui/Forms/ViewManager/ActiveViewChangeEventArgs.cs (.../ActiveViewChangeEventArgs.cs) (revision 0c64d8a6c718c0aa67403a16c94dd0c10f862455)
+++ Core/Common/src/Core.Common.Gui/Forms/ViewManager/ActiveViewChangeEventArgs.cs (.../ActiveViewChangeEventArgs.cs) (revision 1e9f415cb615bf84526faeecb51f9a70498f9ffc)
@@ -25,16 +25,39 @@
namespace Core.Common.Gui.Forms.ViewManager
{
+ ///
+ /// Event arguments for changes to the .
+ ///
public class ActiveViewChangeEventArgs : EventArgs
{
///
- /// Current view.
+ /// Initializes a new instance of the class.
///
- public IView View { get; set; }
+ /// The current active view.
+ public ActiveViewChangeEventArgs(IView currentActiveView)
+ {
+ View = currentActiveView;
+ }
///
- /// Previous view.
+ /// Initializes a new instance of the class.
///
- public IView OldView { get; set; }
+ /// The current active view.
+ /// The previously active view.
+ public ActiveViewChangeEventArgs(IView currentActiveView, IView previousActiveView)
+ {
+ View = currentActiveView;
+ OldView = previousActiveView;
+ }
+
+ ///
+ /// The current active view.
+ ///
+ public IView View { get; private set; }
+
+ ///
+ /// The previously active view. Is not null when switching from one view to another.
+ ///
+ public IView OldView { get; private set; }
}
}
\ No newline at end of file
Index: Core/Common/src/Core.Common.Gui/Forms/ViewManager/AvalonDockDockingManager.cs
===================================================================
diff -u -rfbb37872d09f1ded75ce2209e8e48a6b64d8a78f -r1e9f415cb615bf84526faeecb51f9a70498f9ffc
--- Core/Common/src/Core.Common.Gui/Forms/ViewManager/AvalonDockDockingManager.cs (.../AvalonDockDockingManager.cs) (revision fbb37872d09f1ded75ce2209e8e48a6b64d8a78f)
+++ Core/Common/src/Core.Common.Gui/Forms/ViewManager/AvalonDockDockingManager.cs (.../AvalonDockDockingManager.cs) (revision 1e9f415cb615bf84526faeecb51f9a70498f9ffc)
@@ -162,10 +162,7 @@
if (ViewActivated != null)
{
- ViewActivated(this, new ActiveViewChangeEventArgs
- {
- View = view
- });
+ ViewActivated(this, new ActiveViewChangeEventArgs(view));
}
}
@@ -208,10 +205,7 @@
if (ViewActivated != null)
{
- ViewActivated(this, new ActiveViewChangeEventArgs
- {
- View = activeView
- });
+ ViewActivated(this, new ActiveViewChangeEventArgs(activeView));
}
}
@@ -375,10 +369,7 @@
if (ViewActivated != null)
{
- ViewActivated(this, new ActiveViewChangeEventArgs
- {
- View = view
- });
+ ViewActivated(this, new ActiveViewChangeEventArgs(view));
}
}
@@ -444,7 +435,7 @@
anchorablePane = dockingManager.Layout.Descendents().OfType().FirstOrDefault(p => p.GetSide() == anchorSide);
- if ((location & ViewLocation.Bottom) == ViewLocation.Bottom)
+ if (location.HasFlag(ViewLocation.Bottom))
{
anchorablePane = dockingManager.Layout.Descendents().OfType().LastOrDefault(p => p.GetSide() == anchorSide);
}
@@ -470,7 +461,7 @@
anchorablePane = dockingManager.Layout.Descendents().OfType().FirstOrDefault(p => p.GetSide() == anchorSide);
// check if Top or Bottom is specified
- if ((location & ViewLocation.Bottom) == ViewLocation.Bottom)
+ if (location.HasFlag(ViewLocation.Bottom))
{
anchorablePane = dockingManager.Layout.Descendents().OfType().LastOrDefault(p => p.GetSide() == anchorSide);
}
Index: Core/Common/src/Core.Common.Gui/Forms/ViewManager/DockTabClosingEventArgs.cs
===================================================================
diff -u -rfbb37872d09f1ded75ce2209e8e48a6b64d8a78f -r1e9f415cb615bf84526faeecb51f9a70498f9ffc
--- Core/Common/src/Core.Common.Gui/Forms/ViewManager/DockTabClosingEventArgs.cs (.../DockTabClosingEventArgs.cs) (revision fbb37872d09f1ded75ce2209e8e48a6b64d8a78f)
+++ Core/Common/src/Core.Common.Gui/Forms/ViewManager/DockTabClosingEventArgs.cs (.../DockTabClosingEventArgs.cs) (revision 1e9f415cb615bf84526faeecb51f9a70498f9ffc)
@@ -24,15 +24,18 @@
namespace Core.Common.Gui.Forms.ViewManager
{
+ ///
+ /// Event arguments for closing a docked view.
+ ///
public class DockTabClosingEventArgs : EventArgs
{
///
- /// View trying to close (because a tab is being closed)
+ /// View trying to close (because a tab is being closed).
///
public IView View { get; set; }
///
- /// Specifies the close action should be cancelled
+ /// Specifies if the close action should be cancelled.
///
public bool Cancel { get; set; }
}
Index: Core/Common/src/Core.Common.Gui/Forms/ViewManager/IDockingManager.cs
===================================================================
diff -u -rfbb37872d09f1ded75ce2209e8e48a6b64d8a78f -r1e9f415cb615bf84526faeecb51f9a70498f9ffc
--- Core/Common/src/Core.Common.Gui/Forms/ViewManager/IDockingManager.cs (.../IDockingManager.cs) (revision fbb37872d09f1ded75ce2209e8e48a6b64d8a78f)
+++ Core/Common/src/Core.Common.Gui/Forms/ViewManager/IDockingManager.cs (.../IDockingManager.cs) (revision 1e9f415cb615bf84526faeecb51f9a70498f9ffc)
@@ -28,7 +28,7 @@
namespace Core.Common.Gui.Forms.ViewManager
{
///
- /// Interface providing view docking control. Implemented in DotNetBar for now.
+ /// Interface providing view docking control.
///
public interface IDockingManager : IDisposable
{
Index: Core/Common/src/Core.Common.Gui/Forms/ViewManager/IViewList.cs
===================================================================
diff -u -r0c64d8a6c718c0aa67403a16c94dd0c10f862455 -r1e9f415cb615bf84526faeecb51f9a70498f9ffc
--- Core/Common/src/Core.Common.Gui/Forms/ViewManager/IViewList.cs (.../IViewList.cs) (revision 0c64d8a6c718c0aa67403a16c94dd0c10f862455)
+++ Core/Common/src/Core.Common.Gui/Forms/ViewManager/IViewList.cs (.../IViewList.cs) (revision 1e9f415cb615bf84526faeecb51f9a70498f9ffc)
@@ -27,29 +27,50 @@
namespace Core.Common.Gui.Forms.ViewManager
{
+ ///
+ /// Flags on where views can be located.
+ ///
[Flags]
public enum ViewLocation
{
+ ///
+ /// The location reserved for Document Views.
+ ///
Document = 0x0,
+ ///
+ /// Left of the location reserved for Document Views.
+ ///
Left = 0x1,
+ ///
+ /// Right of the location reserved for Document Views.
+ ///
Right = 0x2,
+ ///
+ /// Above the location reserved for Document Views.
+ ///
Top = 0x4,
+ ///
+ /// Below the location reserved for Document Views.
+ ///
Bottom = 0x8,
+ ///
+ /// Floating panel.
+ ///
Floating = 0x16
};
///
- /// Manages currently displayed views
+ /// Manages currently displayed views.
///
public interface IViewList : IList, IDisposable
{
///
- /// Fired before active view has been changed.
+ /// Fired before active view has changed.
///
event EventHandler ActiveViewChanging;
///
- /// Fired after active view has been changed.
+ /// Fired after active view has changed.
///
event EventHandler ActiveViewChanged;
@@ -64,39 +85,34 @@
bool IgnoreActivation { get; set; }
///
- /// Gets or sets active view, when view is active - its window is activated.
+ /// Gets or sets active view.
///
IView ActiveView { get; set; }
///
- /// Returns all views. Including views inside composite views
+ /// Returns all views.
///
IEnumerable AllViews { get; }
///
- /// Adds a view to the UI.
+ /// Adds a view to the view list and makes it active.
///
- ///
- ///
+ /// The view to be added.
+ /// The location where the view should be added.
void Add(IView view, ViewLocation viewLocation);
///
- /// Sets the tooltip of the view
+ /// Sets the tooltip of the view's container.
///
- ///
- ///
+ /// The view already part of this list.
+ /// The text of the tooltip.
void SetTooltip(IView view, string tooltip);
///
- /// Updates the name of the view
+ /// Removes all views except
///
- ///
- void UpdateViewName(IView view);
-
- ///
- /// Overloaded Clear, removes all views except
- ///
- ///
+ /// The view that should be kept open and made the active view.
+ /// If set to null, all views will be closed and will be null.
void Clear(IView viewToKeep);
}
}
\ No newline at end of file
Index: Core/Common/src/Core.Common.Gui/Forms/ViewManager/ViewList.cs
===================================================================
diff -u -rfbb37872d09f1ded75ce2209e8e48a6b64d8a78f -r1e9f415cb615bf84526faeecb51f9a70498f9ffc
--- Core/Common/src/Core.Common.Gui/Forms/ViewManager/ViewList.cs (.../ViewList.cs) (revision fbb37872d09f1ded75ce2209e8e48a6b64d8a78f)
+++ Core/Common/src/Core.Common.Gui/Forms/ViewManager/ViewList.cs (.../ViewList.cs) (revision 1e9f415cb615bf84526faeecb51f9a70498f9ffc)
@@ -49,7 +49,7 @@
private readonly IList views;
private IView activeView;
- private bool clearing; // used to skip view activation when it is not necessary
+ //private bool clearing; // used to skip view activation when it is not necessary
///
/// Initializes a new instance of the class.
@@ -76,7 +76,6 @@
set
{
- // don't just replace the view..we want contexts to kick in etc..so we do a remove / insert at index
RemoveAt(index);
Insert(index, value);
}
@@ -139,14 +138,6 @@
}
}
- public void AddRange(IEnumerable enumerable)
- {
- foreach (var v in enumerable)
- {
- Add(v);
- }
- }
-
public void SetImage(IView view, Image image)
{
dockingManager.SetImage(view, image);
@@ -172,21 +163,18 @@
public void Clear()
{
- clearing = true;
while (Count > 0)
{
Close(views[0], true, false);
}
- clearing = false;
ActiveView = null;
FireCollectionChangedEvent(NotifyCollectionChangeEventArgs.CreateCollectionResetArgs());
}
public void Clear(IView viewToKeep)
{
- clearing = true;
var viewToKeepIndex = views.IndexOf(viewToKeep);
for (int i = views.Count - 1; i >= 0; i--)
@@ -197,8 +185,6 @@
}
}
- clearing = false;
-
ActiveView = viewToKeep;
}
@@ -212,14 +198,6 @@
views.CopyTo(array, arrayIndex);
}
- public void UpdateViewName(IView view)
- {
- if (UpdateViewNameAction != null)
- {
- UpdateViewNameAction(view);
- }
- }
-
public IEnumerator GetEnumerator()
{
return views.GetEnumerator();
@@ -243,8 +221,7 @@
public bool Remove(IView view)
{
- Close(view, true, true);
- return true;
+ return Close(view, true, true);
}
public void RemoveAt(int index)
@@ -264,13 +241,8 @@
private void ActivateView(IView view)
{
- if (clearing)
- {
- return;
- }
-
var disposableView = view as Control;
- if ((disposableView != null) && disposableView.IsDisposed)
+ if (disposableView != null && disposableView.IsDisposed)
{
return; // skip view activation when it is disposed (happens e.g. when closing app)
}
@@ -280,7 +252,7 @@
return;
}
- if (activeView == view && (activeView != null && ((Control) activeView).Visible))
+ if (activeView == view && activeView != null && ((Control) activeView).Visible)
{
if (activeView is Control)
{
@@ -316,31 +288,25 @@
FireActiveViewChangedEvent(oldView);
}
- ///
- /// Set the active view to previous view in the list (if any). Or sets activeview to null if no other view available
- ///
- private void ChangeActiveView()
+ private void ChangeActiveViewToPrevious()
{
var activeViewIndex = views.IndexOf(activeView);
- // set active view to next view
if (Count > 1)
{
- activeViewIndex = activeViewIndex > 0
- ? Math.Max(0, activeViewIndex - 1)
- : 1;
+ var viewIndexToActivate = activeViewIndex > 0 ?
+ activeViewIndex - 1 :
+ 1; // There is no previous, so use next instead
- ActiveView = views[activeViewIndex];
+ ActiveView = views[viewIndexToActivate];
}
else
{
- //Cannot reproduce, but sometimes it doesn't clear ActiveView (and then crashes) because count==0 (iso 1).
- //So adjusted the check for 'stability'. Couldn't find the underlying issue.
ActiveView = null;
}
}
- private void Close(IView view, bool removeTabFromDockingManager, bool activateNextView)
+ private bool Close(IView view, bool removeTabFromDockingManager, bool activateNextView)
{
if (ViewResolver.IsViewOpening)
{
@@ -349,27 +315,26 @@
if (!Contains(view))
{
- return; // small optimization
+ return false;
}
- if (activateNextView)
+ if (activateNextView && ActiveView == view)
{
- if (ActiveView == view)
- {
- ChangeActiveView();
- }
+ ChangeActiveViewToPrevious();
}
int oldIndex = views.IndexOf(view);
- views.Remove(view);
+ var succesfullyRemovedView = views.Remove(view);
FireCollectionChangedEvent(NotifyCollectionChangeEventArgs.CreateCollectionRemoveArgs(view, oldIndex));
// remove from docking manager
dockingManager.Remove(view, removeTabFromDockingManager);
ForceViewCleanup(view);
+
+ return succesfullyRemovedView;
}
private static void ForceViewCleanup(IView view)
@@ -399,21 +364,15 @@
{
if (ActiveViewChanging != null)
{
- ActiveViewChanging(this, new ActiveViewChangeEventArgs
- {
- View = newView, OldView = oldView
- });
+ ActiveViewChanging(this, new ActiveViewChangeEventArgs(newView, oldView));
}
}
private void FireActiveViewChangedEvent(IView oldView)
{
if (ActiveViewChanged != null)
{
- ActiveViewChanged(this, new ActiveViewChangeEventArgs
- {
- View = ActiveView, OldView = oldView
- });
+ ActiveViewChanged(this, new ActiveViewChangeEventArgs(ActiveView, oldView));
}
}
Index: Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj
===================================================================
diff -u -r0358065f73923af6b8ca6566ee1e210c78c55e44 -r1e9f415cb615bf84526faeecb51f9a70498f9ffc
--- Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj (.../Core.Common.Gui.Test.csproj) (revision 0358065f73923af6b8ca6566ee1e210c78c55e44)
+++ Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj (.../Core.Common.Gui.Test.csproj) (revision 1e9f415cb615bf84526faeecb51f9a70498f9ffc)
@@ -116,6 +116,23 @@
+
+
+
+
+ UserControl
+
+
+ TestView.cs
+
+
+ UserControl
+
+
+ ToolWindowTestControl.cs
+
+
+
True
True
@@ -128,7 +145,6 @@
-
@@ -165,6 +181,13 @@
+
+ TestView.cs
+
+
+ ToolWindowTestControl.cs
+ Designer
+
ResXFileCodeGenerator
Resources.Designer.cs
Index: Core/Common/test/Core.Common.Gui.Test/Forms/SplashScreen/SplashScreenTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.Gui.Test/Forms/SplashScreen/SplashScreenTest.cs (revision 0)
+++ Core/Common/test/Core.Common.Gui.Test/Forms/SplashScreen/SplashScreenTest.cs (revision 1e9f415cb615bf84526faeecb51f9a70498f9ffc)
@@ -0,0 +1,102 @@
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Media;
+
+using NUnit.Framework;
+
+using Application = System.Windows.Forms.Application;
+
+namespace Core.Common.Gui.Test.Forms.SplashScreen
+{
+ [TestFixture]
+ public class SplashScreenTest
+ {
+ [Test]
+ [RequiresSTA]
+ public void ViewProperties_SetNewValues_ShouldSetLabelTextOfUserInterfaceElements()
+ {
+ // Setup
+ var strCompany = "Cmp1";
+ var strCopyright = "Copy1";
+ var strLicense = "License1";
+ var strVersion = "Version1";
+ var strProgressText = "SomeProgress1";
+
+ // Call
+ var screen = new Gui.Forms.SplashScreen.SplashScreen
+ {
+ CompanyText = strCompany,
+ CopyrightText = strCopyright,
+ LicenseText = strLicense,
+ VersionText = strVersion,
+ ProgressText = strProgressText
+ };
+ screen.Show();
+
+ // Assert
+ Assert.AreEqual(strVersion, GetLabelText(screen, "labelVersion"));
+ Assert.AreEqual(strCompany, GetLabelText(screen, "labelCompany"));
+ Assert.AreEqual(strLicense, GetLabelText(screen, "labelLicense"));
+ Assert.AreEqual(strCopyright, GetLabelText(screen, "labelCopyright"));
+ Assert.AreEqual(strProgressText, GetLabelText(screen, "labelProgressMessage"));
+
+ screen.Close();
+ }
+
+ [Test]
+ [RequiresSTA]
+ public void TestProgressBarVisible()
+ {
+ // Setup
+ var screen = new Gui.Forms.SplashScreen.SplashScreen();
+ screen.Show();
+ Assert.IsTrue(screen.HasProgress, "Initially, the progress should be visible");
+ Assert.IsTrue(GetIsControlVisible(screen, "progressBar"));
+ Assert.IsTrue(GetIsControlVisible(screen, "labelProgressMessage"));
+ Assert.IsTrue(GetIsControlVisible(screen, "labelProgressBar"));
+
+ // Call
+ screen.HasProgress = false;
+ Application.DoEvents(); // creating space for lazy-updating to do its work
+
+ // Assert
+ Assert.IsFalse(screen.HasProgress, "HasProgress is changed to FALSE by now");
+
+ Assert.IsFalse(GetIsControlVisible(screen, "progressBar"));
+ Assert.IsFalse(GetIsControlVisible(screen, "labelProgressMessage"));
+ Assert.IsFalse(GetIsControlVisible(screen, "labelProgressBar"));
+
+ screen.Close();
+ }
+
+ private FrameworkElement FindControlRecursively(FrameworkElement parent, string name)
+ {
+ var childrenCount = VisualTreeHelper.GetChildrenCount(parent);
+ FrameworkElement foundChild = null;
+ for (var childIndex = 0; childIndex < childrenCount; childIndex++)
+ {
+ var child = (FrameworkElement)VisualTreeHelper.GetChild(parent, childIndex);
+ foundChild = child.Name == name ? child : FindControlRecursively(child, name);
+
+ if (foundChild != null)
+ {
+ break;
+ }
+ }
+
+ return foundChild;
+ }
+
+ private string GetLabelText(FrameworkElement parent, string labelName)
+ {
+ var label = FindControlRecursively(parent, labelName) as Label;
+ return (label != null) ? label.Content.ToString() : "";
+ }
+
+ private bool GetIsControlVisible(FrameworkElement parent, string ctrlName)
+ {
+ var ctrl = FindControlRecursively(parent, ctrlName) as Control;
+ return ctrl != null && ctrl.IsVisible;
+ }
+ }
+}
\ No newline at end of file
Fisheye: Tag 1e9f415cb615bf84526faeecb51f9a70498f9ffc refers to a dead (removed) revision in file `Core/Common/test/Core.Common.Gui.Test/Forms/SplashScreenTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Core/Common/test/Core.Common.Gui.Test/Forms/ViewManager/ActiveViewChangeEventArgsTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.Gui.Test/Forms/ViewManager/ActiveViewChangeEventArgsTest.cs (revision 0)
+++ Core/Common/test/Core.Common.Gui.Test/Forms/ViewManager/ActiveViewChangeEventArgsTest.cs (revision 1e9f415cb615bf84526faeecb51f9a70498f9ffc)
@@ -0,0 +1,54 @@
+using System;
+
+using Core.Common.Controls.Views;
+using Core.Common.Gui.Forms.ViewManager;
+
+using NUnit.Framework;
+
+using Rhino.Mocks;
+
+namespace Core.Common.Gui.Test.Forms.ViewManager
+{
+ [TestFixture]
+ public class ActiveViewChangeEventArgsTest
+ {
+ [Test]
+ public void ParameteredConstructor_OnlyActiveView_ExpectedValues()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var activeView = mocks.Stub();
+ mocks.ReplayAll();
+
+ // Call
+ var eventArgs = new ActiveViewChangeEventArgs(activeView);
+
+ // Assert
+ Assert.IsInstanceOf(eventArgs);
+ Assert.AreSame(activeView, eventArgs.View);
+ Assert.IsNull(eventArgs.OldView);
+
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void ParameteredConstructor_SwitchedToOtherView_ExpectedValues()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var activeView = mocks.Stub();
+ var previouslyActiveView = mocks.Stub();
+ mocks.ReplayAll();
+
+ // Call
+ var eventArgs = new ActiveViewChangeEventArgs(activeView, previouslyActiveView);
+
+ // Assert
+ Assert.IsInstanceOf(eventArgs);
+ Assert.AreSame(activeView, eventArgs.View);
+ Assert.AreSame(previouslyActiveView, eventArgs.OldView);
+
+ mocks.VerifyAll();
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.Gui.Test/Forms/ViewManager/DockTabClosingEventArgsTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.Gui.Test/Forms/ViewManager/DockTabClosingEventArgsTest.cs (revision 0)
+++ Core/Common/test/Core.Common.Gui.Test/Forms/ViewManager/DockTabClosingEventArgsTest.cs (revision 1e9f415cb615bf84526faeecb51f9a70498f9ffc)
@@ -0,0 +1,47 @@
+using Core.Common.Controls.Views;
+using Core.Common.Gui.Forms.ViewManager;
+
+using NUnit.Framework;
+
+using Rhino.Mocks;
+
+namespace Core.Common.Gui.Test.Forms.ViewManager
+{
+ [TestFixture]
+ public class DockTabClosingEventArgsTest
+ {
+ [Test]
+ public void DefaultConstructor_ExpectedValues()
+ {
+ // Setup
+
+ // Call
+ var eventArgs = new DockTabClosingEventArgs();
+
+ // Assert
+ Assert.IsNull(eventArgs.View);
+ Assert.IsFalse(eventArgs.Cancel);
+ }
+
+ [Test]
+ public void SimpleProperties_SetNewValue_GetNewValue()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var view = mocks.Stub();
+ mocks.ReplayAll();
+
+ var eventArgs = new DockTabClosingEventArgs();
+
+ // Call
+ eventArgs.View = view;
+ eventArgs.Cancel = true;
+
+ // Assert
+ Assert.AreEqual(view, eventArgs.View);
+ Assert.IsTrue(eventArgs.Cancel);
+
+ mocks.VerifyAll();
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.Gui.Test/Forms/ViewManager/TestView.Designer.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.Gui.Test/Forms/ViewManager/TestView.Designer.cs (revision 0)
+++ Core/Common/test/Core.Common.Gui.Test/Forms/ViewManager/TestView.Designer.cs (revision 1e9f415cb615bf84526faeecb51f9a70498f9ffc)
@@ -0,0 +1,56 @@
+namespace Core.Common.Test.TestObjects
+{
+ partial class TestView
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Component Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.textBox1 = new System.Windows.Forms.TextBox();
+ this.SuspendLayout();
+ //
+ // textBox1
+ //
+ this.textBox1.Location = new System.Drawing.Point(3, 3);
+ this.textBox1.Name = "textBox1";
+ this.textBox1.Size = new System.Drawing.Size(74, 20);
+ this.textBox1.TabIndex = 0;
+ //
+ // TestView
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.Controls.Add(this.textBox1);
+ this.Name = "TestView";
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.TextBox textBox1;
+ }
+}
Index: Core/Common/test/Core.Common.Gui.Test/Forms/ViewManager/TestView.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.Gui.Test/Forms/ViewManager/TestView.cs (revision 0)
+++ Core/Common/test/Core.Common.Gui.Test/Forms/ViewManager/TestView.cs (revision 1e9f415cb615bf84526faeecb51f9a70498f9ffc)
@@ -0,0 +1,22 @@
+using System.Windows.Forms;
+using Core.Common.Controls.Views;
+
+namespace Core.Common.Test.TestObjects
+{
+ public partial class TestView : UserControl, IView
+ {
+ public TestView()
+ {
+ InitializeComponent();
+ }
+
+ public object Data { get; set; }
+ }
+
+ public class TestViewDerivative : TestView {}
+
+ public class TestWrapper
+ {
+ public string RealData { get; set; }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.Gui.Test/Forms/ViewManager/TestView.resx
===================================================================
diff -u
--- Core/Common/test/Core.Common.Gui.Test/Forms/ViewManager/TestView.resx (revision 0)
+++ Core/Common/test/Core.Common.Gui.Test/Forms/ViewManager/TestView.resx (revision 1e9f415cb615bf84526faeecb51f9a70498f9ffc)
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
Index: Core/Common/test/Core.Common.Gui.Test/Forms/ViewManager/ToolWindowTestControl.Designer.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.Gui.Test/Forms/ViewManager/ToolWindowTestControl.Designer.cs (revision 0)
+++ Core/Common/test/Core.Common.Gui.Test/Forms/ViewManager/ToolWindowTestControl.Designer.cs (revision 1e9f415cb615bf84526faeecb51f9a70498f9ffc)
@@ -0,0 +1,56 @@
+namespace Core.Common.Gui.Test.Forms.ViewManager
+{
+ partial class ToolWindowTestControl
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Component Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.propertyGrid1 = new System.Windows.Forms.PropertyGrid();
+ this.SuspendLayout();
+ //
+ // propertyGrid1
+ //
+ this.propertyGrid1.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.propertyGrid1.Location = new System.Drawing.Point(0, 0);
+ this.propertyGrid1.Name = "propertyGrid1";
+ this.propertyGrid1.Size = new System.Drawing.Size(150, 150);
+ this.propertyGrid1.TabIndex = 0;
+ //
+ // ToolWindowTestControl
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.Controls.Add(this.propertyGrid1);
+ this.Name = "ToolWindowTestControl";
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.PropertyGrid propertyGrid1;
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.Gui.Test/Forms/ViewManager/ToolWindowTestControl.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.Gui.Test/Forms/ViewManager/ToolWindowTestControl.cs (revision 0)
+++ Core/Common/test/Core.Common.Gui.Test/Forms/ViewManager/ToolWindowTestControl.cs (revision 1e9f415cb615bf84526faeecb51f9a70498f9ffc)
@@ -0,0 +1,26 @@
+using System.Windows.Forms;
+
+using Core.Common.Controls.Views;
+
+namespace Core.Common.Gui.Test.Forms.ViewManager
+{
+ public partial class ToolWindowTestControl : UserControl, IView
+ {
+ public ToolWindowTestControl()
+ {
+ Initialize();
+ }
+
+ #region IView Members
+
+ public object Data { get; set; }
+
+ #endregion
+
+ private void Initialize()
+ {
+ InitializeComponent();
+ propertyGrid1.SelectedObject = propertyGrid1;
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.Gui.Test/Forms/ViewManager/ToolWindowTestControl.resx
===================================================================
diff -u
--- Core/Common/test/Core.Common.Gui.Test/Forms/ViewManager/ToolWindowTestControl.resx (revision 0)
+++ Core/Common/test/Core.Common.Gui.Test/Forms/ViewManager/ToolWindowTestControl.resx (revision 1e9f415cb615bf84526faeecb51f9a70498f9ffc)
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
Index: Core/Common/test/Core.Common.Gui.Test/Forms/ViewManager/ViewListTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.Gui.Test/Forms/ViewManager/ViewListTest.cs (revision 0)
+++ Core/Common/test/Core.Common.Gui.Test/Forms/ViewManager/ViewListTest.cs (revision 1e9f415cb615bf84526faeecb51f9a70498f9ffc)
@@ -0,0 +1,1272 @@
+using System;
+using System.Linq;
+
+using Core.Common.Controls.Views;
+using Core.Common.Gui.Forms.ViewManager;
+using Core.Common.Gui.Test.Properties;
+using Core.Common.TestUtil;
+using Core.Common.Utils.Events;
+
+using NUnit.Framework;
+
+using Rhino.Mocks;
+
+namespace Core.Common.Gui.Test.Forms.ViewManager
+{
+ [TestFixture]
+ public class ViewListTest
+ {
+ [Test]
+ public void ParameteredConstructor_ExpectedValues()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var dockingManager = mocks.Stub();
+ mocks.ReplayAll();
+
+ // Call
+ using (var viewList = new ViewList(dockingManager, ViewLocation.Document))
+ {
+ // Assert
+ CollectionAssert.IsEmpty(viewList);
+ Assert.AreEqual(0, viewList.Count);
+ Assert.IsNull(viewList.ActiveView);
+ CollectionAssert.IsEmpty(viewList.AllViews);
+ Assert.IsFalse(viewList.IgnoreActivation);
+ Assert.IsFalse(viewList.IsReadOnly);
+ Assert.IsNull(viewList.UpdateViewNameAction);
+ }
+
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void ActiveView_SetViewNotInViewList_MakeActiveViewAndFireActiveViewChangingEventsAndLogThatViewIsNotInCollection()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var dockingManager = mocks.Stub();
+ mocks.ReplayAll();
+
+ using (var view = new ToolWindowTestControl())
+ using (var viewList = new ViewList(dockingManager, ViewLocation.Document))
+ {
+ var changingEventCount = 0;
+ viewList.ActiveViewChanging += (sender, args) =>
+ {
+ changingEventCount++;
+ Assert.AreSame(viewList, sender);
+ Assert.AreSame(view, args.View);
+ Assert.IsNull(args.OldView);
+ };
+ var changedEventCount = 0;
+ viewList.ActiveViewChanged += (sender, args) =>
+ {
+ changingEventCount++;
+ Assert.AreSame(viewList, sender);
+ Assert.AreSame(view, args.View);
+ Assert.IsNull(args.OldView);
+ };
+
+ // Precondition
+ CollectionAssert.DoesNotContain(viewList, view);
+
+ // Call
+ Action call = () => viewList.ActiveView = view;
+
+ // Assert
+ TestHelper.AssertLogMessageIsGenerated(call, "Documentvenster is niet gevonden tussen alle mogelijke documentvensters.", 1);
+
+ Assert.AreEqual(1, changingEventCount);
+ Assert.AreEqual(0, changedEventCount);
+
+ Assert.AreSame(view, viewList.ActiveView);
+ Assert.IsFalse(view.Focused);
+ }
+
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void ActiveView_SetViewInList_SwitchActiveViewWithChangeEvents()
+ {
+ // Setup
+ using (var view1 = new ToolWindowTestControl())
+ using (var view2 = new ToolWindowTestControl())
+ {
+ var mocks = new MockRepository();
+ var dockingManager = mocks.Stub();
+ mocks.ReplayAll();
+
+ using (var viewList = new ViewList(dockingManager, ViewLocation.Floating))
+ {
+ viewList.Add(view1);
+ viewList.Add(view2);
+
+ var changingEventCount = 0;
+ viewList.ActiveViewChanging += (sender, args) =>
+ {
+ Assert.AreSame(viewList, sender);
+ Assert.AreSame(view1, args.View);
+ Assert.AreSame(view2, args.OldView);
+ changingEventCount++;
+ };
+
+ var changedEventCount = 0;
+ viewList.ActiveViewChanged += (sender, args) =>
+ {
+ Assert.AreSame(viewList, sender);
+ Assert.AreSame(view1, args.View);
+ Assert.AreSame(view2, args.OldView);
+ changedEventCount++;
+ };
+
+ // Precondition
+ Assert.False(viewList.IgnoreActivation);
+ Assert.AreSame(view2, viewList.ActiveView);
+
+ // Call
+ viewList.ActiveView = view1;
+
+ // Assert
+ Assert.AreSame(view1, viewList.ActiveView);
+
+ Assert.AreEqual(1, changingEventCount);
+ Assert.AreEqual(1, changedEventCount);
+ }
+ mocks.VerifyAll();
+ }
+ }
+
+ [Test]
+ public void ActiveView_IgnoreActivation_DoNotChangeActiveView()
+ {
+ // Setup
+ using (var view1 = new ToolWindowTestControl())
+ using (var view2 = new ToolWindowTestControl())
+ {
+ var mocks = new MockRepository();
+ var dockingManager = mocks.Stub();
+ mocks.ReplayAll();
+
+ using (var viewList = new ViewList(dockingManager, ViewLocation.Floating))
+ {
+ viewList.Add(view1);
+ viewList.Add(view2);
+
+ viewList.IgnoreActivation = true;
+
+ viewList.ActiveViewChanging += (sender, args) =>
+ {
+ Assert.Fail("Should ignore view activation, therefore no events should be fired.");
+ };
+
+ viewList.ActiveViewChanged += (sender, args) =>
+ {
+ Assert.Fail("Should ignore view activation, therefore no events should be fired.");
+ };
+
+ // Precondition
+ Assert.AreSame(view2, viewList.ActiveView);
+
+ // Call
+ viewList.ActiveView = view1;
+
+ // Assert
+ Assert.AreSame(view2, viewList.ActiveView);
+ }
+ mocks.VerifyAll();
+ }
+ }
+
+ [Test]
+ public void ActiveView_ActivatingDisposedView_DoNotChangeActiveView()
+ {
+ // Setup
+ using (var view1 = new ToolWindowTestControl())
+ using (var view2 = new ToolWindowTestControl())
+ {
+ var mocks = new MockRepository();
+ var dockingManager = mocks.Stub();
+ mocks.ReplayAll();
+
+ using (var viewList = new ViewList(dockingManager, ViewLocation.Floating))
+ {
+ viewList.Add(view1);
+ viewList.Add(view2);
+
+ view1.Dispose();
+
+ viewList.ActiveViewChanging += (sender, args) =>
+ {
+ Assert.Fail("Should ignore view activation, therefore no events should be fired.");
+ };
+
+ viewList.ActiveViewChanged += (sender, args) =>
+ {
+ Assert.Fail("Should ignore view activation, therefore no events should be fired.");
+ };
+
+ // Precondition
+ Assert.AreSame(view2, viewList.ActiveView);
+ Assert.IsTrue(view1.IsDisposed);
+
+ // Call
+ viewList.ActiveView = view1;
+
+ // Assert
+ Assert.AreSame(view2, viewList.ActiveView);
+ }
+ mocks.VerifyAll();
+ }
+ }
+
+ [Test]
+ [TestCase(ViewLocation.Top)]
+ [TestCase(ViewLocation.Bottom)]
+ [TestCase(ViewLocation.Document)]
+ [TestCase(ViewLocation.Floating)]
+ [TestCase(ViewLocation.Left)]
+ [TestCase(ViewLocation.Right)]
+ public void Add_ViewInAnyLocation_AppendToListAndMakeActiveWithEventsAndFireCollectionChangedEvent(ViewLocation location)
+ {
+ // Setup
+ using (var view = new ToolWindowTestControl())
+ {
+ var mocks = new MockRepository();
+ var dockingManager = mocks.Stub();
+ dockingManager.Stub(dm => dm.ViewBarClosing += null).IgnoreArguments();
+ dockingManager.Stub(dm => dm.ViewActivated += null).IgnoreArguments();
+ dockingManager.Stub(dm => dm.ViewBarClosing -= null).IgnoreArguments();
+ dockingManager.Stub(dm => dm.ViewActivated -= null).IgnoreArguments();
+ dockingManager.Stub(dm => dm.Dispose());
+ dockingManager.Expect(dm => dm.Add(view, location));
+ dockingManager.Expect(dm => dm.ActivateView(view));
+ mocks.ReplayAll();
+
+ using (var viewList = new ViewList(dockingManager, ViewLocation.Document))
+ {
+ var updateViewNameActionCallCount = 0;
+ viewList.UpdateViewNameAction = v => updateViewNameActionCallCount++;
+
+ var changingEventCount = 0;
+ viewList.ActiveViewChanging += (sender, args) =>
+ {
+ Assert.AreSame(viewList, sender);
+ Assert.AreSame(view, args.View);
+ Assert.IsNull(args.OldView);
+ changingEventCount++;
+ };
+ var changedEventCount = 0;
+ viewList.ActiveViewChanged += (sender, args) =>
+ {
+ Assert.AreSame(viewList, sender);
+ Assert.AreSame(view, args.View);
+ Assert.IsNull(args.OldView);
+ changedEventCount++;
+ };
+ var collectionChangedEventCount = 0;
+ viewList.CollectionChanged += (sender, args) =>
+ {
+ Assert.AreSame(viewList, sender);
+ Assert.AreEqual(NotifyCollectionChangeAction.Add, args.Action);
+ Assert.AreEqual(0, args.Index);
+ Assert.AreSame(view, args.Item);
+ Assert.AreEqual(-1, args.OldIndex);
+ Assert.IsNull(args.OldItem);
+ Assert.IsFalse(args.Cancel);
+ collectionChangedEventCount++;
+ };
+
+ // Call
+ viewList.Add(view, location);
+
+ // Assert
+ Assert.AreEqual(1, viewList.Count);
+ CollectionAssert.AreEqual(new[] { view }, viewList);
+ CollectionAssert.AreEqual(new[] { view }, viewList.AllViews);
+ Assert.AreSame(view, viewList[0]);
+
+ Assert.AreEqual(1, updateViewNameActionCallCount);
+
+ Assert.AreEqual(1, changingEventCount);
+ Assert.AreEqual(1, changedEventCount);
+ Assert.AreEqual(1, collectionChangedEventCount);
+
+ 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 dockingManager = mocks.Stub();
+ var view = mocks.Stub();
+ var viewsToPreadd = new[]
+ {
+ mocks.Stub(),
+ mocks.Stub()
+ };
+ mocks.ReplayAll();
+
+ using (var viewList = new ViewList(dockingManager, 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(ViewLocation.Top)]
+ [TestCase(ViewLocation.Bottom)]
+ [TestCase(ViewLocation.Document)]
+ [TestCase(ViewLocation.Floating)]
+ [TestCase(ViewLocation.Left)]
+ [TestCase(ViewLocation.Right)]
+ public void Add_ViewInAlreadyAddedButNotActive_MakeActiveWithEvents(ViewLocation location)
+ {
+ // Setup
+ using (var view1 = new ToolWindowTestControl())
+ using (var view2 = new ToolWindowTestControl())
+ {
+ var mocks = new MockRepository();
+ var dockingManager = mocks.Stub();
+ dockingManager.Stub(dm => dm.ViewBarClosing += null).IgnoreArguments();
+ dockingManager.Stub(dm => dm.ViewActivated += null).IgnoreArguments();
+ dockingManager.Stub(dm => dm.ViewBarClosing -= null).IgnoreArguments();
+ dockingManager.Stub(dm => dm.ViewActivated -= null).IgnoreArguments();
+ dockingManager.Stub(dm => dm.Dispose());
+ dockingManager.Expect(dm => dm.Add(view2, location));
+ dockingManager.Expect(dm => dm.ActivateView(view2)).Repeat.Twice();
+ dockingManager.Expect(dm => dm.Add(view1, ViewLocation.Document));
+ dockingManager.Expect(dm => dm.ActivateView(view1));
+ mocks.ReplayAll();
+
+ using (var viewList = new ViewList(dockingManager, ViewLocation.Document))
+ {
+ viewList.Add(view2, location);
+ viewList.Add(view1, ViewLocation.Document);
+
+ var updateViewNameActionCallCount = 0;
+ viewList.UpdateViewNameAction = v => updateViewNameActionCallCount++;
+
+ var changingEventCount = 0;
+ viewList.ActiveViewChanging += (sender, args) =>
+ {
+ Assert.AreSame(viewList, sender);
+ Assert.AreSame(view2, args.View);
+ Assert.AreSame(view1, args.OldView);
+ changingEventCount++;
+ };
+ var changedEventCount = 0;
+ viewList.ActiveViewChanged += (sender, args) =>
+ {
+ Assert.AreSame(viewList, sender);
+ Assert.AreSame(view2, args.View);
+ Assert.AreSame(view1, args.OldView);
+ changedEventCount++;
+ };
+ viewList.CollectionChanged += (sender, args) =>
+ {
+ Assert.Fail("View is already added so no collection changes should be sent.");
+ };
+
+ // Call
+ viewList.Add(view2, location);
+
+ // Assert
+ Assert.AreEqual(2, viewList.Count);
+ CollectionAssert.AreEqual(new[] { view2, view1 }, viewList);
+ CollectionAssert.AreEqual(new[] { view2, view1 }, viewList.AllViews);
+ Assert.AreSame(view2, viewList[0]);
+ Assert.AreSame(view1, viewList[1]);
+
+ Assert.AreEqual(0, updateViewNameActionCallCount,
+ "View is already added, therefore no name update should occur.");
+
+ Assert.AreEqual(1, changingEventCount);
+ Assert.AreEqual(1, changedEventCount);
+
+ Assert.AreSame(view2, viewList.ActiveView);
+ }
+
+ mocks.VerifyAll();
+ }
+ }
+
+ [Test]
+ [TestCase(ViewLocation.Top)]
+ [TestCase(ViewLocation.Bottom)]
+ [TestCase(ViewLocation.Document)]
+ [TestCase(ViewLocation.Floating)]
+ [TestCase(ViewLocation.Left)]
+ [TestCase(ViewLocation.Right)]
+ public void Add_ViewAlreadyAddedAndAlreadyActive_ActivateView(ViewLocation location)
+ {
+ // Setup
+ using (var view = new ToolWindowTestControl())
+ {
+ var mocks = new MockRepository();
+ var dockingManager = mocks.Stub();
+ dockingManager.Stub(dm => dm.ViewBarClosing += null).IgnoreArguments();
+ dockingManager.Stub(dm => dm.ViewActivated += null).IgnoreArguments();
+ dockingManager.Stub(dm => dm.ViewBarClosing -= null).IgnoreArguments();
+ dockingManager.Stub(dm => dm.ViewActivated -= null).IgnoreArguments();
+ dockingManager.Stub(dm => dm.Dispose());
+ dockingManager.Expect(dm => dm.Add(view, ViewLocation.Document));
+ dockingManager.Expect(dm => dm.ActivateView(view));
+ mocks.ReplayAll();
+
+ using (var viewList = new ViewList(dockingManager, ViewLocation.Document))
+ {
+ viewList.Add(view);
+
+ viewList.UpdateViewNameAction = v => Assert.Fail("No 'UpdateViewNameAction' should be called.");
+
+ viewList.ActiveViewChanging += (sender, args) =>
+ {
+ Assert.Fail("View is already active, therefore no changes should be broadcasted.");
+ };
+ viewList.ActiveViewChanged += (sender, args) =>
+ {
+ Assert.Fail("View is already active, therefore no changes should be broadcasted.");
+ };
+ viewList.CollectionChanged += (sender, args) =>
+ {
+ Assert.Fail("No collection change event should be fired.");
+ };
+
+ // Call
+ viewList.Add(view, location);
+
+ // Assert
+ Assert.AreEqual(1, viewList.Count);
+ CollectionAssert.AreEqual(new[] { view }, viewList);
+ CollectionAssert.AreEqual(new[] { view }, viewList.AllViews);
+ Assert.AreSame(view, viewList[0]);
+
+ Assert.AreSame(view, viewList.ActiveView);
+ }
+
+ mocks.VerifyAll();
+ }
+ }
+
+ [Test]
+ [TestCase(0)]
+ [TestCase(2)]
+ public void Add_ViewWithoutViewLocation_FireAddCollectionChange(int alreadyAddedViews)
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var dockingManager = mocks.Stub();
+ var view = mocks.Stub();
+ var viewsToPreadd = new[]
+ {
+ mocks.Stub(),
+ mocks.Stub()
+ };
+ mocks.ReplayAll();
+
+ using (var viewList = new ViewList(dockingManager, 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(ViewLocation.Top)]
+ [TestCase(ViewLocation.Bottom)]
+ [TestCase(ViewLocation.Document)]
+ [TestCase(ViewLocation.Floating)]
+ [TestCase(ViewLocation.Left)]
+ [TestCase(ViewLocation.Right)]
+ public void Add_WithoutViewLocation_AppendToAtDefaultLocationListAndMakeActiveWithEventsAndFireCollectionChangedEvent(ViewLocation defaultLocation)
+ {
+ // Setup
+ using (var view1 = new ToolWindowTestControl())
+ using (var view2 = new ToolWindowTestControl())
+ {
+ var mocks = new MockRepository();
+ var dockingManager = mocks.Stub();
+ dockingManager.Stub(dm => dm.ViewBarClosing += null).IgnoreArguments();
+ dockingManager.Stub(dm => dm.ViewActivated += null).IgnoreArguments();
+ dockingManager.Stub(dm => dm.ViewBarClosing -= null).IgnoreArguments();
+ dockingManager.Stub(dm => dm.ViewActivated -= null).IgnoreArguments();
+ dockingManager.Stub(dm => dm.Dispose());
+ dockingManager.Stub(dm => dm.Add(view1, defaultLocation));
+ dockingManager.Stub(dm => dm.ActivateView(view1));
+ dockingManager.Expect(dm => dm.Add(view2, defaultLocation));
+ dockingManager.Expect(dm => dm.ActivateView(view2));
+ mocks.ReplayAll();
+
+ using (var viewList = new ViewList(dockingManager, defaultLocation))
+ {
+ viewList.Add(view1);
+
+ var updateViewNameActionCallCount = 0;
+ viewList.UpdateViewNameAction = v => updateViewNameActionCallCount++;
+
+ var changingEventCount = 0;
+ viewList.ActiveViewChanging += (sender, args) =>
+ {
+ Assert.AreSame(viewList, sender);
+ Assert.AreSame(view2, args.View);
+ Assert.AreSame(view1, args.OldView);
+ changingEventCount++;
+ };
+ var changedEventCount = 0;
+ viewList.ActiveViewChanged += (sender, args) =>
+ {
+ Assert.AreSame(viewList, sender);
+ Assert.AreSame(view2, args.View);
+ Assert.AreSame(view1, args.OldView);
+ changedEventCount++;
+ };
+ var collectionChangedEventCount = 0;
+ viewList.CollectionChanged += (sender, args) =>
+ {
+ Assert.AreSame(viewList, sender);
+ Assert.AreEqual(NotifyCollectionChangeAction.Add, args.Action);
+ Assert.AreEqual(1, args.Index);
+ Assert.AreSame(view2, args.Item);
+ Assert.AreEqual(-1, args.OldIndex);
+ Assert.IsNull(args.OldItem);
+ Assert.IsFalse(args.Cancel);
+ collectionChangedEventCount++;
+ };
+
+ // Call
+ viewList.Add(view2);
+
+ // Assert
+ Assert.AreEqual(2, viewList.Count);
+ CollectionAssert.AreEqual(new[] { view1, view2 }, viewList);
+ CollectionAssert.AreEqual(new[] { view1, view2 }, viewList.AllViews);
+ Assert.AreSame(view2, viewList[1]);
+
+ Assert.AreEqual(1, updateViewNameActionCallCount);
+
+ Assert.AreEqual(1, changingEventCount);
+ Assert.AreEqual(1, changedEventCount);
+ Assert.AreEqual(1, collectionChangedEventCount);
+
+ Assert.AreSame(view2, viewList.ActiveView);
+ }
+
+ mocks.VerifyAll();
+ }
+ }
+
+ [Test]
+ public void Add_WithoutLocationAndListConstructedWithoutDefaultLocation_ThrowInvalidOperationException()
+ {
+ // Setup
+ using (var view = new ToolWindowTestControl())
+ {
+ var mocks = new MockRepository();
+ var dockingManager = mocks.Stub();
+ mocks.ReplayAll();
+
+ using (var viewList = new ViewList(dockingManager, null))
+ {
+ // Call
+ TestDelegate call = () => viewList.Add(view);
+
+ // Assert
+ var message = Assert.Throws(call).Message;
+ Assert.AreEqual("Er is geen standaardlocatie opgegeven. Kan geen documentvenster toevoegen zonder de locatie parameter.", message);
+ }
+
+ mocks.VerifyAll();
+ }
+ }
+
+ [Test]
+ public void Contains_ViewNotInList_ReturnFalse()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var dockingManager = mocks.Stub();
+ mocks.ReplayAll();
+
+ using (var view = new ToolWindowTestControl())
+ using (var viewList = new ViewList(dockingManager, ViewLocation.Document))
+ {
+ // Call
+ var result = viewList.Contains(view);
+
+ // Assert
+ Assert.False(result);
+ }
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Contains_ViewNotInList_ReturnTrue()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var dockingManager = mocks.Stub();
+ mocks.ReplayAll();
+
+ using (var view = new ToolWindowTestControl())
+ using (var viewList = new ViewList(dockingManager, ViewLocation.Document))
+ {
+ viewList.Add(view);
+
+ // Call
+ var result = viewList.Contains(view);
+
+ // Assert
+ Assert.True(result);
+ }
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void GetEnumerator_NoViewsAdded_ReturnEmpty()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var dockingManager = mocks.Stub();
+ mocks.ReplayAll();
+
+ using (var viewList = new ViewList(dockingManager, ViewLocation.Document))
+ {
+ // Call
+ var result = viewList.GetEnumerator();
+
+ // Assert
+ Assert.False(result.MoveNext());
+ }
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void GetEnumerator_ListWithViews_ReturnEnumeratorAcrossAllViews()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var dockingManager = mocks.Stub();
+ mocks.ReplayAll();
+
+ using (var view1 = new ToolWindowTestControl())
+ using (var view2 = new ToolWindowTestControl())
+ using (var view3 = new ToolWindowTestControl())
+ using (var view4 = new ToolWindowTestControl())
+ using (var viewList = new ViewList(dockingManager, ViewLocation.Document))
+ {
+ viewList.Add(view1);
+ viewList.Add(view2);
+ viewList.Add(view3);
+ viewList.Add(view4);
+
+ // Call
+ var result = viewList.GetEnumerator();
+
+ // Assert
+ Assert.True(result.MoveNext());
+ Assert.AreSame(view1, result.Current);
+ Assert.True(result.MoveNext());
+ Assert.AreSame(view2, result.Current);
+ Assert.True(result.MoveNext());
+ Assert.AreSame(view3, result.Current);
+ Assert.True(result.MoveNext());
+ Assert.AreSame(view4, result.Current);
+ Assert.False(result.MoveNext());
+ }
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ [TestCase(ViewLocation.Top)]
+ [TestCase(ViewLocation.Bottom)]
+ [TestCase(ViewLocation.Document)]
+ [TestCase(ViewLocation.Floating)]
+ [TestCase(ViewLocation.Left)]
+ [TestCase(ViewLocation.Right)]
+ public void Insert_WithoutLocation_InsertAtDefaultLocationAndMakeActiveWithEventsAndFireCollectionChange(ViewLocation defaultLocation)
+ {
+ // Setup
+ using (var view1 = new ToolWindowTestControl())
+ using (var view2 = new ToolWindowTestControl())
+ {
+ var mocks = new MockRepository();
+ var dockingManager = mocks.Stub();
+ dockingManager.Stub(dm => dm.ViewBarClosing += null).IgnoreArguments();
+ dockingManager.Stub(dm => dm.ViewActivated += null).IgnoreArguments();
+ dockingManager.Stub(dm => dm.ViewBarClosing -= null).IgnoreArguments();
+ dockingManager.Stub(dm => dm.ViewActivated -= null).IgnoreArguments();
+ dockingManager.Stub(dm => dm.Dispose());
+ dockingManager.Stub(dm => dm.Add(view1, defaultLocation));
+ dockingManager.Stub(dm => dm.ActivateView(view1));
+ dockingManager.Expect(dm => dm.Add(view2, defaultLocation));
+ dockingManager.Expect(dm => dm.ActivateView(view2));
+ mocks.ReplayAll();
+
+ using (var viewList = new ViewList(dockingManager, defaultLocation))
+ {
+ viewList.Add(view1);
+
+ var updateViewNameActionCallCount = 0;
+ viewList.UpdateViewNameAction = v => updateViewNameActionCallCount++;
+
+ var changingEventCount = 0;
+ viewList.ActiveViewChanging += (sender, args) =>
+ {
+ Assert.AreSame(viewList, sender);
+ Assert.AreSame(view2, args.View);
+ Assert.AreSame(view1, args.OldView);
+ changingEventCount++;
+ };
+ var changedEventCount = 0;
+ viewList.ActiveViewChanged += (sender, args) =>
+ {
+ Assert.AreSame(viewList, sender);
+ Assert.AreSame(view2, args.View);
+ Assert.AreSame(view1, args.OldView);
+ changedEventCount++;
+ };
+ var collectionChangedEventCount = 0;
+ viewList.CollectionChanged += (sender, args) =>
+ {
+ Assert.AreSame(viewList, sender);
+ Assert.AreEqual(NotifyCollectionChangeAction.Add, args.Action);
+ Assert.AreEqual(0, args.Index);
+ Assert.AreSame(view2, args.Item);
+ Assert.AreEqual(-1, args.OldIndex);
+ Assert.IsNull(args.OldItem);
+ Assert.IsFalse(args.Cancel);
+ collectionChangedEventCount++;
+ };
+
+ // Call
+ viewList.Insert(0, view2);
+
+ // Assert
+ Assert.AreEqual(2, viewList.Count);
+ CollectionAssert.AreEqual(new[] { view2, view1 }, viewList);
+ CollectionAssert.AreEqual(new[] { view2, view1 }, viewList.AllViews);
+ Assert.AreSame(view2, viewList[0]);
+
+ Assert.AreEqual(1, updateViewNameActionCallCount);
+
+ Assert.AreEqual(1, changingEventCount);
+ Assert.AreEqual(1, changedEventCount);
+ Assert.AreEqual(1, collectionChangedEventCount);
+
+ Assert.AreSame(view2, viewList.ActiveView);
+ }
+
+ mocks.VerifyAll();
+ }
+ }
+
+ [Test]
+ public void Insert_ListConstructedWithoutDefaultLocation_ThrowInvalidOperationException()
+ {
+ // Setup
+ using (var view = new ToolWindowTestControl())
+ {
+ var mocks = new MockRepository();
+ var dockingManager = mocks.Stub();
+ mocks.ReplayAll();
+
+ using (var viewList = new ViewList(dockingManager, null))
+ {
+ // Call
+ TestDelegate call = () => viewList.Insert(0, view);
+
+ // Assert
+ var message = Assert.Throws(call).Message;
+ Assert.AreEqual("Er is geen standaardlocatie opgegeven. Kan geen documentvenster toevoegen zonder de locatie parameter.", message);
+ }
+
+ mocks.VerifyAll();
+ }
+ }
+
+ [Test]
+ [TestCase(0)]
+ [TestCase(2)]
+ public void Insert_ViewWithoutViewLocation_FireAddCollectionChange(int alreadyAddedViews)
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var dockingManager = mocks.Stub();
+ var view = mocks.Stub();
+ var viewsToPreadd = new[]
+ {
+ mocks.Stub(),
+ mocks.Stub()
+ };
+ mocks.ReplayAll();
+
+ using (var viewList = new ViewList(dockingManager, 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 Clear_WithoutViews_FireResetCollectionChanged()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var dockingManager = mocks.Stub();
+ mocks.ReplayAll();
+
+ using (var viewList = new ViewList(dockingManager, 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);
+ }
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Clear_WithViews_FireResetCollectionChangedAndRemoveCollectionChangePerView()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var dockingManager = mocks.Stub();
+ var view1 = mocks.Stub();
+ mocks.ReplayAll();
+
+ using (var viewList = new ViewList(dockingManager, ViewLocation.Document))
+ {
+ viewList.Add(view1);
+
+ 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(view1, 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 dockingManager = mocks.Stub();
+ var view = mocks.Stub();
+ var viewToKeep = mocks.Stub();
+ mocks.ReplayAll();
+
+ using (var viewList = new ViewList(dockingManager, 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]
+ public void Remove_RemovingAddedView_FireRemoveCollectionChange()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var dockingManager = mocks.Stub();
+ var view = mocks.Stub();
+ mocks.ReplayAll();
+
+ using (var viewList = new ViewList(dockingManager, 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 Remove_RemovingViewNotInList_ReturnFalseAndNoCollectionChangedEvents()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var dockingManager = mocks.Stub();
+ var view1 = mocks.Stub();
+ var view2 = mocks.Stub();
+ mocks.ReplayAll();
+
+ using (var viewList = new ViewList(dockingManager, ViewLocation.Document))
+ {
+ viewList.Add(view1);
+
+ viewList.CollectionChanged += (sender, args) =>
+ {
+ Assert.Fail("Shouldn't fire event for removing view not part of list.");
+ };
+
+ // Call
+ var removeResult = viewList.Remove(view2);
+
+ // Assert
+ Assert.False(removeResult);
+ Assert.AreSame(view1, viewList[0]);
+ }
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void RemoveAt_RemovingAddedView_FireRemoveCollectionChange()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var dockingManager = mocks.Stub();
+ var view = mocks.Stub();
+ var anotherView = mocks.Stub();
+ mocks.ReplayAll();
+
+ using (var viewList = new ViewList(dockingManager, 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();
+ }
+
+ [Test]
+ public void IndexOf_ViewNotInList_ReturnMinusOne()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var dockingManager = mocks.Stub();
+ mocks.ReplayAll();
+
+ using (var view = new ToolWindowTestControl())
+ using (var viewList = new ViewList(dockingManager, ViewLocation.Document))
+ {
+ // Call
+ var index = viewList.IndexOf(view);
+
+ // Assert
+ Assert.AreEqual(-1, index);
+ }
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ [TestCase(0)]
+ [TestCase(1)]
+ [TestCase(2)]
+ public void IndexOf_ViewInList_ReturnMinusOne(int expectedViewIndex)
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var dockingManager = mocks.Stub();
+ mocks.ReplayAll();
+
+ using (var view1 = new ToolWindowTestControl())
+ using (var view2 = new ToolWindowTestControl())
+ using (var view3 = new ToolWindowTestControl())
+ using (var viewList = new ViewList(dockingManager, ViewLocation.Document))
+ {
+ var views = new[]
+ {
+ view1,
+ view2,
+ view3
+ };
+ foreach (var view in views)
+ {
+ viewList.Add(view);
+ }
+
+ // Call
+ var index = viewList.IndexOf(views[expectedViewIndex]);
+
+ // Assert
+ Assert.AreEqual(expectedViewIndex, index);
+ }
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void SetToolTip_ViewInList_SetTooltip()
+ {
+ // Setup
+ const string expectedText = "";
+ using (var view = new ToolWindowTestControl())
+ {
+ var mocks = new MockRepository();
+ var dockingManager = mocks.Stub();
+ dockingManager.Stub(dm => dm.ViewBarClosing += null).IgnoreArguments();
+ dockingManager.Stub(dm => dm.ViewActivated += null).IgnoreArguments();
+ dockingManager.Stub(dm => dm.ViewBarClosing -= null).IgnoreArguments();
+ dockingManager.Stub(dm => dm.ViewActivated -= null).IgnoreArguments();
+ dockingManager.Stub(dm => dm.Dispose());
+ dockingManager.Expect(dm => dm.SetToolTip(view, expectedText));
+ dockingManager.Stub(dm => dm.Add(view, ViewLocation.Bottom));
+ dockingManager.Stub(dm => dm.ActivateView(view));
+ mocks.ReplayAll();
+
+ using (var viewList = new ViewList(dockingManager, ViewLocation.Bottom))
+ {
+ viewList.Add(view);
+
+ // Call
+ viewList.SetTooltip(view, expectedText);
+ }
+ // Assert
+ mocks.VerifyAll();
+ }
+ }
+
+ [Test]
+ public void CopyTo_ListWithViews_CopyElementsToTargetArray()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var dockingManager = mocks.Stub();
+ mocks.ReplayAll();
+
+ using (var view1 = new ToolWindowTestControl())
+ using (var view2 = new ToolWindowTestControl())
+ using (var view3 = new ToolWindowTestControl())
+ using (var viewList = new ViewList(dockingManager, ViewLocation.Document))
+ {
+ var views = new[]
+ {
+ view1,
+ view2,
+ view3
+ };
+ foreach (var view in views)
+ {
+ viewList.Add(view);
+ }
+
+ var targetArray = new IView[5];
+
+ // Call
+ viewList.CopyTo(targetArray, 2);
+
+ // Assert
+ CollectionAssert.AreEqual(Enumerable.Repeat(null, 2).Concat(views), targetArray);
+ }
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void SetImage_ViewInList_DockingManagerSetImage()
+ {
+ // Setup
+ using (var view = new ToolWindowTestControl())
+ {
+ var image = Resources.abacus;
+
+ var mocks = new MockRepository();
+ var dockingManager = mocks.Stub();
+ dockingManager.Stub(dm => dm.ViewBarClosing += null).IgnoreArguments();
+ dockingManager.Stub(dm => dm.ViewActivated += null).IgnoreArguments();
+ dockingManager.Stub(dm => dm.ViewBarClosing -= null).IgnoreArguments();
+ dockingManager.Stub(dm => dm.ViewActivated -= null).IgnoreArguments();
+ dockingManager.Stub(dm => dm.Dispose());
+ dockingManager.Stub(dm => dm.Add(view, ViewLocation.Document));
+ dockingManager.Stub(dm => dm.ActivateView(view));
+ dockingManager.Expect(dm => dm.SetImage(view, image));
+ mocks.ReplayAll();
+
+ using (var viewList = new ViewList(dockingManager, ViewLocation.Document))
+ {
+ viewList.Add(view);
+
+ // Call
+ viewList.SetImage(view, image);
+
+
+ }
+ // Assert
+ mocks.VerifyAll(); // Expect calls on IDockingManager
+ }
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.Gui.Test/Forms/ViewManager/ViewResolverTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.Gui.Test/Forms/ViewManager/ViewResolverTest.cs (revision 0)
+++ Core/Common/test/Core.Common.Gui.Test/Forms/ViewManager/ViewResolverTest.cs (revision 1e9f415cb615bf84526faeecb51f9a70498f9ffc)
@@ -0,0 +1,146 @@
+using System;
+using System.Linq;
+
+using Core.Common.Controls.Views;
+using Core.Common.Gui.Forms.ViewManager;
+using Core.Common.Gui.Plugin;
+using Core.Common.Test.TestObjects;
+using Core.Common.Utils;
+
+using NUnit.Framework;
+
+using Rhino.Mocks;
+
+namespace Core.Common.Gui.Test.Forms.ViewManager
+{
+ public class ViewResolverTest
+ {
+ [Test]
+ public void OpeningAViewForAObjectShouldUseNewView()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var dockingManager = mocks.Stub();
+ mocks.ReplayAll();
+
+ var viewList = new ViewList(dockingManager, ViewLocation.Left);
+ var viewResolver = new ViewResolver(viewList, new ViewInfo[]
+ {
+ new ViewInfo
-
- UserControl
-
-
- ToolWindowTestControl.cs
-
-
UserControl
@@ -136,10 +129,6 @@
-
- Designer
- ToolWindowTestControl.cs
-
ResXFileCodeGenerator
Resources.Designer.cs
Fisheye: Tag 1e9f415cb615bf84526faeecb51f9a70498f9ffc refers to a dead (removed) revision in file `Core/Common/test/Core.Common.Test/Gui/ToolWindowTestControl.Designer.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 1e9f415cb615bf84526faeecb51f9a70498f9ffc refers to a dead (removed) revision in file `Core/Common/test/Core.Common.Test/Gui/ToolWindowTestControl.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 1e9f415cb615bf84526faeecb51f9a70498f9ffc refers to a dead (removed) revision in file `Core/Common/test/Core.Common.Test/Gui/ToolWindowTestControl.resx'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 1e9f415cb615bf84526faeecb51f9a70498f9ffc refers to a dead (removed) revision in file `Core/Common/test/Core.Common.Test/Gui/ViewListTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Core/Common/test/Core.Common.Test/TestObjects/TestDockingManager.cs
===================================================================
diff -u -r42ca97fdb85a553c6aac3bfdfe57c7be4af90821 -r1e9f415cb615bf84526faeecb51f9a70498f9ffc
--- Core/Common/test/Core.Common.Test/TestObjects/TestDockingManager.cs (.../TestDockingManager.cs) (revision 42ca97fdb85a553c6aac3bfdfe57c7be4af90821)
+++ Core/Common/test/Core.Common.Test/TestObjects/TestDockingManager.cs (.../TestDockingManager.cs) (revision 1e9f415cb615bf84526faeecb51f9a70498f9ffc)
@@ -3,7 +3,6 @@
using System.Drawing;
using System.Windows.Forms;
using Core.Common.Controls.Views;
-using Core.Common.Gui;
using Core.Common.Gui.Forms.ViewManager;
namespace Core.Common.Test.TestObjects
Index: Core/Plugins/src/Core.Plugins.ProjectExplorer/ProjectExplorer.cs
===================================================================
diff -u -r2dcbaa4e3e89663c926fd0eeaab2141e79b34cad -r1e9f415cb615bf84526faeecb51f9a70498f9ffc
--- Core/Plugins/src/Core.Plugins.ProjectExplorer/ProjectExplorer.cs (.../ProjectExplorer.cs) (revision 2dcbaa4e3e89663c926fd0eeaab2141e79b34cad)
+++ Core/Plugins/src/Core.Plugins.ProjectExplorer/ProjectExplorer.cs (.../ProjectExplorer.cs) (revision 1e9f415cb615bf84526faeecb51f9a70498f9ffc)
@@ -102,10 +102,6 @@
}
}
- ///
- /// Clean up any resources being used.
- ///
- /// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))