Index: Core/Plugins/src/Core.Plugins.CommonTools.Gui/Commands/Charting/ChartViewCommandBase.cs
===================================================================
diff -u -rfefc0cc505a41a79d4643c80335484daf4ca30ce -ra4ab963c024ed8783e21f8fd4b490322f414ea02
--- Core/Plugins/src/Core.Plugins.CommonTools.Gui/Commands/Charting/ChartViewCommandBase.cs (.../ChartViewCommandBase.cs) (revision fefc0cc505a41a79d4643c80335484daf4ca30ce)
+++ Core/Plugins/src/Core.Plugins.CommonTools.Gui/Commands/Charting/ChartViewCommandBase.cs (.../ChartViewCommandBase.cs) (revision a4ab963c024ed8783e21f8fd4b490322f414ea02)
@@ -1,9 +1,14 @@
-using System.Drawing;
+using System;
+using System.Drawing;
using Core.Common.Controls.Swf.Charting;
using Core.Common.Gui;
namespace Core.Plugins.CommonTools.Gui.Commands.Charting
{
+ ///
+ /// Classes derived from this class will have a possibility to obtain the active
+ /// (if any) and the .
+ ///
public abstract class ChartViewCommandBase : GuiCommand
{
public override bool Enabled
@@ -22,6 +27,10 @@
}
}
+ ///
+ /// Gets the currently active view if it is a and
+ /// null otherwise.
+ ///
protected ChartView View
{
get
@@ -32,9 +41,16 @@
}
}
- protected Font GetChangedFontSize(Font font, int pixels)
+ ///
+ /// Changes the size of the with points.
+ ///
+ /// The to modify the size of.
+ /// The change in points to modify the size of by.
+ /// A new instance of with the new size.
+ /// Thrown when modification ends up in a font size <= 0.
+ protected Font GetChangedFontSize(Font font, int points)
{
- return new Font(font.FontFamily, font.Size + pixels, font.Style);
+ return new Font(font.FontFamily, font.SizeInPoints + points, font.Style);
}
}
}
\ No newline at end of file
Index: Core/Plugins/test/Core.Plugins.CommonTools.Gui.Test/Commands/Charting/ChartViewCommandBaseTest.cs
===================================================================
diff -u
--- Core/Plugins/test/Core.Plugins.CommonTools.Gui.Test/Commands/Charting/ChartViewCommandBaseTest.cs (revision 0)
+++ Core/Plugins/test/Core.Plugins.CommonTools.Gui.Test/Commands/Charting/ChartViewCommandBaseTest.cs (revision a4ab963c024ed8783e21f8fd4b490322f414ea02)
@@ -0,0 +1,190 @@
+using System;
+using System.Drawing;
+using Core.Common.Controls.Swf.Charting;
+using Core.Common.Gui;
+using Core.Common.Test.TestObjects;
+using Core.Plugins.CommonTools.Gui.Commands.Charting;
+using NUnit.Framework;
+using Rhino.Mocks;
+
+namespace Core.Plugins.CommonTools.Gui.Test.Commands.Charting
+{
+ [TestFixture]
+ public class ChartViewCommandBaseTest
+ {
+ private MockRepository mocks;
+
+ [SetUp]
+ public void SetUp()
+ {
+ mocks = new MockRepository();
+ }
+
+ [Test]
+ [TestCase(11)]
+ [TestCase(1)]
+ [TestCase(0)]
+ [TestCase(-11)]
+ [TestCase(-5)]
+ public void GetChangedFontSize_StartWithSize12ModifiedWithPoints_ReturnsSmallerFont(int points)
+ {
+ // Setup
+ var command = new TestChartViewCommandBase();
+ var startSize = 12f;
+ var font = new Font(FontFamily.GenericSansSerif, startSize);
+
+ // Call
+ var newFont = command.GetChangedFontSize(font, points);
+
+ // Assert
+ Assert.AreEqual(startSize + points, newFont.SizeInPoints);
+ }
+
+ [Test]
+ [TestCase(-12)]
+ [TestCase(-13)]
+ public void GetChangedFontSize_StartWithSize12ModifiedWithPointsLargerEqualTo12_ThrowsArgumentException(int points)
+ {
+ // Setup
+ var command = new TestChartViewCommandBase();
+ var startSize = 12f;
+ var font = new Font(FontFamily.GenericSansSerif, startSize);
+
+ // Call
+ TestDelegate test = () => command.GetChangedFontSize(font, points);
+
+ // Assert
+ Assert.Throws(test);
+ }
+
+ [Test]
+ public void View_WithoutGui_Null()
+ {
+ // Setup
+ var command = new TestChartViewCommandBase();
+
+ // Call
+ var result = command.GetView();
+
+ // Assert
+ Assert.IsNull(result);
+ }
+
+ [Test]
+ public void View_GuiWithoutDocumentView_ThrowsNullReferenceException()
+ {
+ // Setup
+ var guiMock = mocks.StrictMock();
+ guiMock.Expect(g => g.DocumentViews).Return(null);
+
+ mocks.ReplayAll();
+
+ var command = new TestChartViewCommandBase
+ {
+ Gui = guiMock
+ };
+
+ // Call
+ TestDelegate test = () => command.GetView();
+
+ // Assert
+ Assert.Throws(test);
+
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void View_GuiWithDocumentViewActiveViewNull_CallsActiveViewReturnsNull()
+ {
+ // Setup
+ var guiMock = mocks.StrictMock();
+ var viewListMock = mocks.StrictMock();
+ guiMock.Expect(g => g.DocumentViews).Return(viewListMock);
+ viewListMock.Expect(vl => vl.ActiveView).Return(null);
+
+ mocks.ReplayAll();
+
+ var command = new TestChartViewCommandBase
+ {
+ Gui = guiMock
+ };
+
+ // Call
+ var result = command.GetView();
+
+ // Assert
+ Assert.IsNull(result);
+
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void View_GuiWithDocumentViewActiveViewNotChartView_CallsActiveViewReturnsNull()
+ {
+ // Setup
+ var guiMock = mocks.StrictMock();
+ var viewListMock = mocks.StrictMock();
+ guiMock.Expect(g => g.DocumentViews).Return(viewListMock);
+ viewListMock.Expect(vl => vl.ActiveView).Return(new TestView());
+
+ mocks.ReplayAll();
+
+ var command = new TestChartViewCommandBase
+ {
+ Gui = guiMock
+ };
+
+ // Call
+ var result = command.GetView();
+
+ // Assert
+ Assert.IsNull(result);
+
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void View_GuiWithDocumentViewActiveViewChartView_CallsActiveViewReturnsChartView()
+ {
+ // Setup
+ var expectedView = new ChartView();
+
+ var guiMock = mocks.StrictMock();
+ var viewListMock = mocks.StrictMock();
+ guiMock.Expect(g => g.DocumentViews).Return(viewListMock);
+ viewListMock.Expect(vl => vl.ActiveView).Return(expectedView);
+
+ mocks.ReplayAll();
+
+ var command = new TestChartViewCommandBase
+ {
+ Gui = guiMock
+ };
+
+ // Call
+ var result = command.GetView();
+
+ // Assert
+ Assert.AreSame(expectedView, result);
+
+ mocks.VerifyAll();
+ }
+
+ private class TestChartViewCommandBase : ChartViewCommandBase {
+ public override void Execute(params object[] arguments)
+ {
+ throw new NotImplementedException();
+ }
+
+ public new Font GetChangedFontSize(Font font, int points)
+ {
+ return base.GetChangedFontSize(font, points);
+ }
+
+ public ChartView GetView()
+ {
+ return View;
+ }
+ }
+ }
+}
\ No newline at end of file
Index: Core/Plugins/test/Core.Plugins.CommonTools.Gui.Test/Core.Plugins.CommonTools.Gui.Test.csproj
===================================================================
diff -u -r10671f81a86637fcab2f4a38af58a9899ca1b240 -ra4ab963c024ed8783e21f8fd4b490322f414ea02
--- Core/Plugins/test/Core.Plugins.CommonTools.Gui.Test/Core.Plugins.CommonTools.Gui.Test.csproj (.../Core.Plugins.CommonTools.Gui.Test.csproj) (revision 10671f81a86637fcab2f4a38af58a9899ca1b240)
+++ Core/Plugins/test/Core.Plugins.CommonTools.Gui.Test/Core.Plugins.CommonTools.Gui.Test.csproj (.../Core.Plugins.CommonTools.Gui.Test.csproj) (revision a4ab963c024ed8783e21f8fd4b490322f414ea02)
@@ -76,6 +76,7 @@
+
@@ -94,6 +95,14 @@
{F49BD8B2-332A-4C91-A196-8CCE0A2C7D98}
Core.Common.Utils
+
+ {D749EE4C-CE50-4C17-BF01-9A953028C126}
+ Core.Common.TestUtil
+
+
+ {E0990383-FB2E-47D1-99CD-9B9FA2929E5B}
+ Core.Common.Test
+
{93E73FAB-FAE8-49C6-9ABB-27D24DF761F6}
Core.Plugins.CommonTools.Gui