diff --git a/src/ImageProcessor.UnitTests/Extensions/StringExtensionsUnitTests.cs b/src/ImageProcessor.UnitTests/Extensions/StringExtensionsUnitTests.cs deleted file mode 100644 index ab43bd92b..000000000 --- a/src/ImageProcessor.UnitTests/Extensions/StringExtensionsUnitTests.cs +++ /dev/null @@ -1,83 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) James South. -// Licensed under the Apache License, Version 2.0. -// -// -// Provides a test harness for the string extensions -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace ImageProcessor.UnitTests.Extensions -{ - using System.Collections.Generic; - using ImageProcessor.Common.Extensions; - using NUnit.Framework; - - /// - /// Test harness for the string extensions - /// - [TestFixture] - public class StringExtensionsUnitTests - { - /// - /// Tests the passing to an integer array - /// - [Test] - public void TestToIntegerArray() - { - Dictionary data = new Dictionary - { - { - "123-456,78-90", - new[] { 123, 456, 78, 90 } - }, - { - "87390174,741897498,74816,748297,57355", - new[] - { - 87390174, 741897498, 74816, - 748297, 57355 - } - }, - { "1-2-3", new[] { 1, 2, 3 } } - }; - - foreach (KeyValuePair item in data) - { - int[] result = item.Key.ToPositiveIntegerArray(); - Assert.AreEqual(item.Value, result); - } - } - - /// - /// Tests the passing to an float array - /// - [Test] - public void TestToFloatArray() - { - Dictionary data = new Dictionary - { - { - "12.3-4.56,78-9.0", - new[] { 12.3F, 4.56F, 78, 9 } - }, - { - "87390.174,7.41897498,748.16,748297,5.7355", - new[] - { - 87390.174F, 7.41897498F, - 748.16F, 748297, 5.7355F - } - }, - { "1-2-3", new float[] { 1, 2, 3 } } - }; - - foreach (KeyValuePair item in data) - { - float[] result = item.Key.ToPositiveFloatArray(); - 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 5b6bc12d1..930267a63 100644 --- a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj +++ b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj @@ -48,7 +48,6 @@ - @@ -130,7 +129,5 @@ - - - + \ No newline at end of file diff --git a/src/ImageProcessor.Web.UnitTests/Extensions/StringExtensionsUnitTests.cs b/src/ImageProcessor.Web.UnitTests/Extensions/StringExtensionsUnitTests.cs index 57c261c7b..3e9053aed 100644 --- a/src/ImageProcessor.Web.UnitTests/Extensions/StringExtensionsUnitTests.cs +++ b/src/ImageProcessor.Web.UnitTests/Extensions/StringExtensionsUnitTests.cs @@ -11,6 +11,8 @@ namespace ImageProcessor.Web.UnitTests.Extensions { using System; + using System.Collections.Generic; + using ImageProcessor.Web.Extensions; using NUnit.Framework; @@ -20,6 +22,66 @@ namespace ImageProcessor.Web.UnitTests.Extensions [TestFixture] public class StringExtensionsUnitTests { + /// + /// Tests the passing to an integer array + /// + [Test] + public void TestToIntegerArray() + { + Dictionary data = new Dictionary + { + { + "123-456,78-90", + new[] { 123, 456, 78, 90 } + }, + { + "87390174,741897498,74816,748297,57355", + new[] + { + 87390174, 741897498, 74816, + 748297, 57355 + } + }, + { "1-2-3", new[] { 1, 2, 3 } } + }; + + foreach (KeyValuePair item in data) + { + int[] result = item.Key.ToPositiveIntegerArray(); + Assert.AreEqual(item.Value, result); + } + } + + /// + /// Tests the passing to an float array + /// + [Test] + public void TestToFloatArray() + { + Dictionary data = new Dictionary + { + { + "12.3-4.56,78-9.0", + new[] { 12.3F, 4.56F, 78, 9 } + }, + { + "87390.174,7.41897498,748.16,748297,5.7355", + new[] + { + 87390.174F, 7.41897498F, + 748.16F, 748297, 5.7355F + } + }, + { "1-2-3", new float[] { 1, 2, 3 } } + }; + + foreach (KeyValuePair item in data) + { + float[] result = item.Key.ToPositiveFloatArray(); + Assert.AreEqual(item.Value, result); + } + } + /// /// Tests the MD5 fingerprint /// diff --git a/src/ImageProcessor.Web/NET4/ImageProcessor.Web_NET4.csproj b/src/ImageProcessor.Web/NET4/ImageProcessor.Web_NET4.csproj index d830257ae..82d3986a7 100644 --- a/src/ImageProcessor.Web/NET4/ImageProcessor.Web_NET4.csproj +++ b/src/ImageProcessor.Web/NET4/ImageProcessor.Web_NET4.csproj @@ -98,6 +98,9 @@ DirectoryInfoExtensions.cs + + StringExtensions.cs + CommonParameterParserUtility.cs diff --git a/src/ImageProcessor.Web/NET45/Caching/DiskCache.cs b/src/ImageProcessor.Web/NET45/Caching/DiskCache.cs index 6a23d48ad..be6b88744 100644 --- a/src/ImageProcessor.Web/NET45/Caching/DiskCache.cs +++ b/src/ImageProcessor.Web/NET45/Caching/DiskCache.cs @@ -20,7 +20,6 @@ namespace ImageProcessor.Web.Caching using System.Web; using System.Web.Hosting; - using ImageProcessor.Common.Extensions; using ImageProcessor.Web.Configuration; using ImageProcessor.Web.Extensions; using ImageProcessor.Web.Helpers; @@ -245,7 +244,7 @@ namespace ImageProcessor.Web.Caching fileInfo.Delete(); count -= 1; } - // ReSharper disable once EmptyGeneralCatchClause + // ReSharper disable once EmptyGeneralCatchClause catch { // Do nothing; skip to the next file. diff --git a/src/ImageProcessor.Web/NET45/Helpers/CommonParameterParserUtility.cs b/src/ImageProcessor.Web/NET45/Helpers/CommonParameterParserUtility.cs index ae71ca7ef..505d80d99 100644 --- a/src/ImageProcessor.Web/NET45/Helpers/CommonParameterParserUtility.cs +++ b/src/ImageProcessor.Web/NET45/Helpers/CommonParameterParserUtility.cs @@ -17,6 +17,7 @@ namespace ImageProcessor.Web.Helpers using ImageProcessor.Common.Extensions; using ImageProcessor.Imaging; + using ImageProcessor.Web.Extensions; /// /// Encapsulates methods to correctly parse querystring parameters. diff --git a/src/ImageProcessor.Web/NET45/Processors/Crop.cs b/src/ImageProcessor.Web/NET45/Processors/Crop.cs index c621ebd1a..c669c8e1b 100644 --- a/src/ImageProcessor.Web/NET45/Processors/Crop.cs +++ b/src/ImageProcessor.Web/NET45/Processors/Crop.cs @@ -13,9 +13,9 @@ namespace ImageProcessor.Web.Processors using System.Text; using System.Text.RegularExpressions; - using ImageProcessor.Common.Extensions; using ImageProcessor.Imaging; using ImageProcessor.Processors; + using ImageProcessor.Web.Extensions; /// /// Crops an image to the given directions. diff --git a/src/ImageProcessor.Web/NET45/Processors/Resize.cs b/src/ImageProcessor.Web/NET45/Processors/Resize.cs index 95d962958..09ce9bc3c 100644 --- a/src/ImageProcessor.Web/NET45/Processors/Resize.cs +++ b/src/ImageProcessor.Web/NET45/Processors/Resize.cs @@ -17,9 +17,9 @@ namespace ImageProcessor.Web.Processors using System.Text; using System.Text.RegularExpressions; - using ImageProcessor.Common.Extensions; using ImageProcessor.Imaging; using ImageProcessor.Processors; + using ImageProcessor.Web.Extensions; /// /// Resizes an image to the given dimensions. diff --git a/src/ImageProcessor.Web/NET45/Processors/Watermark.cs b/src/ImageProcessor.Web/NET45/Processors/Watermark.cs index 27e83e288..d87f09388 100644 --- a/src/ImageProcessor.Web/NET45/Processors/Watermark.cs +++ b/src/ImageProcessor.Web/NET45/Processors/Watermark.cs @@ -15,9 +15,9 @@ namespace ImageProcessor.Web.Processors using System.Linq; using System.Text.RegularExpressions; - using ImageProcessor.Common.Extensions; using ImageProcessor.Imaging; using ImageProcessor.Processors; + using ImageProcessor.Web.Extensions; using ImageProcessor.Web.Helpers; /// diff --git a/src/ImageProcessor/Common/Extensions/StringExtensions.cs b/src/ImageProcessor/Common/Extensions/StringExtensions.cs deleted file mode 100644 index f315df797..000000000 --- a/src/ImageProcessor/Common/Extensions/StringExtensions.cs +++ /dev/null @@ -1,80 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) James South. -// Licensed under the Apache License, Version 2.0. -// -// -// Encapsulates a series of time saving extension methods to the class. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace ImageProcessor.Common.Extensions -{ - using System; - using System.Globalization; - using System.Text.RegularExpressions; - - /// - /// Encapsulates a series of time saving extension methods to the class. - /// - public static class StringExtensions - { - /// - /// Creates an array of integers scraped from the String. - /// - /// The String instance that this method extends. - /// An array of integers scraped from the String. - public static int[] ToPositiveIntegerArray(this string expression) - { - if (string.IsNullOrWhiteSpace(expression)) - { - throw new ArgumentNullException("expression"); - } - - Regex regex = new Regex(@"[\d+]+(?=[,-])|[\d+]+(?![,-])", RegexOptions.Compiled); - - MatchCollection matchCollection = regex.Matches(expression); - - // Get the collections. - int count = matchCollection.Count; - int[] matches = new int[count]; - - // Loop and parse the int values. - for (int i = 0; i < count; i++) - { - matches[i] = int.Parse(matchCollection[i].Value, CultureInfo.InvariantCulture); - } - - return matches; - } - - /// - /// Creates an array of floats scraped from the String. - /// - /// The String instance that this method extends. - /// An array of floats scraped from the String. - public static float[] ToPositiveFloatArray(this string expression) - { - if (string.IsNullOrWhiteSpace(expression)) - { - throw new ArgumentNullException("expression"); - } - - Regex regex = new Regex(@"[\d+\.]+(?=[,-])|[\d+\.]+(?![,-])", RegexOptions.Compiled); - - MatchCollection matchCollection = regex.Matches(expression); - - // Get the collections. - int count = matchCollection.Count; - float[] matches = new float[count]; - - // Loop and parse the int values. - for (int i = 0; i < count; i++) - { - matches[i] = float.Parse(matchCollection[i].Value, CultureInfo.InvariantCulture); - } - - return matches; - } - } -} diff --git a/src/ImageProcessor/ImageProcessor.csproj b/src/ImageProcessor/ImageProcessor.csproj index 274b3e76d..0e0d276bb 100644 --- a/src/ImageProcessor/ImageProcessor.csproj +++ b/src/ImageProcessor/ImageProcessor.csproj @@ -66,7 +66,6 @@ -