Browse Source

Fix dll load plus regex tests

Former-commit-id: 2778a682ce325c1739e49f1e88ab7c5a8fa9f431
af/merge-core
James South 12 years ago
parent
commit
158ae434d5
  1. 36
      src/ImageProcessor.UnitTests/Extensions/DoubleExtensionsUnitTests.cs
  2. 4
      src/ImageProcessor.Web.UnitTests/ImageProcessor.Web.UnitTests.csproj
  3. 201
      src/ImageProcessor.Web.UnitTests/RegularExpressionUnitTests.cs
  4. 2
      src/ImageProcessor.Web/NET45/Helpers/CommonParameterParserUtility.cs
  5. 8
      src/ImageProcessor/Configuration/ImageProcessorBootstrapper.cs

36
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
{
/// <summary>
/// Stores the values to test for the ToByte() extension method
/// </summary>
private Dictionary<double, byte> doubleToByteTests;
/// <summary>
/// Sets up the values for the tests
/// </summary>
[TestFixtureSetUp]
public void Init()
{
this.doubleToByteTests = new Dictionary<double, byte>
{
{ -10, 0x0 },
{ 1.5, 0x1 },
{ 25.7, 0x19 },
{ 1289047, 0xFF }
};
}
/// <summary>
/// Tests the double to byte conversion
/// </summary>
/// <param name="input">Double input</param>
/// <param name="expected">Expected result</param>
[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);
}
}
}

4
src/ImageProcessor.Web.UnitTests/ImageProcessor.Web.UnitTests.csproj

@ -69,6 +69,10 @@
<Project>{3b5dd734-fb7a-487d-8ce6-55e7af9aea7e}</Project>
<Name>ImageProcessor</Name>
</ProjectReference>
<ProjectReference Include="..\Plugins\ImageProcessor\ImageProcessor.Plugins.WebP\ImageProcessor.Plugins.WebP.csproj">
<Project>{2cf69699-959a-44dc-a281-4e2596c25043}</Project>
<Name>ImageProcessor.Plugins.WebP</Name>
</ProjectReference>
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">

201
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;
/// <summary>
@ -40,37 +44,55 @@ namespace ImageProcessor.Web.UnitTests
}
/// <summary>
/// The brightness regex unit test.
/// The contrast regex unit test.
/// </summary>
/// <param name="input">
/// The input string.
/// </param>
/// <param name="expected">
/// The expected result.
/// </param>
[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);
}
/// <summary>
/// The contrast regex unit test.
/// </summary>
/// <param name="input">
/// The input string.
/// </param>
/// <param name="expected">
/// The expected result.
/// </param>
[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);
}
/// <summary>
@ -93,52 +115,102 @@ namespace ImageProcessor.Web.UnitTests
/// The filter regex unit test.
/// </summary>
[Test]
public void TestFilterRegex()
{
// Should really write more for the other filters.
const string Querystring = "filter=lomograph";
IMatrixFilter expected = MatrixFilters.Lomograph;
Dictionary<string, IMatrixFilter> data = new Dictionary<string, IMatrixFilter>
{
{
"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<string, IMatrixFilter> item in data)
{
filter.MatchRegexIndex(item.Key);
IMatrixFilter result = filter.Processor.DynamicParameter;
Assert.AreEqual(item.Value, result);
}
}
/// <summary>
/// The format regex unit test.
/// </summary>
/// <param name="input">
/// The input querystring.
/// </param>
/// <param name="expected">
/// The expected type.
/// </param>
[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);
}
/// <summary>
/// The quality regex unit test.
/// </summary>
/// <param name="input">
/// The input.
/// </param>
/// <param name="expected">
/// The expected result.
/// </param>
[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);
}
/// <summary>
@ -161,18 +233,25 @@ namespace ImageProcessor.Web.UnitTests
/// <summary>
/// The rotate regex unit test.
/// </summary>
/// <param name="input">
/// The input string.
/// </param>
/// <param name="expected">
/// The expected result.
/// </param>
[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);
}
/// <summary>
@ -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<string, RoundedCornerLayer> data = new Dictionary<string, RoundedCornerLayer>
{
{
"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<string, RoundedCornerLayer> item in data)
{
roundedCorners.MatchRegexIndex(item.Key);
RoundedCornerLayer result = roundedCorners.Processor.DynamicParameter;
Assert.AreEqual(item.Value, result);
}
}
/// <summary>

2
src/ImageProcessor.Web/NET45/Helpers/CommonParameterParserUtility.cs

@ -37,7 +37,7 @@ namespace ImageProcessor.Web.Helpers
/// <summary>
/// The regular expression to search strings for values between 1 and 100.
/// </summary>
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);
/// <summary>
/// The sharpen regex.

8
src/ImageProcessor/Configuration/ImageProcessorBootstrapper.cs

@ -73,13 +73,6 @@ namespace ImageProcessor.Configuration
try
{
Type type = typeof(ISupportedImageFormat);
HashSet<string> found = new HashSet<string>();
// 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<string> found = new HashSet<string>();
foreach (FileInfo fileInfo in files)
{
AssemblyName assemblyName = AssemblyName.GetAssemblyName(fileInfo.FullName);

Loading…
Cancel
Save