Index: Application/Application.Ringtoets/Application.Ringtoets.csproj
===================================================================
diff -u -r6e613570fb69ad93ca5fe269e6f48c8f6ceb1bab -r1c526b820be6d88285ac58ff819944b208966f39
--- Application/Application.Ringtoets/Application.Ringtoets.csproj (.../Application.Ringtoets.csproj) (revision 6e613570fb69ad93ca5fe269e6f48c8f6ceb1bab)
+++ Application/Application.Ringtoets/Application.Ringtoets.csproj (.../Application.Ringtoets.csproj) (revision 1c526b820be6d88285ac58ff819944b208966f39)
@@ -601,7 +601,7 @@
xcopy /S /D /Y /Q "$(SolutionDir)\lib\Common\SharpMap\*" .\
xcopy /S /D /Y /Q "$(SolutionDir)\lib\Common\SharpMap.Extensions\*" .\
-copy "$(SolutionDir)\src\DeltaShell\DeltaShell.Core\bin\$(ConfigurationName)\DeltaShell.Core.XmlSerializers.dll" .\
+copy "$(SolutionDir)\Core\Common\src\Core.Common.Base\bin\$(ConfigurationName)\DeltaShell.Core.XmlSerializers.dll" .\
copy "$(SolutionDir)\lib\*.dll" .\
Index: Core/Common/test/Core.Common.DelftTools.Tests/App.config
===================================================================
diff -u
--- Core/Common/test/Core.Common.DelftTools.Tests/App.config (revision 0)
+++ Core/Common/test/Core.Common.DelftTools.Tests/App.config (revision 1c526b820be6d88285ac58ff819944b208966f39)
@@ -0,0 +1,71 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Index: Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/CSV/CsvImportTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/CSV/CsvImportTest.cs (revision 0)
+++ Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/CSV/CsvImportTest.cs (revision 1c526b820be6d88285ac58ff819944b208966f39)
@@ -0,0 +1,76 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using DelftTools.TestUtils;
+using DelftTools.Utils.Csv.Importer;
+using NUnit.Framework;
+
+namespace DelftTools.Tests.Controls.Swf.CSV
+{
+ [TestFixture]
+ public class CsvImportTest
+ {
+ [Test]
+ public void ConvertCsvFile()
+ {
+ var csvToDataTableConverter = new CsvImporter();
+
+ var dataTable = csvToDataTableConverter.SplitToTable(TestHelper.GetTestFilePath("Timeseries.csv"),
+ new CsvSettings
+ {
+ Delimiter = ',',
+ FirstRowIsHeader = true,
+ SkipEmptyLines = true
+ });
+
+ var customDTFormat = (DateTimeFormatInfo) CultureInfo.InvariantCulture.DateTimeFormat.Clone();
+ customDTFormat.FullDateTimePattern = "dd/MM/yyyy";
+
+ var csvMapping = new Dictionary
+ {
+ {
+ new CsvRequiredField("Date time", typeof(DateTime)), new CsvColumnInfo(0, customDTFormat)
+ },
+ {
+ new CsvRequiredField("Value (m AD)", typeof(double)), new CsvColumnInfo(1, new NumberFormatInfo())
+ }
+ };
+
+ var typedDataTable = csvToDataTableConverter.Extract(dataTable, csvMapping);
+
+ Assert.AreEqual(2, typedDataTable.Columns.Count);
+ Assert.AreEqual(4, typedDataTable.Rows.Count);
+ Assert.IsTrue(typedDataTable.Rows[0][0] is DateTime);
+ Assert.AreEqual(10.005, typedDataTable.Rows[0][1]);
+ }
+
+ [Test]
+ public void ParseCsvFileAndFilterColumn()
+ {
+ var csvToDataTableConverter = new CsvImporter();
+
+ var dataTable = csvToDataTableConverter.SplitToTable(TestHelper.GetTestFilePath("Timeseries.csv"),
+ new CsvSettings
+ {
+ Delimiter = ',',
+ FirstRowIsHeader = true,
+ SkipEmptyLines = true
+ });
+
+ var csvMapping = new Dictionary
+ {
+ {
+ new CsvRequiredField("Value (m AD)", typeof(double)), new CsvColumnInfo(1, new NumberFormatInfo())
+ }
+ };
+ var filteredDataTable = csvToDataTableConverter.Extract(dataTable, csvMapping, new[]
+ {
+ new CsvPassIfEqualFilter(0, "14/07/1990")
+ });
+
+ Assert.AreEqual(1, filteredDataTable.Columns.Count);
+ Assert.AreEqual(1, filteredDataTable.Rows.Count);
+ Assert.AreEqual(15.0, filteredDataTable.Rows[0][0]);
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Charting/ChartTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Charting/ChartTest.cs (revision 0)
+++ Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Charting/ChartTest.cs (revision 1c526b820be6d88285ac58ff819944b208966f39)
@@ -0,0 +1,103 @@
+using System;
+using System.IO;
+using DelftTools.Controls.Swf.Charting;
+using DelftTools.Controls.Swf.Charting.Series;
+using DelftTools.TestUtils;
+using DelftTools.Utils.Collections;
+using NUnit.Framework;
+
+namespace DelftTools.Tests.Controls.Swf.Charting
+{
+ [TestFixture]
+ public class ChartTest
+ {
+ [Test]
+ public void AddingSeriesToChartTriggersChartCollectionChanged()
+ {
+ var chart = new Chart();
+ var count = 0;
+
+ ((INotifyCollectionChanged) chart).CollectionChanged += (s, e) => { count++; };
+
+ chart.Series.Add(new AreaChartSeries());
+
+ Assert.AreEqual(1, count);
+ }
+
+ [Test]
+ public void ExportAsImageWorks()
+ {
+ SaveDeleteAndAssertExport("test.png");
+ }
+
+ [Test]
+ public void ExportAsVectorGraphicsImageWorks()
+ {
+ SaveDeleteAndAssertExport("test.svg");
+ }
+
+ [Test]
+ public void ExportAsVectorGraphicsImagesGivesWarningForIgnoringHatchStyle()
+ {
+ var chart = new Chart();
+ var areaSeries = new AreaChartSeries
+ {
+ UseHatch = true
+ };
+ chart.Series.Add(areaSeries);
+
+ TestHelper.AssertLogMessageIsGenerated(() => SaveDeleteAndAssertExport("test.svg", chart), "Hatch style is not supported for exports and will be ignored.", 1);
+ }
+
+ [Test]
+ [ExpectedException(typeof(ArgumentException), ExpectedMessage = "Argument did not contain a filename\r\nParameter name: filename")]
+ public void ExportAsImageThrowsOnIncompleteFileName()
+ {
+ SaveDeleteAndAssertExport(".noname");
+ }
+
+ [Test]
+ [ExpectedException(typeof(ArgumentException), ExpectedMessage = "Extension (.ext) not supported\r\nParameter name: filename")]
+ public void ExportAsImageThrowsOnUnSupportedExtension()
+ {
+ SaveDeleteAndAssertExport("incorrect.ext");
+ }
+
+ [Test]
+ [ExpectedException(typeof(ArgumentException), ExpectedMessage = "Argument should not be null\r\nParameter name: filename")]
+ public void ExportAsImageThrowsOnNullArgument()
+ {
+ SaveDeleteAndAssertExport(null);
+ }
+
+ [Test]
+ [ExpectedException(typeof(ArgumentException), ExpectedMessage = "Argument should have an extension\r\nParameter name: filename")]
+ public void ExportAsImageThrowsOnMissingExtension()
+ {
+ SaveDeleteAndAssertExport("noextension");
+ }
+
+ private static void SaveDeleteAndAssertExport(string exportFileName, IChart chart = null)
+ {
+ try
+ {
+ if (chart == null)
+ {
+ new Chart().ExportAsImage(exportFileName, null, null);
+ }
+ else
+ {
+ chart.ExportAsImage(exportFileName, null, null);
+ }
+ Assert.IsTrue(File.Exists(exportFileName));
+ }
+ finally
+ {
+ if (File.Exists(exportFileName))
+ {
+ File.Delete(exportFileName);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Charting/QuarterViewDateTimeFormatProviderTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Charting/QuarterViewDateTimeFormatProviderTest.cs (revision 0)
+++ Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Charting/QuarterViewDateTimeFormatProviderTest.cs (revision 1c526b820be6d88285ac58ff819944b208966f39)
@@ -0,0 +1,22 @@
+using System;
+using DelftTools.Controls.Swf.Charting;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace DelftTools.Tests.Controls.Swf.Charting
+{
+ [TestFixture]
+ public class QuarterViewDateTimeFormatProviderTest
+ {
+ [Test]
+ public void CheckQuarterViewDateTimeFormatProviderOutput()
+ {
+ var provider = new QuarterNavigatableLabelFormatProvider();
+
+ var minDate = new DateTime(2001, 1, 1);
+ var maxDate = new DateTime(2002, 7, 1);
+
+ provider.GetRangeLabel(minDate, maxDate).Should("Unexpected quarter datetime string.").Be.EqualTo("1st Qtr 2001 till 3rd Qtr 2002");
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Charting/Series/AreaChartSeriesTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Charting/Series/AreaChartSeriesTest.cs (revision 0)
+++ Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Charting/Series/AreaChartSeriesTest.cs (revision 1c526b820be6d88285ac58ff819944b208966f39)
@@ -0,0 +1,47 @@
+using DelftTools.Controls.Swf.Charting.Series;
+using NUnit.Framework;
+
+namespace DelftTools.Tests.Controls.Swf.Charting.Series
+{
+ [TestFixture]
+ public class AreaChartSeriesTest
+ {
+ [Test]
+ public void TestMaximumValueClipping()
+ {
+ const int maximum = 999999;
+ var series = new AreaChartSeries
+ {
+ LineWidth = maximum,
+ PointerSize = maximum,
+ };
+ Assert.AreEqual(maximum, series.LineWidth);
+ Assert.AreEqual(maximum, series.PointerSize);
+
+ series.LineWidth = maximum + 1;
+ series.PointerSize = maximum + 1;
+
+ Assert.AreEqual(maximum, series.LineWidth);
+ Assert.AreEqual(maximum, series.PointerSize);
+ }
+
+ [Test]
+ public void TestMinimumValueClipping()
+ {
+ const int minimum = 0;
+ var series = new AreaChartSeries
+ {
+ LineWidth = minimum,
+ PointerSize = minimum,
+ };
+ Assert.AreEqual(minimum, series.LineWidth);
+ Assert.AreEqual(minimum, series.PointerSize);
+
+ series.LineWidth = minimum - 1;
+ series.PointerSize = minimum - 1;
+
+ Assert.AreEqual(minimum, series.LineWidth);
+ Assert.AreEqual(minimum, series.PointerSize);
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Charting/Series/BarSeriesTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Charting/Series/BarSeriesTest.cs (revision 0)
+++ Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Charting/Series/BarSeriesTest.cs (revision 1c526b820be6d88285ac58ff819944b208966f39)
@@ -0,0 +1,39 @@
+using DelftTools.Controls.Swf.Charting.Series;
+using NUnit.Framework;
+
+namespace DelftTools.Tests.Controls.Swf.Charting.Series
+{
+ [TestFixture]
+ public class BarSeriesTest
+ {
+ [Test]
+ public void TestMaximumValueClipping()
+ {
+ const int maximum = 999999;
+ var series = new BarSeries
+ {
+ LineWidth = maximum
+ };
+ Assert.AreEqual(maximum, series.LineWidth);
+
+ series.LineWidth = maximum + 1;
+
+ Assert.AreEqual(maximum, series.LineWidth);
+ }
+
+ [Test]
+ public void TestMinimumValueClipping()
+ {
+ const int minimum = 0;
+ var series = new BarSeries
+ {
+ LineWidth = minimum,
+ };
+ Assert.AreEqual(minimum, series.LineWidth);
+
+ series.LineWidth = minimum - 1;
+
+ Assert.AreEqual(minimum, series.LineWidth);
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Charting/Series/LineChartSeriesTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Charting/Series/LineChartSeriesTest.cs (revision 0)
+++ Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Charting/Series/LineChartSeriesTest.cs (revision 1c526b820be6d88285ac58ff819944b208966f39)
@@ -0,0 +1,47 @@
+using DelftTools.Controls.Swf.Charting.Series;
+using NUnit.Framework;
+
+namespace DelftTools.Tests.Controls.Swf.Charting.Series
+{
+ [TestFixture]
+ public class LineChartSeriesTest
+ {
+ [Test]
+ public void TestMaximumValueClipping()
+ {
+ const int maximum = 999999;
+ var series = new LineChartSeries
+ {
+ Width = maximum,
+ PointerSize = maximum,
+ };
+ Assert.AreEqual(maximum, series.Width);
+ Assert.AreEqual(maximum, series.PointerSize);
+
+ series.Width = maximum + 1;
+ series.PointerSize = maximum + 1;
+
+ Assert.AreEqual(maximum, series.Width);
+ Assert.AreEqual(maximum, series.PointerSize);
+ }
+
+ [Test]
+ public void TestMinimumValueClipping()
+ {
+ const int minimum = 0;
+ var series = new LineChartSeries
+ {
+ Width = minimum,
+ PointerSize = minimum,
+ };
+ Assert.AreEqual(minimum, series.Width);
+ Assert.AreEqual(minimum, series.PointerSize);
+
+ series.Width = minimum - 1;
+ series.PointerSize = minimum - 1;
+
+ Assert.AreEqual(minimum, series.Width);
+ Assert.AreEqual(minimum, series.PointerSize);
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Charting/Series/PointChartSeriesTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Charting/Series/PointChartSeriesTest.cs (revision 0)
+++ Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Charting/Series/PointChartSeriesTest.cs (revision 1c526b820be6d88285ac58ff819944b208966f39)
@@ -0,0 +1,39 @@
+using DelftTools.Controls.Swf.Charting.Series;
+using NUnit.Framework;
+
+namespace DelftTools.Tests.Controls.Swf.Charting.Series
+{
+ [TestFixture]
+ public class PointChartSeriesTest
+ {
+ [Test]
+ public void TestMaximumValueClipping()
+ {
+ const int maximum = 999999;
+ var series = new PointChartSeries
+ {
+ Size = maximum
+ };
+ Assert.AreEqual(maximum, series.Size);
+
+ series.Size = maximum + 1;
+
+ Assert.AreEqual(maximum, series.Size);
+ }
+
+ [Test]
+ public void TestMinimumValueClipping()
+ {
+ const int minimum = 0;
+ var series = new PointChartSeries
+ {
+ Size = minimum
+ };
+ Assert.AreEqual(minimum, series.Size);
+
+ series.Size = minimum - 1;
+
+ Assert.AreEqual(minimum, series.Size);
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Charting/Series/PolygonChartSeriesTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Charting/Series/PolygonChartSeriesTest.cs (revision 0)
+++ Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Charting/Series/PolygonChartSeriesTest.cs (revision 1c526b820be6d88285ac58ff819944b208966f39)
@@ -0,0 +1,39 @@
+using DelftTools.Controls.Swf.Charting.Series;
+using NUnit.Framework;
+
+namespace DelftTools.Tests.Controls.Swf.Charting.Series
+{
+ [TestFixture]
+ public class PolygonChartSeriesTest
+ {
+ [Test]
+ public void TestMaximumValueClipping()
+ {
+ const int maximum = 999999;
+ var series = new PolygonChartSeries
+ {
+ LineWidth = maximum
+ };
+ Assert.AreEqual(maximum, series.LineWidth);
+
+ series.LineWidth = maximum + 1;
+
+ Assert.AreEqual(maximum, series.LineWidth);
+ }
+
+ [Test]
+ public void TestMinimumValueClipping()
+ {
+ const int minimum = 0;
+ var series = new PolygonChartSeries
+ {
+ LineWidth = minimum
+ };
+ Assert.AreEqual(minimum, series.LineWidth);
+
+ series.LineWidth = minimum - 1;
+
+ Assert.AreEqual(minimum, series.LineWidth);
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Charting/Series/TeeChartSeriesDecoratorTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Charting/Series/TeeChartSeriesDecoratorTest.cs (revision 0)
+++ Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Charting/Series/TeeChartSeriesDecoratorTest.cs (revision 1c526b820be6d88285ac58ff819944b208966f39)
@@ -0,0 +1,19 @@
+using System;
+using System.Linq;
+using DelftTools.Controls.Swf.Charting.Series;
+using NUnit.Framework;
+
+namespace DelftTools.Tests.Controls.Swf.Charting.Series
+{
+ [TestFixture]
+ public class TeeChartSeriesDecoratorTest
+ {
+ [Test]
+ [ExpectedException(typeof(ArgumentException), ExpectedMessage = "Invalid argument for series datasource. Are you passing IEnumerable? IList and IListSource are supported")]
+ public void ThrowExceptionOnSettingInvalidDataSource()
+ {
+ ILineChartSeries lineChartSeries = ChartSeriesFactory.CreateLineSeries();
+ lineChartSeries.DataSource = Enumerable.Range(1, 3);
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Charting/YearViewDateTimeFormatProviderTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Charting/YearViewDateTimeFormatProviderTest.cs (revision 0)
+++ Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Charting/YearViewDateTimeFormatProviderTest.cs (revision 1c526b820be6d88285ac58ff819944b208966f39)
@@ -0,0 +1,24 @@
+using System;
+using DelftTools.Controls.Swf.Charting;
+using NUnit.Framework;
+
+namespace DelftTools.Tests.Controls.Swf.Charting
+{
+ [TestFixture]
+ public class YearViewDateTimeFormatProviderTest
+ {
+ private static readonly YearNavigatableLabelFormatProvider Provider = new YearNavigatableLabelFormatProvider();
+
+ [Test]
+ public void GetLabel()
+ {
+ Assert.AreEqual("1991", Provider.GetLabel(new DateTime(1991, 11, 11), TimeSpan.Zero));
+ }
+
+ [Test]
+ public void GetAxisAnnotation()
+ {
+ Assert.AreEqual("1991 till 2010", Provider.GetRangeLabel(new DateTime(1991, 11, 11), new DateTime(2010, 1, 1)));
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/CustomInputDialogTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/CustomInputDialogTest.cs (revision 0)
+++ Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/CustomInputDialogTest.cs (revision 1c526b820be6d88285ac58ff819944b208966f39)
@@ -0,0 +1,50 @@
+using System.Collections.Generic;
+using System.Windows.Forms;
+using DelftTools.Controls.Swf;
+using NUnit.Framework;
+
+namespace DelftTools.Tests.Controls.Swf
+{
+ [TestFixture]
+ public class CustomInputDialogTest
+ {
+ [Test]
+ public void CreateCustomDialog()
+ {
+ var dialog = new CustomInputDialog();
+ dialog.AddInput("Name");
+ dialog.AddInput("Lastname");
+ dialog.AddInput("Age").ValidationMethod = (o, v) => ((double) v) < 0 ? "Must be positive" : "";
+ dialog.AddInput("Is employee1");
+ dialog.AddInput("Is employee2");
+ dialog.AddInput("Is employee3");
+ dialog.AddInput("Is employee4");
+ dialog.AddInput("Result", DialogResult.Retry);
+ var valueInput = dialog.AddInput("Value", 10.0);
+ valueInput.ToolTip = "Value of item";
+ valueInput.UnitSymbol = "m";
+
+ Assert.AreEqual(10.0, dialog["Value"]);
+ Assert.AreEqual(DialogResult.Retry, dialog["Result"]);
+ }
+
+ [Test]
+ public void CreateCustomDialogWithDropDownBox()
+ {
+ var dialog = new CustomInputDialog();
+ dialog.AddInput("Name");
+ dialog.AddChoice("Occupation", new List
+ {
+ "Construction", "IT", "Management", "Finance"
+ });
+ dialog.AddChoice("Years of experience", new List
+ {
+ 0, 1, 2, 3
+ }).ToolTip = "Number of years experience, choose 3 if 3 or more year";
+
+ Assert.AreEqual("", dialog["Name"]);
+ Assert.AreEqual("Construction", dialog["Occupation"]);
+ Assert.AreEqual(0, dialog["Years of experience"]);
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/DataEditorGenerator/SelfCollapsingGroupboxTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/DataEditorGenerator/SelfCollapsingGroupboxTest.cs (revision 0)
+++ Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/DataEditorGenerator/SelfCollapsingGroupboxTest.cs (revision 1c526b820be6d88285ac58ff819944b208966f39)
@@ -0,0 +1,86 @@
+using System.Windows.Forms;
+using DelftTools.Controls.Swf.DataEditorGenerator;
+using NUnit.Framework;
+
+namespace DelftTools.Tests.Controls.Swf.DataEditorGenerator
+{
+ [TestFixture]
+ public class SelfCollapsingGroupboxTest
+ {
+ [Test]
+ public void OneChildTest()
+ {
+ var box = new SelfCollapsingGroupbox();
+
+ var panel = new FlowLayoutPanel();
+ box.Controls.Add(panel);
+ box.SetChildContainer(panel);
+
+ var child1 = new SelfCollapsingPanel();
+ panel.Controls.Add(child1);
+ box.SubscribeChild(child1);
+
+ Assert.IsTrue(box.Visible);
+
+ child1.Visible = false;
+ Assert.IsFalse(box.Visible);
+ }
+
+ [Test]
+ public void TwoChildrenTest()
+ {
+ var box = new SelfCollapsingGroupbox();
+
+ var panel = new FlowLayoutPanel();
+ box.Controls.Add(panel);
+ box.SetChildContainer(panel);
+
+ var child1 = new SelfCollapsingPanel();
+ panel.Controls.Add(child1);
+ box.SubscribeChild(child1);
+
+ var child2 = new SelfCollapsingPanel();
+ panel.Controls.Add(child2);
+ box.SubscribeChild(child2);
+
+ Assert.IsTrue(box.Visible);
+
+ child1.Visible = false;
+ Assert.IsTrue(box.Visible);
+
+ child2.Visible = false;
+ Assert.IsFalse(box.Visible);
+ }
+
+ [Test]
+ public void AlreadyInvisibleTest()
+ {
+ var box = new SelfCollapsingGroupbox();
+
+ var panel = new FlowLayoutPanel();
+ box.Controls.Add(panel);
+ box.SetChildContainer(panel);
+
+ var child1 = new SelfCollapsingPanel
+ {
+ Visible = false
+ };
+
+ panel.Controls.Add(child1);
+ box.SubscribeChild(child1);
+
+ var child2 = new SelfCollapsingPanel
+ {
+ Visible = false
+ };
+
+ panel.Controls.Add(child2);
+ box.SubscribeChild(child2);
+
+ Assert.IsFalse(box.Visible);
+
+ child1.Visible = true;
+ Assert.IsTrue(box.Visible);
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/FileSystemTreeViewTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/FileSystemTreeViewTest.cs (revision 0)
+++ Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/FileSystemTreeViewTest.cs (revision 1c526b820be6d88285ac58ff819944b208966f39)
@@ -0,0 +1,24 @@
+using System.IO;
+using DelftTools.Controls.Swf;
+using NUnit.Framework;
+
+namespace DelftTools.Tests.Controls.Swf
+{
+ [TestFixture]
+ public class FileSystemTreeViewTest
+ {
+ [Test]
+ public void ExpandTo()
+ {
+ var treeView = new FileSystemTreeView();
+ Assert.IsTrue(treeView.ExpandTo(Path.GetTempPath()));
+ }
+
+ [Test]
+ public void ExpandToWithEmptyString()
+ {
+ var treeView = new FileSystemTreeView();
+ Assert.IsFalse(treeView.ExpandTo(""));
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/FindAndReplaceControlTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/FindAndReplaceControlTest.cs (revision 0)
+++ Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/FindAndReplaceControlTest.cs (revision 1c526b820be6d88285ac58ff819944b208966f39)
@@ -0,0 +1,61 @@
+using DelftTools.Controls.Swf;
+using DelftTools.Utils.Reflection;
+using NUnit.Framework;
+
+namespace DelftTools.Tests.Controls.Swf
+{
+ [TestFixture]
+ public class FindAndReplaceControlTest
+ {
+ [TestCase(true)] // search for third "Test" occurrence (index 23)
+ [TestCase(false)] // search for second "Test" occurrence (index 11)
+ public void FindNextText(bool check2)
+ {
+ var text = "Test text\n Test text2\n Test text2";
+ var findAndReplaceControl = new FindAndReplaceControl
+ {
+ GetTextToSearch = () => text,
+ GetCurrentPosition = () => (!check2) ? 4 : 11,
+ SelectText = (start, length) =>
+ {
+ Assert.AreEqual(check2 ? 23 : 11, start);
+ Assert.AreEqual(4, length);
+ },
+ HighLightText = t => Assert.AreEqual("Test", t)
+ };
+
+ findAndReplaceControl.FindTextBox.Text = "Test";
+
+ TypeUtils.CallPrivateMethod(findAndReplaceControl, "FindNext");
+ }
+
+ [Test]
+ public void ReplaceText()
+ {
+ var text = "Test text\n Test text2\n Test text2";
+ var findAndReplaceControl = new FindAndReplaceControl
+ {
+ GetTextToSearch = () => text,
+ GetCurrentPosition = () => 11,
+ ReplaceText = (start, length, newText) =>
+ {
+ Assert.AreEqual(11, start);
+ Assert.AreEqual(4, length);
+ Assert.AreEqual("New test", newText);
+ },
+ SelectText = (start, length) =>
+ {
+ Assert.AreEqual(23, start);
+ Assert.AreEqual(4, length);
+ },
+ HighLightText = t => Assert.AreEqual("Test", t)
+ };
+
+ findAndReplaceControl.FindTextBox.Text = "Test";
+ findAndReplaceControl.ReplaceTextBox.Text = "New test";
+
+ // replace second "Test" occurrence (index 11) with "New test"
+ TypeUtils.CallPrivateMethod(findAndReplaceControl, "Replace");
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/MessageBoxTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/MessageBoxTest.cs (revision 0)
+++ Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/MessageBoxTest.cs (revision 1c526b820be6d88285ac58ff819944b208966f39)
@@ -0,0 +1,30 @@
+using System.Windows.Forms;
+using DelftTools.Controls.Swf;
+using NUnit.Framework;
+using Rhino.Mocks;
+using MessageBox = DelftTools.Controls.Swf.MessageBox;
+
+namespace DelftTools.Tests.Controls.Swf
+{
+ [TestFixture]
+ public class MessageBoxTest
+ {
+ [Test]
+ public void UseCustomMessageBoxIfDefined()
+ {
+ var mockRepository = new MockRepository();
+ var customMessageBox = mockRepository.StrictMock();
+ customMessageBox.Expect(m => m.Show("text", "caption", MessageBoxButtons.OK)).Return(DialogResult.OK);
+ MessageBox.CustomMessageBox = customMessageBox;
+
+ mockRepository.ReplayAll();
+
+ MessageBox.Show("text", "caption", MessageBoxButtons.OK);
+
+ mockRepository.VerifyAll();
+
+ //don't forget to reset!
+ MessageBox.CustomMessageBox = null;
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Table/TableViewCopyPasteTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Table/TableViewCopyPasteTest.cs (revision 0)
+++ Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Table/TableViewCopyPasteTest.cs (revision 1c526b820be6d88285ac58ff819944b208966f39)
@@ -0,0 +1,290 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.IO;
+using System.Linq;
+using System.Windows.Forms;
+using DelftTools.Controls.Swf.Table;
+using DelftTools.Tests.Controls.Swf.Table.TestClasses;
+using DelftTools.TestUtils;
+using DelftTools.Utils;
+using DevExpress.XtraGrid;
+using NUnit.Framework;
+using Category = NUnit.Framework.CategoryAttribute;
+
+namespace DelftTools.Tests.Controls.Swf.Table
+{
+ [TestFixture]
+ public class TableViewCopyPasteTest
+ {
+ [Test]
+ public void CopyPasteDateTimeTools8628()
+ {
+ using (var tableView = new TableView())
+ {
+ using (var dataset = new DataSet())
+ {
+ using (var dataTable = dataset.Tables.Add())
+ {
+ dataTable.Columns.Add("A", typeof(DateTime));
+ dataTable.Columns.Add("B", typeof(double));
+ dataTable.Rows.Add(new DateTime(2000, 1, 31), 10.0);
+ dataTable.Rows.Add(new DateTime(2000, 2, 1), 15.0);
+
+ tableView.Data = dataTable;
+
+ tableView.SelectRows(new[]
+ {
+ 0,
+ 1
+ }); //select all
+ tableView.CopySelectionToClipboard();
+ dataTable.Clear();
+
+ tableView.SelectRow(0);
+ tableView.PasteClipboardContents();
+
+ Assert.AreEqual(2, dataTable.Rows.Count);
+ Assert.AreEqual(new DateTime(2000, 1, 31), dataTable.Rows[0][0]);
+ Assert.AreEqual(10.0, dataTable.Rows[0][1]);
+ }
+ }
+ }
+ }
+
+ [Test]
+ public void PasteLargeAmountOfDataShouldBeFast()
+ {
+ using (var dataset = new DataSet())
+ {
+ using (var dataTable = dataset.Tables.Add())
+ {
+ dataTable.Columns.Add("A", typeof(DateTime));
+ dataTable.Columns.Add("B", typeof(double));
+
+ var view = new TableView
+ {
+ Data = dataTable
+ };
+
+ var file = TestHelper.GetTestFilePath("TestPasteData.txt");
+ var contents = File.ReadAllText(file);
+ Clipboard.SetText(contents);
+
+ TestHelper.AssertIsFasterThan(17500, view.PasteClipboardContents);
+
+ Assert.Greater(dataTable.Rows.Count, 5);
+ }
+ }
+ }
+
+ [Test]
+ public void PasteDutchDateTimeShouldWorkFineTools8878()
+ {
+ using (var dataset = new DataSet())
+ {
+ using (var dataTable = dataset.Tables.Add())
+ {
+ dataTable.Columns.Add("A", typeof(DateTime));
+ dataTable.Columns.Add("B", typeof(double));
+
+ var view = new TableView
+ {
+ Data = dataTable
+ };
+
+ Clipboard.SetText(File.ReadAllText(TestHelper.GetTestFilePath("TestPasteData_DutchDates.txt")));
+
+ using (CultureUtils.SwitchToCulture("nl-NL"))
+ {
+ view.PasteClipboardContents();
+ }
+
+ var dateTimes = dataTable.AsEnumerable().Select(r => r.Field("A")).ToList();
+
+ Assert.AreEqual(60, dateTimes.Count);
+ Assert.AreEqual(new DateTime(2001, 1, 1), dateTimes.Min());
+ Assert.AreEqual(new DateTime(2001, 3, 1), dateTimes.Max());
+ }
+ }
+ }
+
+ [Test]
+ public void PasteClipboardContentsCanAddRows()
+ {
+ var person = new List
+ {
+ new Person
+ {
+ Age = 12, Name = "Hoi"
+ },
+ new Person
+ {
+ Age = 11, Name = "keers"
+ }
+ };
+ //set two persons in clipboard
+ const string clipBoardContents = "cees anton\t34\r\nsaifon\t66\r\nmartijn\t31\r\n";
+ Clipboard.SetText(clipBoardContents);
+ //setup a tableview
+ var tableView = new TableView
+ {
+ Data = person
+ };
+
+ tableView.PasteClipboardContents();
+
+ Assert.AreEqual("martijn", person[2].Name);
+ Assert.AreEqual(31, person[2].Age);
+ }
+
+ [Test]
+ public void PasteIntoEmptyTableView()
+ {
+ var persons = new List();
+ //set two persons in clipboard
+ const string clipBoardContents = "cees anton\t34\r\nsaifon\t66\r\nmartijn\t31\r\n";
+ Clipboard.SetText(clipBoardContents);
+ //setup a tableview
+ var tableView = new TableView
+ {
+ Data = persons
+ };
+
+ //action!
+ tableView.PasteClipboardContents();
+
+ Assert.AreEqual("martijn", persons[2].Name);
+ Assert.AreEqual(31, persons[2].Age);
+ Assert.AreEqual(3, persons.Count);
+ }
+
+ [Test]
+ public void PasteColumnIntoEmptyTableView()
+ {
+ var persons = new List();
+ //set two persons in clipboard
+ const string clipBoardContents = "1\r\n2\r\n3\r\n";
+ Clipboard.SetText(clipBoardContents);
+ //setup a tableview
+ var tableView = new TableView
+ {
+ Data = persons
+ };
+
+ //action!
+ tableView.PasteClipboardContents();
+
+ Assert.AreEqual(new[]
+ {
+ "1",
+ "2",
+ "3"
+ }, persons.Select(p => p.Name).ToArray());
+ //assert the data is not pasted into the other column
+ Assert.AreEqual(new[]
+ {
+ 0,
+ 0,
+ 0
+ }, persons.Select(p => p.Age).ToArray());
+ }
+
+ [Test]
+ public void PasteClipboardContentsOverwritesExistingRows()
+ {
+ var person = new List
+ {
+ new Person
+ {
+ Age = 12, Name = "Hoi"
+ },
+ new Person
+ {
+ Age = 11, Name = "keers"
+ }
+ };
+ //set two persons in clipboard
+ const string clipBoardContents = "cees anton\t34\r\nsaifon\t66\r\n";
+ Clipboard.SetText(clipBoardContents);
+ //setup a tableview
+ var tableView = new TableView
+ {
+ Data = person
+ };
+
+ tableView.PasteClipboardContents();
+
+ Assert.AreEqual("cees anton", person[0].Name);
+ Assert.AreEqual(34, person[0].Age);
+ Assert.AreEqual("saifon", person[1].Name);
+ Assert.AreEqual(66, person[1].Age);
+ }
+
+ [Test]
+ public void CopySelectionIntoClipBoard()
+ {
+ var table = new DataTable();
+ table.Columns.Add("column1", typeof(string));
+ table.Columns.Add("column2", typeof(string));
+ table.Rows.Add("1", "2");
+ table.Rows.Add("3", "4");
+
+ var tableView = new TableView
+ {
+ Data = table
+ };
+
+ //select two rows
+ tableView.SelectCells(0, 0, 1, 1);
+
+ //action! copy selection to clipboard
+ //tableView.CopySelection
+ tableView.CopySelectionToClipboard();
+
+ Assert.AreEqual("1\t2\r\n3\t4\r\n", Clipboard.GetText());
+ }
+
+ [Test]
+ public void PasteIntoNewRow()
+ {
+ //this test relates to issue 3069...demonstrating a problem paste lines when rowselect is enabled.
+ var table = new DataTable();
+ table.Columns.Add("column1", typeof(string));
+ table.Columns.Add("column2", typeof(string));
+ table.Rows.Add("1", "2");
+ table.Rows.Add("3", "4");
+
+ var tableView = new TableView
+ {
+ Data = table, RowSelect = true
+ };
+
+ const string clipBoardContents = "5\t6\r\n";
+ Clipboard.SetText(clipBoardContents);
+
+ //first select the 1st row
+ tableView.SelectRow(0);
+
+ //add a new row
+ table.Rows.Add();
+
+ //focus on the left cell of the new row
+ tableView.SetFocus(GridControl.NewItemRowHandle, 0);
+
+ tableView.PasteClipboardContents();
+
+ //check a new row was added to the table
+ Assert.AreEqual(3, table.Rows.Count);
+
+ //check that the first row equals the clip board contents
+ var rowView = tableView.CurrentFocusedRowObject as DataRowView;
+ var rowData = (rowView == null) ? null : rowView.Row.ItemArray;
+ Assert.AreEqual(rowData, new object[]
+ {
+ "5",
+ "6"
+ });
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Table/TableViewCsvImportWizardDialogTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Table/TableViewCsvImportWizardDialogTest.cs (revision 0)
+++ Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Table/TableViewCsvImportWizardDialogTest.cs (revision 1c526b820be6d88285ac58ff819944b208966f39)
@@ -0,0 +1,50 @@
+using System.Collections.Generic;
+using System.Data;
+using System.Globalization;
+using DelftTools.Controls.Swf.Table;
+using DelftTools.Utils.Csv.Importer;
+using NUnit.Framework;
+
+namespace DelftTools.Tests.Controls.Swf.Table
+{
+ [TestFixture]
+ public class TableViewCsvImportWizardDialogTest
+ {
+ [Test]
+ public void ImportDataFromClipboard()
+ {
+ var tableView = new TableView();
+ var dataTable = new DataTable();
+ dataTable.Columns.Add("Foo", typeof(int));
+ dataTable.Columns.Add("Bar", typeof(int));
+ tableView.Data = dataTable;
+
+ var dialog = new TableViewCsvImportWizardDialog(tableView, "0\t0\n" +
+ "1\t2\n");
+
+ Assert.AreEqual(0, tableView.RowCount);
+
+ dialog.DoImport(new CsvMappingData
+ {
+ Settings = new CsvSettings
+ {
+ Delimiter = '\t', FirstRowIsHeader = false, SkipEmptyLines = true
+ },
+ Filters = new CsvFilter[0],
+ FieldToColumnMapping = new Dictionary
+ {
+ {
+ new CsvRequiredField("Foo", typeof(int)),
+ new CsvColumnInfo(0, CultureInfo.CurrentCulture.NumberFormat)
+ },
+ {
+ new CsvRequiredField("Bar", typeof(int)),
+ new CsvColumnInfo(1, CultureInfo.CurrentCulture.NumberFormat)
+ }
+ },
+ });
+
+ Assert.AreEqual(2, tableView.RowCount);
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Table/TableViewPasteControllerTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Table/TableViewPasteControllerTest.cs (revision 0)
+++ Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Table/TableViewPasteControllerTest.cs (revision 1c526b820be6d88285ac58ff819944b208966f39)
@@ -0,0 +1,511 @@
+using System;
+using System.ComponentModel;
+using System.Data;
+using System.Linq;
+using System.Windows.Forms;
+using DelftTools.Controls;
+using DelftTools.Controls.Swf.Editors;
+using DelftTools.Controls.Swf.Table;
+using DelftTools.Tests.Controls.Swf.Table.TestClasses;
+using NUnit.Framework;
+
+namespace DelftTools.Tests.Controls.Swf.Table
+{
+ [TestFixture]
+ public class TableViewPasteControllerTest
+ {
+ [Test]
+ public void PasteFailsOnSortedColumn()
+ {
+ TableView tableView = GetTableViewWithTwoStringColumnsAndOneRow();
+
+ //hook up a copy paste controller
+ var tableViewCopyPasteController = new TableViewPasteController(tableView);
+
+ //sort on the second column
+ tableView.Columns[1].SortOrder = SortOrder.Ascending;
+
+ //setup eventhandler for failed paste checking error message
+ int callCount = 0;
+ tableViewCopyPasteController.PasteFailed += (s, e) =>
+ {
+ Assert.AreEqual("Cannot paste into sorted column",
+ e.Value);
+ callCount++;
+ };
+ //action! paste in the first column..second column is hit so should fail
+ tableView.SelectCells(0, 0, 0, 0);
+ tableViewCopyPasteController.PasteLines(new[]
+ {
+ "kaas\tmelk"
+ });
+
+ //we should have failed
+ Assert.AreEqual(1, callCount);
+ }
+
+ [Test]
+ public void PasteFailsInFilterGrid()
+ {
+ TableView tableView = GetTableViewWithTwoStringColumnsAndOneRow();
+
+ //hook up a copy paste controller
+ var tableViewCopyPasteController = new TableViewPasteController(tableView);
+
+ //filter first column
+ tableView.Columns[0].FilterString = "[Name] Like 'Jaap%'";
+
+ //setup eventhandler for failed paste checking error message
+ int callCount = 0;
+ tableViewCopyPasteController.PasteFailed += (s, e) =>
+ {
+ Assert.AreEqual("Cannot paste into filtered tableview.",
+ e.Value);
+ callCount++;
+ };
+
+ //action! paste in the first column..
+ tableView.SelectCells(0, 0, 0, 0);
+ tableViewCopyPasteController.PasteLines(new[]
+ {
+ "kaas"
+ });
+
+ //we should have failed
+ Assert.AreEqual(1, callCount);
+ }
+
+ [Test]
+ public void PasteDoesNotAddNewRowsToSortedTableView()
+ {
+ TableView tableView = GetTableViewWithTwoStringColumnsAndOneRow();
+
+ //hook up a copy paste controller
+ var tableViewCopyPasteController = new TableViewPasteController(tableView);
+
+ //select the first cell of the second column
+ tableView.SelectCells(0, 1, 0, 1);
+ //sort fist column
+ tableView.Columns[0].SortOrder = SortOrder.Ascending;
+
+ //action paste a possible 3 lines
+ tableViewCopyPasteController.PasteLines(new[]
+ {
+ "kaas\tmelk",
+ "noot\tmies",
+ "appel\tflap"
+ });
+
+ //assert rowcount is still one..no new rows are added on a sorted grid
+ Assert.AreEqual(1, tableView.RowCount);
+ //make sure we did something
+ Assert.AreEqual("kaas", tableView.GetCellValue(0, 1));
+ }
+
+ [Test]
+ public void PasteDataWithEmptyLinesIsMaintained()
+ {
+ var list = new BindingList()
+ {
+ new Person
+ {
+ Name = "jan", Age = 25
+ },
+ new Person
+ {
+ Name = "fon", Age = 33
+ },
+ new Person
+ {
+ Name = "peer", Age = 25
+ },
+ new Person
+ {
+ Name = "fo", Age = 33
+ }
+ };
+
+ var tableView = new TableView
+ {
+ Data = list
+ };
+
+ //select all cells in first column
+ tableView.SelectCells(0, 0, 3, 0);
+
+ //hook up a copy paste controller
+ var tableViewCopyPasteController = new TableViewPasteController(tableView);
+ //this should set the first column to kees,anton,kees,anton
+ Clipboard.SetText("kees\r\nanton\r\n\r\npeer");
+
+ tableViewCopyPasteController.PasteClipboardContents();
+ //asert the names are now like this
+ Assert.AreEqual(new[]
+ {
+ "kees",
+ "anton",
+ "",
+ "peer"
+ }, list.Select(p => p.Name).ToArray());
+ }
+
+ [Test]
+ public void PasteFillsSelection()
+ {
+ var list = new BindingList()
+ {
+ new Person
+ {
+ Name = "jan", Age = 25
+ },
+ new Person
+ {
+ Name = "fon", Age = 33
+ },
+ new Person
+ {
+ Name = "peer", Age = 25
+ },
+ new Person
+ {
+ Name = "fo", Age = 33
+ }
+ };
+
+ var tableView = new TableView
+ {
+ Data = list
+ };
+
+ //select all cells in first column
+ tableView.SelectCells(0, 0, 3, 0);
+
+ //hook up a copy paste controller
+ var tableViewCopyPasteController = new TableViewPasteController(tableView);
+ //this should set the first column to kees,anton,kees,anton
+ tableViewCopyPasteController.PasteLines(new[]
+ {
+ "kees",
+ "anton"
+ });
+
+ //asert the names are now like this
+ Assert.AreEqual(new[]
+ {
+ "kees",
+ "anton",
+ "kees",
+ "anton"
+ }, list.Select(p => p.Name).ToArray());
+ }
+
+ [Test]
+ public void PasteFailsIntoNonSquareSelection()
+ {
+ var list = new BindingList()
+ {
+ new Person
+ {
+ Name = "jan", Age = 25
+ },
+ new Person
+ {
+ Name = "fon", Age = 33
+ },
+ new Person
+ {
+ Name = "peer", Age = 25
+ },
+ new Person
+ {
+ Name = "fo", Age = 33
+ }
+ };
+
+ var tableView = new TableView
+ {
+ Data = list
+ };
+ //make a diagonal selection
+ tableView.SelectedCells.Add(new TableViewCell(0, tableView.Columns.FirstOrDefault(c => c.DisplayIndex == 0)));
+ tableView.SelectedCells.Add(new TableViewCell(1, tableView.Columns.FirstOrDefault(c => c.DisplayIndex == 1)));
+
+ var tableViewCopyPasteController = new TableViewPasteController(tableView);
+ int callCount = 0;
+ tableViewCopyPasteController.PasteFailed += (s, e) =>
+ {
+ callCount++;
+ Assert.AreEqual(
+ "Cannot paste into non rectangular selection",
+ e.Value);
+ };
+ //this should a paste failed event
+ tableViewCopyPasteController.PasteLines(new[]
+ {
+ "kees",
+ "anton"
+ });
+
+ Assert.AreEqual(1, callCount);
+ }
+
+ [Test]
+ public void CopyPasteEnumInBindingList()
+ {
+ var list = new BindingList
+ {
+ new ClassWithEnum
+ {
+ Type = FruitType.Banaan
+ },
+ new ClassWithEnum
+ {
+ Type = FruitType.Peer
+ }
+ };
+ var tableView = new TableView
+ {
+ Data = list
+ };
+
+ var editor = new ComboBoxTypeEditor
+ {
+ Items = Enum.GetValues(typeof(FruitType))
+ };
+ tableView.Columns[0].Editor = editor;
+
+ var tableViewCopyPasteController = new TableViewPasteController(tableView);
+ //select 2nd row
+ tableView.SelectCells(1, 0, 1, 0);
+
+ //paste twee bananen en een peer ;)
+ tableViewCopyPasteController.PasteLines(new[]
+ {
+ "Banaan",
+ "Banaan",
+ "Peer"
+ });
+
+ //we should have 3 bananas and a pear
+ Assert.AreEqual("Banaan", "Banaan", "Banaan", "Peer", list.Select(c => c.Type).ToArray());
+ //WindowsFormsTestHelper.ShowModal(tableView);
+ }
+
+ [Test]
+ public void PasteTakesInvisibleColumnsIntoAccount()
+ {
+ //if a possible paste is too big it is important to not exceed the visiblecolcount - 1
+ var list = new BindingList()
+ {
+ new Person
+ {
+ Name = "jan", Age = 25
+ },
+ new Person
+ {
+ Name = "fon", Age = 33
+ },
+ new Person
+ {
+ Name = "peer", Age = 25
+ },
+ new Person
+ {
+ Name = "fo", Age = 33
+ }
+ };
+
+ var tableView = new TableView
+ {
+ Data = list
+ };
+ //hide the age column
+ tableView.Columns[1].Visible = false;
+ //select top left
+ tableView.SelectCells(0, 0, 0, 0);
+ var tableViewCopyPasteController = new TableViewPasteController(tableView);
+
+ //paste some non sense
+ tableViewCopyPasteController.PasteLines(new[]
+ {
+ "kees\tkan\twel"
+ });
+
+ //first person should be kees now
+ Assert.AreEqual("kees", list[0].Name);
+ }
+
+ [Test]
+ public void PasteIntoGridBoundToDataTable()
+ {
+ var tableWithTwoStrings = new DataTable();
+ tableWithTwoStrings.Columns.Add("A", typeof(string));
+ tableWithTwoStrings.Columns.Add("B", typeof(string));
+ tableWithTwoStrings.Rows.Add("a", "b");
+
+ var tableView = new TableView
+ {
+ Data = tableWithTwoStrings
+ };
+
+ Clipboard.SetText(string.Format("{0}\t{1}" + Environment.NewLine + "{0}\t{1}", "oe", "oe1"));
+
+ tableView.PasteClipboardContents();
+
+ //WindowsFormsTestHelper.ShowModal(tableView);
+
+ //should overwrite existing row and add another one
+ Assert.AreEqual(2, tableWithTwoStrings.Rows.Count);
+ Assert.AreEqual("oe", tableWithTwoStrings.Rows[0][0]);
+ Assert.AreEqual("oe1", tableWithTwoStrings.Rows[0][1]);
+ Assert.AreEqual("oe", tableWithTwoStrings.Rows[1][0]);
+ Assert.AreEqual("oe1", tableWithTwoStrings.Rows[1][1]);
+ }
+
+ [Test]
+ public void PastingIntoReadOnlyCellsDoesNotChangeTheValues()
+ {
+ var tableWithTwoStrings = new DataTable();
+ tableWithTwoStrings.Columns.Add("A", typeof(string));
+ tableWithTwoStrings.Columns.Add("B", typeof(string));
+ tableWithTwoStrings.Rows.Add("a", "b");
+
+ var tableView = new TableView
+ {
+ Data = tableWithTwoStrings
+ };
+ //values in the first column are read only
+ tableView.ReadOnlyCellFilter = delegate(TableViewCell cell) { return cell.Column.AbsoluteIndex == 0; };
+
+ //select top row
+ tableView.SelectCells(0, 0, 0, 1);
+
+ var tableViewCopyPasteController = new TableViewPasteController(tableView);
+
+ //paste some non sense.
+ tableViewCopyPasteController.PasteLines(new[]
+ {
+ "c\td"
+ });
+
+ //only column b should have changed
+ Assert.AreEqual("a", tableWithTwoStrings.Rows[0][0]);
+ Assert.AreEqual("d", tableWithTwoStrings.Rows[0][1]);
+ }
+
+ [Test]
+ public void PasteIntoARowSelection()
+ {
+ var tableWithTwoStrings = new DataTable();
+ tableWithTwoStrings.Columns.Add("A", typeof(string));
+ tableWithTwoStrings.Columns.Add("B", typeof(string));
+ tableWithTwoStrings.Rows.Add("a", "b");
+
+ var tableView = new TableView
+ {
+ Data = tableWithTwoStrings
+ };
+ var tableViewCopyPasteController = new TableViewPasteController(tableView);
+
+ //select top row
+ tableView.SelectCells(0, 0, 0, 1);
+
+ //paste some non sense.
+ tableViewCopyPasteController.PasteLines(new[]
+ {
+ "c"
+ });
+
+ //first line should now be [c c]
+ Assert.AreEqual("c", tableWithTwoStrings.Rows[0][0]);
+ Assert.AreEqual("c", tableWithTwoStrings.Rows[0][1]);
+ }
+
+ [Test]
+ public void UseValidatorToIgnorePaste()
+ {
+ var tableView = new TableView();
+ var tableWithTwoStrings = new DataTable();
+ tableWithTwoStrings.Columns.Add("Name", typeof(string));
+ tableWithTwoStrings.Columns.Add("B", typeof(string));
+ tableWithTwoStrings.Rows.Add("a", "b");
+ tableView.Data = tableWithTwoStrings;
+
+ tableView.InputValidator += TableViewEditorValidator;
+
+ var tableViewCopyPasteController = new TableViewPasteController(tableView);
+ Assert.AreEqual("b", tableWithTwoStrings.Rows[0][1]);
+
+ //select top right cell
+ tableView.SelectCells(0, 1, 0, 1);
+
+ // paste "c" and check result
+ tableViewCopyPasteController.PasteLines(new[]
+ {
+ "c"
+ });
+ Assert.AreEqual("c", tableWithTwoStrings.Rows[0][1]);
+
+ // check paste of d fails
+ tableViewCopyPasteController.PasteLines(new[]
+ {
+ "d"
+ });
+ Assert.AreEqual("c", tableWithTwoStrings.Rows[0][1]);
+ }
+
+ [Test]
+ public void UseValidatorToIgnoreRow()
+ {
+ var tableView = new TableView();
+ var dataTable = new DataTable();
+ dataTable.Columns.Add("Alpha", typeof(string));
+ dataTable.Columns.Add("Numeric", typeof(int));
+ dataTable.Rows.Add("a", 1);
+ tableView.Data = dataTable;
+
+ tableView.PasteController.PasteBehaviour = TableViewPasteBehaviourOptions.SkipRowWhenValueIsInvalid;
+ tableView.InputValidator = (c, v) =>
+ {
+ if (c.Column.AbsoluteIndex == 0 && (v.ToString() == "b"))
+ {
+ return new Utils.Tuple("b not allowed", false);
+ }
+
+ return new Utils.Tuple("", true);
+ };
+
+ var tableViewCopyPasteController = new TableViewPasteController(tableView);
+ Assert.AreEqual(1, dataTable.Rows[0][1]);
+
+ //select top left cell
+ tableView.SelectCells(1, 0, 0, 0);
+
+ // paste "c" and check result
+ tableViewCopyPasteController.PasteLines(new[]
+ {
+ "b\t2",
+ "c\t3"
+ });
+ Assert.AreEqual(2, dataTable.Rows.Count);
+ Assert.AreEqual("c", dataTable.Rows[1][0]);
+ }
+
+ private static TableView GetTableViewWithTwoStringColumnsAndOneRow()
+ {
+ var tableView = new TableView();
+ var tableWithTwoStrings = new DataTable();
+ tableWithTwoStrings.Columns.Add("Name", typeof(string));
+ tableWithTwoStrings.Columns.Add("B", typeof(string));
+ tableWithTwoStrings.Rows.Add("a", "b");
+ tableView.Data = tableWithTwoStrings;
+ return tableView;
+ }
+
+ private static Utils.Tuple TableViewEditorValidator(TableViewCell tableViewCell, object value)
+ {
+ // do not accept "d"
+ return ((string) value).Contains("d") ? new Utils.Tuple("", false) : new Utils.Tuple("", true);
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Table/TableViewTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Table/TableViewTest.cs (revision 0)
+++ Core/Common/test/Core.Common.DelftTools.Tests/Controls/Swf/Table/TableViewTest.cs (revision 1c526b820be6d88285ac58ff819944b208966f39)
@@ -0,0 +1,2044 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Globalization;
+using System.IO;
+using System.Linq;
+using System.Threading;
+using System.Windows.Forms;
+using DelftTools.Controls;
+using DelftTools.Controls.Swf.Editors;
+using DelftTools.Controls.Swf.Table;
+using DelftTools.Tests.Controls.Swf.Table.TestClasses;
+using DelftTools.TestUtils;
+using DelftTools.Utils.Collections.Generic;
+using DelftTools.Utils.Globalization;
+using DelftTools.Utils.Reflection;
+using DevExpress.XtraEditors.Repository;
+using DevExpress.XtraGrid.Columns;
+using DevExpress.XtraGrid.Views.Grid;
+using DevExpress.XtraGrid.Views.Grid.ViewInfo;
+using NUnit.Framework;
+using Rhino.Mocks;
+using SharpTestsEx;
+using Category = NUnit.Framework.CategoryAttribute;
+
+namespace DelftTools.Tests.Controls.Swf.Table
+{
+ [TestFixture]
+ public class TableViewTest
+ {
+ [Test]
+ public void PinColumns()
+ {
+ using (var dataset = new DataSet())
+ {
+ using (var dataTable = dataset.Tables.Add())
+ {
+ dataTable.Columns.Add("A", typeof(double));
+ dataTable.Columns.Add("B", typeof(double));
+ dataTable.Columns.Add("C", typeof(double));
+ dataTable.Columns.Add("D", typeof(double));
+ dataTable.Columns.Add("E", typeof(double));
+
+ dataTable.Rows.Add(1, 2, 3, 4, 5);
+ dataTable.Rows.Add(6, 7, 8, 9, 10);
+ dataTable.Rows.Add(11, 12, 13, 14, 15);
+ dataTable.Rows.Add(16, 17, 18, 19, 20);
+ dataTable.Rows.Add(21, 22, 23, 24, 25);
+
+ var tableView = new TableView
+ {
+ Data = dataTable
+ };
+
+ var column0 = tableView.Columns[0];
+ var column1 = tableView.Columns[1];
+ var column3 = tableView.Columns[3];
+ var column4 = tableView.Columns[4];
+
+ column3.ReadOnly = true;
+
+ var index3 = column3.DisplayIndex;
+ var index4 = column4.DisplayIndex;
+
+ column3.Pinned = true;
+ column4.Pinned = true;
+
+ column3.Pinned = false;
+
+ // expect original index + pinned column 4
+ Assert.AreEqual(index3 + 1, column3.DisplayIndex);
+
+ column4.Pinned = false;
+
+ // expect original indices (no pinned columns)
+ Assert.AreEqual(index3, column3.DisplayIndex);
+ Assert.AreEqual(index4, column4.DisplayIndex);
+
+ column0.Pinned = true;
+ column1.Pinned = true;
+ Assert.AreEqual(0, column0.DisplayIndex, "display index of first pinned column");
+ Assert.AreEqual(1, column1.DisplayIndex, "display index of second pinned column");
+
+ column0.Pinned = false;
+ Assert.AreEqual(1, column0.DisplayIndex, "display index of first unpinned column");
+ Assert.AreEqual(0, column1.DisplayIndex, "display index of pinned column");
+ }
+ }
+ }
+
+ [Test]
+ public void FilterIntegerValues()
+ {
+ var tableView = new TableView
+ {
+ Data = new[]
+ {
+ 1,
+ 2,
+ 3,
+ 4,
+ 5
+ },
+ ReadOnly = true
+ };
+
+ int callCount = 0;
+
+ tableView.ColumnFilterChanged += (s, e) => { callCount++; };
+
+ tableView.Columns[0].FilterString = "Column > 2";
+
+ Assert.AreEqual(1, callCount);
+ Assert.AreEqual(3, tableView.RowCount);
+ }
+
+ [Test]
+ public void EmptyTableViewHasNoFocusedCell()
+ {
+ var tableView = new TableView();
+ var cell = TypeUtils.CallPrivateMethod(tableView, "GetFocusedCell");
+ Assert.AreEqual(null, cell);
+ }
+
+ [Test]
+ public void TableViewWithNoDataHasNoFocusedCell()
+ {
+ var tableView = new TableView
+ {
+ Data = new List()
+ };
+ var cell = TypeUtils.CallPrivateMethod(tableView, "GetFocusedCell");
+ Assert.AreEqual(null, cell);
+ }
+
+ [Test]
+ public void DefaultFocusedCellIsTopLeft()
+ {
+ //tableview with a single row
+ var tableView = new TableView
+ {
+ Data = new List
+ {
+ new Person
+ {
+ Age = 10, Name = "Piet"
+ }
+ }
+ };
+
+ var cell = TypeUtils.CallPrivateMethod(tableView, "GetFocusedCell");
+
+ Assert.AreEqual(0, cell.Column.DisplayIndex);
+ Assert.AreEqual(0, cell.RowIndex);
+ }
+
+ [Test]
+ public void TableViewShouldUseDefaultValuesWhenDeleting()
+ {
+ using (var dataset = new DataSet())
+ {
+ using (var dataTable = dataset.Tables.Add())
+ {
+ dataTable.Columns.Add("A", typeof(double));
+ dataTable.Columns.Add("B", typeof(double));
+ dataTable.Columns.Add("C", typeof(double));
+
+ dataTable.Rows.Add(1, 2, 3);
+ dataTable.Rows.Add(4, 5, 6);
+ dataTable.Rows.Add(7, 8, 9);
+ dataTable.Rows.Add(10, 11, 12);
+
+ var tableView = new TableView
+ {
+ Data = dataTable
+ };
+
+ tableView.Columns[1].ReadOnly = false;
+ tableView.Columns[1].DefaultValue = 99.9;
+ tableView.Columns[2].ReadOnly = false;
+ tableView.Columns[2].DefaultValue = double.NaN;
+
+ tableView.AllowColumnSorting = false;
+ tableView.AllowColumnFiltering = false;
+
+ tableView.SelectCells(1, 1, 1, 2);
+ tableView.DeleteCurrentSelection();
+
+ var secondIndexValue = (double) tableView.GetCellValue(1, 1);
+ Assert.AreEqual(99.9, secondIndexValue, "the deleted double column value becomes the given default value.");
+ var thirdIndexValue = (double) tableView.GetCellValue(1, 2);
+ Assert.AreEqual(double.NaN, thirdIndexValue, "the deleted double column value becomes the given default value.");
+ }
+ }
+ }
+
+ [Test] //devexpress code modified to prevent pascal casing to be split into words
+ public void TableViewShouldUpdateColums()
+ {
+ var table = new DataTable("tablename");
+ var view = new TableView
+ {
+ Data = table
+ };
+ //view.Show();
+ var column = new DataColumn("testName", typeof(double))
+ {
+ Caption = "testCaption"
+ };
+ table.Columns.Add(column);
+ Assert.AreEqual(1, view.Columns.Count);
+ Assert.AreEqual("testName", view.Columns[0].Name);
+ Assert.AreEqual("testCaption", view.Columns[0].Caption);
+
+ column.Caption = "newTestCaption";
+ view.ResetBindings();
+
+ Assert.AreEqual("newTestCaption", view.Columns[0].Caption);
+ }
+
+ [Test]
+ public void FilterDateTimeColumn()
+ {
+ var oldCulture = Thread.CurrentThread.CurrentCulture;
+ Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
+
+ var tableView = new TableView();
+ var table = new DataTable();
+
+ table.Columns.Add("A", typeof(DateTime));
+ table.Columns.Add("B", typeof(double));
+
+ var row = table.NewRow();
+
+ var dateTime = DateTime.Now;
+ var dateTimeMinus1Day = dateTime - new TimeSpan(1, 0, 0, 0);
+ var dateTimePlus1Day = dateTime.AddDays(1);
+
+ row["A"] = dateTime;
+ row["B"] = 0;
+
+ table.Rows.Add(row);
+ tableView.Data = table;
+
+ tableView.SetColumnFilter("A", string.Format("[A] >= #{0}# And [A] < #{1}#", dateTimeMinus1Day, dateTimePlus1Day));
+
+ Assert.AreEqual(1, tableView.RowCount);
+
+ Thread.CurrentThread.CurrentCulture = oldCulture;
+ }
+
+ [Test]
+ public void SetTextToTableViewWithDateTimeColumnUsCulture()
+ {
+ var oldCulture = Thread.CurrentThread.CurrentCulture;
+ var specificCulture = CultureInfo.CreateSpecificCulture("en-US");
+ specificCulture.NumberFormat.NumberGroupSeparator = ",";
+ specificCulture.NumberFormat.NumberDecimalSeparator = ".";
+
+ Thread.CurrentThread.CurrentCulture = specificCulture;
+
+ var tableView = new TableView();
+
+ var table = new DataTable();
+
+ table.Columns.Add("A", typeof(DateTime));
+ table.Columns.Add("B", typeof(double));
+ var row = table.NewRow();
+ row["A"] = DateTime.Now;
+ row["B"] = 0;
+ table.Rows.Add(row);
+ tableView.Data = table;
+
+ tableView.SetCellValue(0, 0, "2010/11/18 01:02:03");
+ var dateTime = DateTime.Parse(tableView.GetCellValue(0, 0).ToString());
+ Assert.AreEqual(new DateTime(2010, 11, 18, 01, 02, 03), dateTime);
+
+ tableView.SetCellValue(0, 1, "1,234.5");
+ var value = double.Parse(tableView.GetCellValue(0, 1).ToString());
+
+ Assert.AreEqual(1234.5, value, "Expects uncustomized en-US number formatting; " +
+ "If this fails, please check if local number format for en-US culture was modified.");
+
+ Thread.CurrentThread.CurrentCulture = oldCulture;
+ }
+
+ [Test]
+ public void SetTextToTableViewWithDateTimeColumnNlCulture()
+ {
+ var oldCulture = Thread.CurrentThread.CurrentCulture;
+ var specificCulture = CultureInfo.CreateSpecificCulture("nl-NL");
+ specificCulture.NumberFormat.NumberGroupSeparator = ".";
+ specificCulture.NumberFormat.NumberDecimalSeparator = ",";
+
+ Thread.CurrentThread.CurrentCulture = specificCulture;
+
+ var tableView = new TableView();
+
+ var table = new DataTable();
+
+ table.Columns.Add("A", typeof(DateTime));
+ table.Columns.Add("B", typeof(double));
+ var row = table.NewRow();
+ row["A"] = DateTime.Now;
+ row["B"] = 0;
+ table.Rows.Add(row);
+ tableView.Data = table;
+
+ tableView.SetCellValue(0, 0, "2010/11/18 01:02:03");
+ var dateTime = DateTime.Parse(tableView.GetCellValue(0, 0).ToString());
+ Assert.AreEqual(new DateTime(2010, 11, 18, 01, 02, 03), dateTime);
+
+ tableView.SetCellValue(0, 1, "1.234,5");
+
+ var value = double.Parse(tableView.GetCellValue(0, 1).ToString());
+
+ Assert.AreEqual(1234.5, value);
+
+ Thread.CurrentThread.CurrentCulture = oldCulture;
+ }
+
+ [Test]
+ public void ExportToCsv()
+ {
+ var tableView = new TableView();
+
+ var table = new DataTable();
+
+ table.Columns.Add("A", typeof(DateTime));
+ table.Columns.Add("B", typeof(int));
+ for (int i = 0; i < 50; i++)
+ {
+ DataRow row = table.NewRow();
+ row["A"] = DateTime.Now;
+ row["B"] = i;
+ table.Rows.Add(row);
+ }
+
+ tableView.Data = table;
+
+ var path = "ExportToCsv.csv";
+ tableView.ExportAsCsv(path);
+
+ var exportedLines = File.ReadAllLines(path);
+
+ Assert.AreEqual(51, exportedLines.Length);
+ Assert.AreEqual("A, B", exportedLines[0]);
+ }
+
+ [Test]
+ public void SetDataSource()
+ {
+ var table = new DataTable("table1");
+
+ var tableView = new TableView
+ {
+ Data = table
+ };
+
+ Assert.AreEqual(table, tableView.Data, "Data assigned to TableView must not change by itself");
+ }
+
+ [Test]
+ [Ignore("Doesn't work on buildserver because next test is started before previous one is finished")]
+ public void Copy1Paste1Cell()
+ {
+ DataTable table = CreateTableForCopyPaste();
+
+ Assert.AreEqual(0, table.Rows[0].ItemArray[1]);
+ Assert.AreEqual(1, table.Rows[1].ItemArray[1]);
+
+ var tableView = new TableView
+ {
+ Data = table
+ };
+ Action