From 673048f7bdfc448e52829b90be2c2d62e41c97da Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sun, 29 Jun 2014 22:54:11 +0200 Subject: [PATCH 1/9] Adds unit tests for double extension methods + Fixes a build problem on Mono Former-commit-id: 599a7c107767d137d1d6ff38085bc42bf4c11015 --- .../Extensions/DoubleExtensionsUnitTests.cs | 55 +++++++++++++++++++ .../ImageProcessor.UnitTests.csproj | 4 ++ src/ImageProcessor/ImageProcessor.csproj | 6 +- 3 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 src/ImageProcessor.UnitTests/Extensions/DoubleExtensionsUnitTests.cs diff --git a/src/ImageProcessor.UnitTests/Extensions/DoubleExtensionsUnitTests.cs b/src/ImageProcessor.UnitTests/Extensions/DoubleExtensionsUnitTests.cs new file mode 100644 index 000000000..108a9a246 --- /dev/null +++ b/src/ImageProcessor.UnitTests/Extensions/DoubleExtensionsUnitTests.cs @@ -0,0 +1,55 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) James South. +// Licensed under the Apache License, Version 2.0. +// +// +// Runs unit tests on the extension methods +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace ImageProcessor.UnitTests +{ + using System; + using System.Collections.Generic; + using Common.Extensions; + using NUnit.Framework; + + /// + /// Test harness for the DoubleExtensions extension methods + /// + [TestFixture] + public class DoubleExtensionsUnitTests + { + /// + /// Stores the values to test for the ToByte() extension method + /// + private Dictionary doubleToByteTests; + + /// + /// Sets up the values for the tests + /// + [TestFixtureSetUp] + public void Init() + { + this.doubleToByteTests = new Dictionary(); + this.doubleToByteTests.Add(-10, 0x0); + this.doubleToByteTests.Add(1.5, 0x1); + this.doubleToByteTests.Add(25.7, 0x19); + this.doubleToByteTests.Add(1289047, 0xFF); + } + + /// + /// Tests the double to byte conversion + /// + [Test] + public void TestDoubleToByte() + { + foreach (var item in this.doubleToByteTests) + { + var result = item.Key.ToByte(); + Assert.AreEqual(item.Value, result); + } + } + } +} \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj index c872dbbb8..e715df657 100644 --- a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj +++ b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj @@ -46,6 +46,7 @@ PreserveNewest + @@ -127,4 +128,7 @@ + + + \ No newline at end of file diff --git a/src/ImageProcessor/ImageProcessor.csproj b/src/ImageProcessor/ImageProcessor.csproj index 4521b06eb..331690773 100644 --- a/src/ImageProcessor/ImageProcessor.csproj +++ b/src/ImageProcessor/ImageProcessor.csproj @@ -3,8 +3,6 @@ Debug AnyCPU - 8.0.30703 - 2.0 {3B5DD734-FB7A-487D-8CE6-55E7AF9AEA7E} Library Properties @@ -25,7 +23,6 @@ prompt 4 bin\Debug\ImageProcessor.XML - false pdbonly @@ -46,6 +43,8 @@ prompt false true + 4 + false @@ -57,6 +56,7 @@ + From 27191ed6e3e14b61a2e7c5deafb2852fa6643b3d Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sun, 29 Jun 2014 23:41:33 +0200 Subject: [PATCH 2/9] Adds a few unit tests for integer extension methods Former-commit-id: c587d0b1373ced2470459836d5814afe0e7e31e8 --- .../Extensions/IntegerExtensionsUnitTests.cs | 38 +++++++++++++++++++ .../ImageProcessor.UnitTests.csproj | 1 + 2 files changed, 39 insertions(+) create mode 100644 src/ImageProcessor.UnitTests/Extensions/IntegerExtensionsUnitTests.cs diff --git a/src/ImageProcessor.UnitTests/Extensions/IntegerExtensionsUnitTests.cs b/src/ImageProcessor.UnitTests/Extensions/IntegerExtensionsUnitTests.cs new file mode 100644 index 000000000..1e85e633b --- /dev/null +++ b/src/ImageProcessor.UnitTests/Extensions/IntegerExtensionsUnitTests.cs @@ -0,0 +1,38 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) James South. +// Licensed under the Apache License, Version 2.0. +// +// +// Runs unit tests on the extension methods +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace ImageProcessor.UnitTests +{ + using System; + using Common.Extensions; + using NUnit.Framework; + + /// + /// Provides a test harness for the integer extension class + /// + [TestFixture] + public class IntegerExtensionsUnitTests + { + /// + /// Tests the "ToByte" extension + /// + /// Integer input + /// Expected result + [Test] + [TestCase(21, 0x15)] + [TestCase(190, 0xBE)] + [TestCase(3156, 0xFF)] + public void ToByteTest(int input, byte expected) + { + var result = input.ToByte(); + Assert.AreEqual(expected, result); + } + } +} \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj index e715df657..b545a11d9 100644 --- a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj +++ b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj @@ -47,6 +47,7 @@ PreserveNewest + From e008f57d8e5c99351aed25a9cb633ed5f478f77f Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sun, 29 Jun 2014 22:54:11 +0200 Subject: [PATCH 3/9] Adds unit tests for double extension methods + Fixes a build problem on Mono Former-commit-id: 0173a90054d91a5e80b0eb8765e10ddcb8a28085 --- .../Extensions/DoubleExtensionsUnitTests.cs | 55 +++++++++++++++++++ .../ImageProcessor.UnitTests.csproj | 4 ++ src/ImageProcessor/ImageProcessor.csproj | 6 +- 3 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 src/ImageProcessor.UnitTests/Extensions/DoubleExtensionsUnitTests.cs diff --git a/src/ImageProcessor.UnitTests/Extensions/DoubleExtensionsUnitTests.cs b/src/ImageProcessor.UnitTests/Extensions/DoubleExtensionsUnitTests.cs new file mode 100644 index 000000000..108a9a246 --- /dev/null +++ b/src/ImageProcessor.UnitTests/Extensions/DoubleExtensionsUnitTests.cs @@ -0,0 +1,55 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) James South. +// Licensed under the Apache License, Version 2.0. +// +// +// Runs unit tests on the extension methods +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace ImageProcessor.UnitTests +{ + using System; + using System.Collections.Generic; + using Common.Extensions; + using NUnit.Framework; + + /// + /// Test harness for the DoubleExtensions extension methods + /// + [TestFixture] + public class DoubleExtensionsUnitTests + { + /// + /// Stores the values to test for the ToByte() extension method + /// + private Dictionary doubleToByteTests; + + /// + /// Sets up the values for the tests + /// + [TestFixtureSetUp] + public void Init() + { + this.doubleToByteTests = new Dictionary(); + this.doubleToByteTests.Add(-10, 0x0); + this.doubleToByteTests.Add(1.5, 0x1); + this.doubleToByteTests.Add(25.7, 0x19); + this.doubleToByteTests.Add(1289047, 0xFF); + } + + /// + /// Tests the double to byte conversion + /// + [Test] + public void TestDoubleToByte() + { + foreach (var item in this.doubleToByteTests) + { + var result = item.Key.ToByte(); + Assert.AreEqual(item.Value, result); + } + } + } +} \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj index c872dbbb8..e715df657 100644 --- a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj +++ b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj @@ -46,6 +46,7 @@ PreserveNewest + @@ -127,4 +128,7 @@ + + + \ No newline at end of file diff --git a/src/ImageProcessor/ImageProcessor.csproj b/src/ImageProcessor/ImageProcessor.csproj index 1c5b26e80..c21b78194 100644 --- a/src/ImageProcessor/ImageProcessor.csproj +++ b/src/ImageProcessor/ImageProcessor.csproj @@ -3,8 +3,6 @@ Debug AnyCPU - 8.0.30703 - 2.0 {3B5DD734-FB7A-487D-8CE6-55E7AF9AEA7E} Library Properties @@ -25,7 +23,6 @@ prompt 4 bin\Debug\ImageProcessor.XML - false pdbonly @@ -46,6 +43,8 @@ prompt false true + 4 + false @@ -57,6 +56,7 @@ + From 8f238310ea4d7804fc945a6d7869646f6027a4a5 Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sun, 29 Jun 2014 23:41:33 +0200 Subject: [PATCH 4/9] Adds a few unit tests for integer extension methods Former-commit-id: 456bf78a23c676691a90f7bfe1149673e5e0d79d --- .../Extensions/IntegerExtensionsUnitTests.cs | 38 +++++++++++++++++++ .../ImageProcessor.UnitTests.csproj | 1 + 2 files changed, 39 insertions(+) create mode 100644 src/ImageProcessor.UnitTests/Extensions/IntegerExtensionsUnitTests.cs diff --git a/src/ImageProcessor.UnitTests/Extensions/IntegerExtensionsUnitTests.cs b/src/ImageProcessor.UnitTests/Extensions/IntegerExtensionsUnitTests.cs new file mode 100644 index 000000000..1e85e633b --- /dev/null +++ b/src/ImageProcessor.UnitTests/Extensions/IntegerExtensionsUnitTests.cs @@ -0,0 +1,38 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) James South. +// Licensed under the Apache License, Version 2.0. +// +// +// Runs unit tests on the extension methods +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace ImageProcessor.UnitTests +{ + using System; + using Common.Extensions; + using NUnit.Framework; + + /// + /// Provides a test harness for the integer extension class + /// + [TestFixture] + public class IntegerExtensionsUnitTests + { + /// + /// Tests the "ToByte" extension + /// + /// Integer input + /// Expected result + [Test] + [TestCase(21, 0x15)] + [TestCase(190, 0xBE)] + [TestCase(3156, 0xFF)] + public void ToByteTest(int input, byte expected) + { + var result = input.ToByte(); + Assert.AreEqual(expected, result); + } + } +} \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj index e715df657..b545a11d9 100644 --- a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj +++ b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj @@ -47,6 +47,7 @@ PreserveNewest + From e54765c81bf875c2e1139e3fcc24f56a8c648f30 Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sun, 29 Jun 2014 22:54:11 +0200 Subject: [PATCH 5/9] Adds unit tests for double extension methods + Fixes a build problem on Mono Former-commit-id: e8f60511fcccad4fd1f9e38d4d33cfdcb8a7020d --- .../Extensions/DoubleExtensionsUnitTests.cs | 55 +++++++++++++++++++ .../ImageProcessor.UnitTests.csproj | 4 ++ src/ImageProcessor/ImageProcessor.csproj | 6 +- 3 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 src/ImageProcessor.UnitTests/Extensions/DoubleExtensionsUnitTests.cs diff --git a/src/ImageProcessor.UnitTests/Extensions/DoubleExtensionsUnitTests.cs b/src/ImageProcessor.UnitTests/Extensions/DoubleExtensionsUnitTests.cs new file mode 100644 index 000000000..108a9a246 --- /dev/null +++ b/src/ImageProcessor.UnitTests/Extensions/DoubleExtensionsUnitTests.cs @@ -0,0 +1,55 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) James South. +// Licensed under the Apache License, Version 2.0. +// +// +// Runs unit tests on the extension methods +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace ImageProcessor.UnitTests +{ + using System; + using System.Collections.Generic; + using Common.Extensions; + using NUnit.Framework; + + /// + /// Test harness for the DoubleExtensions extension methods + /// + [TestFixture] + public class DoubleExtensionsUnitTests + { + /// + /// Stores the values to test for the ToByte() extension method + /// + private Dictionary doubleToByteTests; + + /// + /// Sets up the values for the tests + /// + [TestFixtureSetUp] + public void Init() + { + this.doubleToByteTests = new Dictionary(); + this.doubleToByteTests.Add(-10, 0x0); + this.doubleToByteTests.Add(1.5, 0x1); + this.doubleToByteTests.Add(25.7, 0x19); + this.doubleToByteTests.Add(1289047, 0xFF); + } + + /// + /// Tests the double to byte conversion + /// + [Test] + public void TestDoubleToByte() + { + foreach (var item in this.doubleToByteTests) + { + var result = item.Key.ToByte(); + Assert.AreEqual(item.Value, result); + } + } + } +} \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj index c872dbbb8..e715df657 100644 --- a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj +++ b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj @@ -46,6 +46,7 @@ PreserveNewest + @@ -127,4 +128,7 @@ + + + \ No newline at end of file diff --git a/src/ImageProcessor/ImageProcessor.csproj b/src/ImageProcessor/ImageProcessor.csproj index 1c5b26e80..c21b78194 100644 --- a/src/ImageProcessor/ImageProcessor.csproj +++ b/src/ImageProcessor/ImageProcessor.csproj @@ -3,8 +3,6 @@ Debug AnyCPU - 8.0.30703 - 2.0 {3B5DD734-FB7A-487D-8CE6-55E7AF9AEA7E} Library Properties @@ -25,7 +23,6 @@ prompt 4 bin\Debug\ImageProcessor.XML - false pdbonly @@ -46,6 +43,8 @@ prompt false true + 4 + false @@ -57,6 +56,7 @@ + From d2e13160342c9a576e10df96412977d926b92fec Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sun, 29 Jun 2014 23:41:33 +0200 Subject: [PATCH 6/9] Adds a few unit tests for integer extension methods Former-commit-id: e90275cd32600a9a68010f0fb1aeebbb6d092598 --- .../Extensions/IntegerExtensionsUnitTests.cs | 38 +++++++++++++++++++ .../ImageProcessor.UnitTests.csproj | 1 + 2 files changed, 39 insertions(+) create mode 100644 src/ImageProcessor.UnitTests/Extensions/IntegerExtensionsUnitTests.cs diff --git a/src/ImageProcessor.UnitTests/Extensions/IntegerExtensionsUnitTests.cs b/src/ImageProcessor.UnitTests/Extensions/IntegerExtensionsUnitTests.cs new file mode 100644 index 000000000..1e85e633b --- /dev/null +++ b/src/ImageProcessor.UnitTests/Extensions/IntegerExtensionsUnitTests.cs @@ -0,0 +1,38 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) James South. +// Licensed under the Apache License, Version 2.0. +// +// +// Runs unit tests on the extension methods +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace ImageProcessor.UnitTests +{ + using System; + using Common.Extensions; + using NUnit.Framework; + + /// + /// Provides a test harness for the integer extension class + /// + [TestFixture] + public class IntegerExtensionsUnitTests + { + /// + /// Tests the "ToByte" extension + /// + /// Integer input + /// Expected result + [Test] + [TestCase(21, 0x15)] + [TestCase(190, 0xBE)] + [TestCase(3156, 0xFF)] + public void ToByteTest(int input, byte expected) + { + var result = input.ToByte(); + Assert.AreEqual(expected, result); + } + } +} \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj index e715df657..b545a11d9 100644 --- a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj +++ b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj @@ -47,6 +47,7 @@ PreserveNewest + From 49850747b2651de6cf199f14c8d8c564f9f43ff4 Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Fri, 4 Jul 2014 22:01:17 +0200 Subject: [PATCH 7/9] Unit tests some string extensions Former-commit-id: 86a9c83b1ecc00e2f966372a77c6956676b1d7fb --- .../Extensions/StringExtensionsUnitTests.cs | 91 +++++++++++++++++++ .../ImageProcessor.UnitTests.csproj | 1 + 2 files changed, 92 insertions(+) create mode 100644 src/ImageProcessor.UnitTests/Extensions/StringExtensionsUnitTests.cs diff --git a/src/ImageProcessor.UnitTests/Extensions/StringExtensionsUnitTests.cs b/src/ImageProcessor.UnitTests/Extensions/StringExtensionsUnitTests.cs new file mode 100644 index 000000000..d1fefa395 --- /dev/null +++ b/src/ImageProcessor.UnitTests/Extensions/StringExtensionsUnitTests.cs @@ -0,0 +1,91 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) James South. +// Licensed under the Apache License, Version 2.0. +// +// +// Provides a test harness for the string extensions +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace ImageProcessor.UnitTests +{ + using System; + using Common.Extensions; + using NUnit.Framework; + + /// + /// Test harness for the string extensions + /// + [TestFixture] + public class StringExtensionsUnitTests + { + /// + /// Tests the MD5 fingerprint + /// + /// The input value + /// The expexted output of the hash + [Test] + [TestCase("test input", "2e7f7a62eabf0993239ca17c78c464d9")] + [TestCase("lorem ipsum dolor", "96ee002fee25e8b675a477c9750fa360")] + [TestCase("LoReM IpSuM DoLoR", "41e201da794c7fbdb8ce5526a71c8c83")] + [TestCase("1234567890", "e15e31c3d8898c92ab172a4311be9e84")] + public void TestToMd5Fingerprint(string input, string expected) + { + var result = input.ToMD5Fingerprint(); + var comparison = result.Equals(expected, StringComparison.InvariantCultureIgnoreCase); + Assert.True(comparison); + } + + /// + /// Tests the SHA-1 fingerprint + /// + /// The input value + /// The expexted output of the hash + [Test] + [TestCase("test input", "49883b34e5a0f48224dd6230f471e9dc1bdbeaf5")] + [TestCase("lorem ipsum dolor", "75899ad8827a32493928903aecd6e931bf36f967")] + [TestCase("LoReM IpSuM DoLoR", "2f44519afae72fc0837b72c6b53cb11338a1f916")] + [TestCase("1234567890", "01b307acba4f54f55aafc33bb06bbbf6ca803e9a")] + public void TestToSHA1Fingerprint(string input, string expected) + { + var result = input.ToSHA1Fingerprint(); + var comparison = result.Equals(expected, StringComparison.InvariantCultureIgnoreCase); + Assert.True(comparison); + } + + /// + /// Tests the SHA-256 fingerprint + /// + /// The input value + /// The expexted output of the hash + [Test] + [TestCase("test input", "9dfe6f15d1ab73af898739394fd22fd72a03db01834582f24bb2e1c66c7aaeae")] + [TestCase("lorem ipsum dolor", "ed03353266c993ea9afb9900a3ca688ddec1656941b1ca15ee1650a022616dfa")] + [TestCase("LoReM IpSuM DoLoR", "55f6cb90ba5cd8eeb6f5f16f083ebcd48ea06c34cc5aed8e33246fc3153d3898")] + [TestCase("1234567890", "c775e7b757ede630cd0aa1113bd102661ab38829ca52a6422ab782862f268646")] + public void TestToSHA256Fingerprint(string input, string expected) + { + var result = input.ToSHA256Fingerprint(); + var comparison = result.Equals(expected, StringComparison.InvariantCultureIgnoreCase); + Assert.True(comparison); + } + + /// + /// Tests the SHA-512 fingerprint + /// + /// The input value + /// The expexted output of the hash + [Test] + [TestCase("test input", "40aa1b203c9d8ee150b21c3c7cda8261492e5420c5f2b9f7380700e094c303b48e62f319c1da0e32eb40d113c5f1749cc61aeb499167890ab82f2cc9bb706971")] + [TestCase("lorem ipsum dolor", "cd813e13d1d3919cdccc31c19d8f8b70bd25e9819f8770a011c8c7a6228536e6c9427b338cd732f2da3c0444dfebef838b745cdaf3fd5dcba8db24fc83a3f6ef")] + [TestCase("LoReM IpSuM DoLoR", "3e4704d31f838456c0a5f0892afd392fbc79649a029d017b8104ebd00e2816d94ab4629f731765bf655088b130c51f6f47ca2f8b047749dbd992cf45e89ff431")] + [TestCase("1234567890", "12b03226a6d8be9c6e8cd5e55dc6c7920caaa39df14aab92d5e3ea9340d1c8a4d3d0b8e4314f1f6ef131ba4bf1ceb9186ab87c801af0d5c95b1befb8cedae2b9")] + public void TestToSHA512Fingerprint(string input, string expected) + { + var result = input.ToSHA512Fingerprint(); + var comparison = result.Equals(expected, StringComparison.InvariantCultureIgnoreCase); + Assert.True(comparison); + } + } +} \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj index b545a11d9..5b6bc12d1 100644 --- a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj +++ b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj @@ -48,6 +48,7 @@ + From aca285a315670eaf872dbcdb6810c3e4a48aebf1 Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Fri, 4 Jul 2014 22:31:53 +0200 Subject: [PATCH 8/9] Adds unit tests for some more string extensions Former-commit-id: 1af9789d4c15050ae0c9234e1101083c0884bb25 --- .../Extensions/StringExtensionsUnitTests.cs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/ImageProcessor.UnitTests/Extensions/StringExtensionsUnitTests.cs b/src/ImageProcessor.UnitTests/Extensions/StringExtensionsUnitTests.cs index d1fefa395..17cc4c753 100644 --- a/src/ImageProcessor.UnitTests/Extensions/StringExtensionsUnitTests.cs +++ b/src/ImageProcessor.UnitTests/Extensions/StringExtensionsUnitTests.cs @@ -11,6 +11,7 @@ namespace ImageProcessor.UnitTests { using System; + using System.Collections.Generic; using Common.Extensions; using NUnit.Framework; @@ -87,5 +88,41 @@ namespace ImageProcessor.UnitTests var comparison = result.Equals(expected, StringComparison.InvariantCultureIgnoreCase); Assert.True(comparison); } + + /// + /// Tests the pasing to an integer array + /// + [Test] + public void TestToIntegerArray() + { + Dictionary data = new Dictionary(); + data.Add("123-456,78-90", new int[] { 123, 456, 78, 90 }); + data.Add("87390174,741897498,74816,748297,57355", new int[] { 87390174, 741897498, 74816, 748297, 57355 }); + data.Add("1-2-3", new int[] { 1, 2, 3 }); + + foreach (var item in data) + { + var result = item.Key.ToPositiveIntegerArray(); + Assert.AreEqual(item.Value, result); + } + } + + /// + /// Tests the pasing to an float array + /// + [Test] + public void TestToFloatArray() + { + Dictionary data = new Dictionary(); + data.Add("12.3-4.56,78-9.0", new float[] { 12.3F, 4.56F, 78, 9 }); + data.Add("87390.174,7.41897498,748.16,748297,5.7355", new float[] { 87390.174F, 7.41897498F, 748.16F, 748297, 5.7355F }); + data.Add("1-2-3", new float[] { 1, 2, 3 }); + + foreach (var item in data) + { + var result = item.Key.ToPositiveFloatArray(); + Assert.AreEqual(item.Value, result); + } + } } } \ No newline at end of file From 7e06bbb25a347d2b7f5fc734bdff25f8563bb78d Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Fri, 4 Jul 2014 22:49:13 +0200 Subject: [PATCH 9/9] Tests a few more string extensions Former-commit-id: c442263a29c5247ec0c9cb568f64e4a85eb9c0f1 --- .../Extensions/StringExtensionsUnitTests.cs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/ImageProcessor.UnitTests/Extensions/StringExtensionsUnitTests.cs b/src/ImageProcessor.UnitTests/Extensions/StringExtensionsUnitTests.cs index 17cc4c753..70f3e83db 100644 --- a/src/ImageProcessor.UnitTests/Extensions/StringExtensionsUnitTests.cs +++ b/src/ImageProcessor.UnitTests/Extensions/StringExtensionsUnitTests.cs @@ -124,5 +124,45 @@ namespace ImageProcessor.UnitTests Assert.AreEqual(item.Value, result); } } + + /// + /// Tests if the value is a valid URI + /// + /// The value to test + /// Whether the value is correct + /// + /// The full RFC3986 does not seem to pass the test with the square brackets + /// + [Test] + [TestCase("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", true)] + [TestCase("-", true)] + [TestCase(".", true)] + [TestCase("_", true)] + [TestCase("~", true)] + [TestCase(":", true)] + [TestCase("/", true)] + [TestCase("?", true)] + [TestCase("#", true)] + [TestCase("[", false)] + [TestCase("]", false)] + [TestCase("@", true)] + [TestCase("!", true)] + [TestCase("$", true)] + [TestCase("&", true)] + [TestCase("'", true)] + [TestCase("(", true)] + [TestCase(")", true)] + [TestCase("*", true)] + [TestCase("+", true)] + [TestCase(",", true)] + [TestCase(";", true)] + [TestCase("=", true)] + [TestCase("lorem ipsum", false)] + [TestCase("é", false)] + public void TestIsValidUri(string input, bool expected) + { + var result = input.IsValidVirtualPathName(); + Assert.AreEqual(expected, result); + } } } \ No newline at end of file