diff --git a/src/ImageProcessor.UnitTests/Extensions/DoubleExtensionsUnitTests.cs b/src/ImageProcessor.UnitTests/Extensions/DoubleExtensionsUnitTests.cs
index cba1c07bc5..91b62d74f2 100644
--- a/src/ImageProcessor.UnitTests/Extensions/DoubleExtensionsUnitTests.cs
+++ b/src/ImageProcessor.UnitTests/Extensions/DoubleExtensionsUnitTests.cs
@@ -10,7 +10,6 @@
namespace ImageProcessor.UnitTests.Extensions
{
- using System.Collections.Generic;
using Common.Extensions;
using NUnit.Framework;
@@ -20,37 +19,20 @@ namespace ImageProcessor.UnitTests.Extensions
[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
- {
- { -10, 0x0 },
- { 1.5, 0x1 },
- { 25.7, 0x19 },
- { 1289047, 0xFF }
- };
- }
-
///
/// Tests the double to byte conversion
///
+ /// Double input
+ /// Expected result
[Test]
- public void TestDoubleToByte()
+ [TestCase(-10, 0x0)]
+ [TestCase(1.5, 0x1)]
+ [TestCase(25.7, 0x19)]
+ [TestCase(1289047, 0xFF)]
+ public void TestDoubleToByte(double input, byte expected)
{
- foreach (var item in this.doubleToByteTests)
- {
- var result = item.Key.ToByte();
- Assert.AreEqual(item.Value, result);
- }
+ byte result = input.ToByte();
+ Assert.AreEqual(expected, result);
}
}
}
\ No newline at end of file
diff --git a/src/ImageProcessor.Web.UnitTests/ImageProcessor.Web.UnitTests.csproj b/src/ImageProcessor.Web.UnitTests/ImageProcessor.Web.UnitTests.csproj
index 460e329b9d..357f3b11d8 100644
--- a/src/ImageProcessor.Web.UnitTests/ImageProcessor.Web.UnitTests.csproj
+++ b/src/ImageProcessor.Web.UnitTests/ImageProcessor.Web.UnitTests.csproj
@@ -69,6 +69,10 @@
{3b5dd734-fb7a-487d-8ce6-55e7af9aea7e}
ImageProcessor
+
+ {2cf69699-959a-44dc-a281-4e2596c25043}
+ ImageProcessor.Plugins.WebP
+
diff --git a/src/ImageProcessor.Web.UnitTests/RegularExpressionUnitTests.cs b/src/ImageProcessor.Web.UnitTests/RegularExpressionUnitTests.cs
index c414545635..86c346e380 100644
--- a/src/ImageProcessor.Web.UnitTests/RegularExpressionUnitTests.cs
+++ b/src/ImageProcessor.Web.UnitTests/RegularExpressionUnitTests.cs
@@ -10,10 +10,14 @@
namespace ImageProcessor.Web.UnitTests
{
+ using System;
+ using System.Collections.Generic;
using System.Drawing;
using ImageProcessor.Imaging;
using ImageProcessor.Imaging.Filters;
using ImageProcessor.Imaging.Formats;
+ using ImageProcessor.Plugins.WebP.Imaging.Formats;
+
using NUnit.Framework;
///
@@ -40,37 +44,55 @@ namespace ImageProcessor.Web.UnitTests
}
///
- /// The brightness regex unit test.
+ /// The contrast regex unit test.
///
+ ///
+ /// The input string.
+ ///
+ ///
+ /// The expected result.
+ ///
[Test]
- public void TestBrightnessRegex()
+ [TestCase("brightness=56", 56)]
+ [TestCase("brightness=84", 84)]
+ [TestCase("brightness=66", 66)]
+ [TestCase("brightness=101", 1)]
+ [TestCase("brightness=00001", 1)]
+ [TestCase("brightness=-50", -50)]
+ [TestCase("brightness=0", 0)]
+ public void TestBrightnesstRegex(string input, int expected)
{
- const string Querystring = "brightness=56";
- const int Expected = 56;
-
Processors.Brightness brightness = new Processors.Brightness();
- brightness.MatchRegexIndex(Querystring);
+ brightness.MatchRegexIndex(input);
+ int result = brightness.Processor.DynamicParameter;
- int actual = brightness.Processor.DynamicParameter;
-
- Assert.AreEqual(Expected, actual);
+ Assert.AreEqual(expected, result);
}
///
/// The contrast regex unit test.
///
+ ///
+ /// The input string.
+ ///
+ ///
+ /// The expected result.
+ ///
[Test]
- public void TestContrastRegex()
+ [TestCase("contrast=56", 56)]
+ [TestCase("contrast=84", 84)]
+ [TestCase("contrast=66", 66)]
+ [TestCase("contrast=101", 1)]
+ [TestCase("contrast=00001", 1)]
+ [TestCase("contrast=-50", -50)]
+ [TestCase("contrast=0", 0)]
+ public void TestContrastRegex(string input, int expected)
{
- const string Querystring = "contrast=56";
- const int Expected = 56;
-
Processors.Contrast contrast = new Processors.Contrast();
- contrast.MatchRegexIndex(Querystring);
-
- int actual = contrast.Processor.DynamicParameter;
+ contrast.MatchRegexIndex(input);
+ int result = contrast.Processor.DynamicParameter;
- Assert.AreEqual(Expected, actual);
+ Assert.AreEqual(expected, result);
}
///
@@ -93,52 +115,102 @@ namespace ImageProcessor.Web.UnitTests
/// The filter regex unit test.
///
[Test]
+
public void TestFilterRegex()
{
- // Should really write more for the other filters.
- const string Querystring = "filter=lomograph";
- IMatrixFilter expected = MatrixFilters.Lomograph;
+ Dictionary data = new Dictionary
+ {
+ {
+ "filter=lomograph", MatrixFilters.Lomograph
+ },
+ {
+ "filter=polaroid", MatrixFilters.Polaroid
+ },
+ {
+ "filter=comic", MatrixFilters.Comic
+ },
+ {
+ "filter=greyscale", MatrixFilters.GreyScale
+ },
+ {
+ "filter=blackwhite", MatrixFilters.BlackWhite
+ },
+ {
+ "filter=invert", MatrixFilters.Invert
+ },
+ {
+ "filter=gotham", MatrixFilters.Gotham
+ },
+ {
+ "filter=hisatch", MatrixFilters.HiSatch
+ },
+ {
+ "filter=losatch", MatrixFilters.LoSatch
+ },
+ {
+ "filter=sepia", MatrixFilters.Sepia
+ }
+ };
Processors.Filter filter = new Processors.Filter();
- filter.MatchRegexIndex(Querystring);
-
- IMatrixFilter actual = filter.Processor.DynamicParameter;
-
- Assert.AreEqual(expected, actual);
+ foreach (KeyValuePair item in data)
+ {
+ filter.MatchRegexIndex(item.Key);
+ IMatrixFilter result = filter.Processor.DynamicParameter;
+ Assert.AreEqual(item.Value, result);
+ }
}
///
/// The format regex unit test.
///
+ ///
+ /// The input querystring.
+ ///
+ ///
+ /// The expected type.
+ ///
[Test]
- public void TestFormatRegex()
+ [TestCase("format=bmp", typeof(BitmapFormat))]
+ [TestCase("format=png", typeof(PngFormat))]
+ [TestCase("format=png8", typeof(PngFormat))]
+ [TestCase("format=jpeg", typeof(JpegFormat))]
+ [TestCase("format=jpg", typeof(JpegFormat))]
+ [TestCase("format=gif", typeof(GifFormat))]
+ [TestCase("format=webp", typeof(WebPFormat))]
+ public void TestFormatRegex(string input, Type expected)
{
- const string Querystring = "format=gif";
- ISupportedImageFormat expected = new GifFormat();
-
Processors.Format format = new Processors.Format();
- format.MatchRegexIndex(Querystring);
-
- ISupportedImageFormat actual = format.Processor.DynamicParameter;
+ format.MatchRegexIndex(input);
+ Type result = format.Processor.DynamicParameter.GetType();
- Assert.AreEqual(expected, actual);
+ Assert.AreEqual(expected, result);
}
///
/// The quality regex unit test.
///
+ ///
+ /// The input.
+ ///
+ ///
+ /// The expected result.
+ ///
[Test]
- public void TestQualityRegex()
+ [TestCase("quality=56", 56)]
+ [TestCase("quality=84", 84)]
+ [TestCase("quality=66", 66)]
+ [TestCase("quality=101", 1)]
+ [TestCase("quality=00001", 1)]
+ [TestCase("quality=-50", 50)]
+ [TestCase("quality=0", 0)]
+ public void TestQualityRegex(string input, int expected)
{
- const string Querystring = "quality=56";
- const int Expected = 56;
-
Processors.Quality quality = new Processors.Quality();
- quality.MatchRegexIndex(Querystring);
-
- int actual = quality.Processor.DynamicParameter;
+ quality.MatchRegexIndex(input);
+ int result = quality.Processor.DynamicParameter;
- Assert.AreEqual(Expected, actual);
+ Assert.AreEqual(expected, result);
}
///
@@ -161,18 +233,25 @@ namespace ImageProcessor.Web.UnitTests
///
/// The rotate regex unit test.
///
+ ///
+ /// The input string.
+ ///
+ ///
+ /// The expected result.
+ ///
[Test]
- public void TestRotateRegex()
+ [TestCase("rotate=0", 0)]
+ [TestCase("rotate=270", 270)]
+ [TestCase("rotate=-270", 0)]
+ [TestCase("rotate=angle-28", 28)]
+ public void TestRotateRegex(string input, int expected)
{
- const string Querystring = "rotate=270";
- const int Expected = 270;
-
Processors.Rotate rotate = new Processors.Rotate();
- rotate.MatchRegexIndex(Querystring);
+ rotate.MatchRegexIndex(input);
- int actual = rotate.Processor.DynamicParameter;
+ int result = rotate.Processor.DynamicParameter;
- Assert.AreEqual(Expected, actual);
+ Assert.AreEqual(expected, result);
}
///
@@ -181,14 +260,26 @@ namespace ImageProcessor.Web.UnitTests
[Test]
public void TestRoundedCornersRegex()
{
- const string Querystring = "roundedcorners=30";
- RoundedCornerLayer expected = new RoundedCornerLayer(30, true, true, true, true);
- Processors.RoundedCorners roundedCorners = new Processors.RoundedCorners();
- roundedCorners.MatchRegexIndex(Querystring);
+ Dictionary data = new Dictionary
+ {
+ {
+ "roundedcorners=30", new RoundedCornerLayer(30, true, true, true, true)
+ },
+ {
+ "roundedcorners=radius-26|tl-true|tr-false|bl-true|br-false", new RoundedCornerLayer(26, true, false, true, false)
+ },
+ {
+ "roundedcorners=26,tl=true,tr=false,bl=true,br=false", new RoundedCornerLayer(26, true, false, true, false)
+ }
+ };
- RoundedCornerLayer actual = roundedCorners.Processor.DynamicParameter;
-
- Assert.AreEqual(expected, actual);
+ Processors.RoundedCorners roundedCorners = new Processors.RoundedCorners();
+ foreach (KeyValuePair item in data)
+ {
+ roundedCorners.MatchRegexIndex(item.Key);
+ RoundedCornerLayer result = roundedCorners.Processor.DynamicParameter;
+ Assert.AreEqual(item.Value, result);
+ }
}
///
diff --git a/src/ImageProcessor.Web/NET45/Helpers/CommonParameterParserUtility.cs b/src/ImageProcessor.Web/NET45/Helpers/CommonParameterParserUtility.cs
index 505d80d99b..22c266a85f 100644
--- a/src/ImageProcessor.Web/NET45/Helpers/CommonParameterParserUtility.cs
+++ b/src/ImageProcessor.Web/NET45/Helpers/CommonParameterParserUtility.cs
@@ -37,7 +37,7 @@ namespace ImageProcessor.Web.Helpers
///
/// The regular expression to search strings for values between 1 and 100.
///
- private static readonly Regex In100RangeRegex = new Regex(@"(-?(?:100)|-?([1-9]?[0-9]))", RegexOptions.Compiled);
+ private static readonly Regex In100RangeRegex = new Regex(@"(-?(0*(?:[1-9][0-9]?|100)))", RegexOptions.Compiled);
///
/// The sharpen regex.
diff --git a/src/ImageProcessor/Configuration/ImageProcessorBootstrapper.cs b/src/ImageProcessor/Configuration/ImageProcessorBootstrapper.cs
index 59f975fb3a..4cffe51eb4 100644
--- a/src/ImageProcessor/Configuration/ImageProcessorBootstrapper.cs
+++ b/src/ImageProcessor/Configuration/ImageProcessorBootstrapper.cs
@@ -73,13 +73,6 @@ namespace ImageProcessor.Configuration
try
{
Type type = typeof(ISupportedImageFormat);
- HashSet found = new HashSet();
-
- // Get any references and used assemblies.
- foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
- {
- this.LoadReferencedAssemblies(found, assembly);
- }
// Get any referenced but not used assemblies.
Assembly executingAssembly = Assembly.GetExecutingAssembly();
@@ -88,6 +81,7 @@ namespace ImageProcessor.Configuration
// ReSharper disable once AssignNullToNotNullAttribute
FileInfo[] files = new DirectoryInfo(targetBasePath).GetFiles("*.dll", SearchOption.AllDirectories);
+ HashSet found = new HashSet();
foreach (FileInfo fileInfo in files)
{
AssemblyName assemblyName = AssemblyName.GetAssemblyName(fileInfo.FullName);