Index: Core/Common/src/Core.Common.Gui/Converters/ExpandableArrayConverter.cs =================================================================== diff -u -r0c64d8a6c718c0aa67403a16c94dd0c10f862455 -rce50b65f662bcccb1849444e4d51549731131234 --- Core/Common/src/Core.Common.Gui/Converters/ExpandableArrayConverter.cs (.../ExpandableArrayConverter.cs) (revision 0c64d8a6c718c0aa67403a16c94dd0c10f862455) +++ Core/Common/src/Core.Common.Gui/Converters/ExpandableArrayConverter.cs (.../ExpandableArrayConverter.cs) (revision ce50b65f662bcccb1849444e4d51549731131234) @@ -28,7 +28,7 @@ namespace Core.Common.Gui.Converters { /// - /// with modified conversion to string and shows as array + /// with modified conversion to string and shows an array /// starting with index 1 instead of 0. /// public class ExpandableArrayConverter : ArrayConverter Index: Core/Common/src/Core.Common.Gui/Converters/PngToIconConverter.cs =================================================================== diff -u -r0c64d8a6c718c0aa67403a16c94dd0c10f862455 -rce50b65f662bcccb1849444e4d51549731131234 --- Core/Common/src/Core.Common.Gui/Converters/PngToIconConverter.cs (.../PngToIconConverter.cs) (revision 0c64d8a6c718c0aa67403a16c94dd0c10f862455) +++ Core/Common/src/Core.Common.Gui/Converters/PngToIconConverter.cs (.../PngToIconConverter.cs) (revision ce50b65f662bcccb1849444e4d51549731131234) @@ -20,19 +20,26 @@ // All rights reserved. using System; +using System.Drawing; +using System.Drawing.Imaging; +using System.Globalization; using System.IO; using System.Windows.Data; using System.Windows.Media.Imaging; namespace Core.Common.Gui.Converters { + /// + /// Converter to change a instance to a instance. + /// public class PngToIconConverter : IValueConverter { - public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { MemoryStream ms = new MemoryStream(); - ((System.Drawing.Bitmap)value).Save(ms, System.Drawing.Imaging.ImageFormat.Png); - BitmapImage image = new BitmapImage(); + ((Bitmap)value).Save(ms, ImageFormat.Png); + + var image = new BitmapImage(); image.BeginInit(); ms.Seek(0, SeekOrigin.Begin); image.StreamSource = ms; @@ -41,7 +48,7 @@ return image; } - public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } Index: Core/Common/test/Core.Common.Gui.Test/Converters/ExpandableArrayConverterTest.cs =================================================================== diff -u --- Core/Common/test/Core.Common.Gui.Test/Converters/ExpandableArrayConverterTest.cs (revision 0) +++ Core/Common/test/Core.Common.Gui.Test/Converters/ExpandableArrayConverterTest.cs (revision ce50b65f662bcccb1849444e4d51549731131234) @@ -0,0 +1,132 @@ +using System; +using System.ComponentModel; +using System.Linq; + +using Core.Common.Gui.Converters; + +using NUnit.Framework; + +namespace Core.Common.Gui.Test.Converters +{ + [TestFixture] + public class ExpandableArrayConverterTest + { + [Test] + public void DefaultConstructor_ExpectedValues() + { + // Setup + + // Call + var converter = new ExpandableArrayConverter(); + + // Assert + Assert.IsInstanceOf(converter); + } + + [Test] + public void ConvertTo_FromArrayToString_ReturnCountText([Random(0, 10, 1)]int arrayCount) + { + // Setup + var sourceArray = new int[arrayCount]; + var converter = new ExpandableArrayConverter(); + + // Call + var text = converter.ConvertTo(sourceArray, typeof(string)); + + // Assert + Assert.AreEqual(string.Format("Aantal ({0})", arrayCount), text); + } + + [Test] + public void ConvertTo_FromNullToString_ReturnEmptyText() + { + // Setup + var converter = new ExpandableArrayConverter(); + + // Call + var text = converter.ConvertTo(null, typeof(string)); + + // Assert + Assert.AreEqual(string.Empty, text); + } + + [Test] + public void ConvertTo_FromArrayToInt_ThrowsInvalidOperationException() + { + // Setup + var sourceArray = new int[1]; + var converter = new ExpandableArrayConverter(); + + // Call + TestDelegate call = () => converter.ConvertTo(sourceArray, typeof(int)); + + // Assert + Assert.Throws(call); + } + + [Test] + public void ConvertTo_FromArrayToString_ReturnCountText() + { + // Setup + var sourceArray = new int[2]; + var converter = new ExpandableArrayConverter(); + + // Call + TestDelegate call =() => converter.ConvertTo(sourceArray, null); + + // Assert + Assert.Throws(call); + } + + [Test] + [TestCase(0)] + [TestCase(1)] + [TestCase(12)] + public void GetProperties_FromArray_ReturnPropertyDescriptorsForEachElementWithNameToOneBasedIndex(int elementCount) + { + // Setup + var array = Enumerable.Range(10, elementCount).ToArray(); + + var converter = new ExpandableArrayConverter(); + + // Call + var propertyDescriptors = converter.GetProperties(array); + + // Assert + Assert.IsNotNull(propertyDescriptors); + Assert.AreEqual(elementCount, propertyDescriptors.Count); + for (int i = 0; i < elementCount; i++) + { + Assert.AreEqual(array.GetType(), propertyDescriptors[i].ComponentType); + Assert.AreEqual(string.Format("[{0}]", i + 1), propertyDescriptors[i].Name); + Assert.AreEqual(string.Format("[{0}]", i + 1), propertyDescriptors[i].DisplayName); + Assert.AreEqual(typeof(int), propertyDescriptors[i].PropertyType); + CollectionAssert.IsEmpty(propertyDescriptors[i].Attributes); + + Assert.AreEqual(array[i], propertyDescriptors[i].GetValue(array)); + } + } + + + [Test] + public void GetProperties_FromArray_SettingValuesShouldUpdateArray() + { + // Setup + const int elementCount = 12; + var array = Enumerable.Repeat(10, elementCount).ToArray(); + + var converter = new ExpandableArrayConverter(); + + // Call + var propertyDescriptors = converter.GetProperties(array); + for (int i = 0; i < elementCount; i++) + { + propertyDescriptors[i].SetValue(array, i); + } + + // Assert + CollectionAssert.AreEqual(Enumerable.Range(0, elementCount), array); + + } + } +} \ No newline at end of file Index: Core/Common/test/Core.Common.Gui.Test/Converters/PngToIconConverterTest.cs =================================================================== diff -u --- Core/Common/test/Core.Common.Gui.Test/Converters/PngToIconConverterTest.cs (revision 0) +++ Core/Common/test/Core.Common.Gui.Test/Converters/PngToIconConverterTest.cs (revision ce50b65f662bcccb1849444e4d51549731131234) @@ -0,0 +1,56 @@ +using System; +using System.Drawing; +using System.Globalization; +using System.Windows.Data; +using System.Windows.Media.Imaging; + +using Core.Common.Gui.Converters; +using Core.Common.Gui.Test.Properties; + +using NUnit.Framework; + +namespace Core.Common.Gui.Test.Converters +{ + [TestFixture] + public class PngToIconConverterTest + { + [Test] + public void DefaultConcstructor_ExpectedValues() + { + // Call + var converter = new PngToIconConverter(); + + // Assert + Assert.IsInstanceOf(converter); + } + + [Test] + public void Convert_WithPngImage_ConvertToBitmapImage() + { + // Setup + var converter = new PngToIconConverter(); + + // Call + var bitmap = converter.Convert(Resources.abacus, typeof(BitmapImage), null, CultureInfo.InvariantCulture); + + // Assert + Assert.IsInstanceOf(bitmap); + var bitmapInstance = (BitmapImage)bitmap; + Assert.AreEqual(16, bitmapInstance.Height); + Assert.AreEqual(16, bitmapInstance.Width); + } + + [Test] + public void ConvertBack_ThrowNotImplementedException() + { + // Setup + var converter = new PngToIconConverter(); + + // Call + TestDelegate call = () => converter.ConvertBack(new BitmapImage(), typeof(Bitmap), null, CultureInfo.InvariantCulture); + + // Assert + Assert.Throws(call); + } + } +} \ No newline at end of file Index: Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj =================================================================== diff -u -r791e86bf9004a55178386416eb6a9c545380bd1c -rce50b65f662bcccb1849444e4d51549731131234 --- Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj (.../Core.Common.Gui.Test.csproj) (revision 791e86bf9004a55178386416eb6a9c545380bd1c) +++ Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj (.../Core.Common.Gui.Test.csproj) (revision ce50b65f662bcccb1849444e4d51549731131234) @@ -75,7 +75,14 @@ + + + + True + True + Resources.resx + @@ -119,6 +126,15 @@ + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + ..\Resources\abacus.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file Index: Core/Common/test/Core.Common.Gui.Test/Resources/abacus.png =================================================================== diff -u Binary files differ