Browse Source

Fix dll load plus regex tests

Former-commit-id: 16389800dc947aa8032737685e69e84f46708aa0
af/merge-core
James South 12 years ago
parent
commit
5ecb68ebf1
  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 namespace ImageProcessor.UnitTests.Extensions
{ {
using System.Collections.Generic;
using Common.Extensions; using Common.Extensions;
using NUnit.Framework; using NUnit.Framework;
@ -20,37 +19,20 @@ namespace ImageProcessor.UnitTests.Extensions
[TestFixture] [TestFixture]
public class DoubleExtensionsUnitTests 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> /// <summary>
/// Tests the double to byte conversion /// Tests the double to byte conversion
/// </summary> /// </summary>
/// <param name="input">Double input</param>
/// <param name="expected">Expected result</param>
[Test] [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) byte result = input.ToByte();
{ Assert.AreEqual(expected, result);
var result = item.Key.ToByte();
Assert.AreEqual(item.Value, result);
}
} }
} }
} }

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

@ -69,6 +69,10 @@
<Project>{3b5dd734-fb7a-487d-8ce6-55e7af9aea7e}</Project> <Project>{3b5dd734-fb7a-487d-8ce6-55e7af9aea7e}</Project>
<Name>ImageProcessor</Name> <Name>ImageProcessor</Name>
</ProjectReference> </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> </ItemGroup>
<Choose> <Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'"> <When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">

201
src/ImageProcessor.Web.UnitTests/RegularExpressionUnitTests.cs

@ -10,10 +10,14 @@
namespace ImageProcessor.Web.UnitTests namespace ImageProcessor.Web.UnitTests
{ {
using System;
using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using ImageProcessor.Imaging; using ImageProcessor.Imaging;
using ImageProcessor.Imaging.Filters; using ImageProcessor.Imaging.Filters;
using ImageProcessor.Imaging.Formats; using ImageProcessor.Imaging.Formats;
using ImageProcessor.Plugins.WebP.Imaging.Formats;
using NUnit.Framework; using NUnit.Framework;
/// <summary> /// <summary>
@ -40,37 +44,55 @@ namespace ImageProcessor.Web.UnitTests
} }
/// <summary> /// <summary>
/// The brightness regex unit test. /// The contrast regex unit test.
/// </summary> /// </summary>
/// <param name="input">
/// The input string.
/// </param>
/// <param name="expected">
/// The expected result.
/// </param>
[Test] [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(); 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, result);
Assert.AreEqual(Expected, actual);
} }
/// <summary> /// <summary>
/// The contrast regex unit test. /// The contrast regex unit test.
/// </summary> /// </summary>
/// <param name="input">
/// The input string.
/// </param>
/// <param name="expected">
/// The expected result.
/// </param>
[Test] [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(); Processors.Contrast contrast = new Processors.Contrast();
contrast.MatchRegexIndex(Querystring); contrast.MatchRegexIndex(input);
int result = contrast.Processor.DynamicParameter;
int actual = contrast.Processor.DynamicParameter;
Assert.AreEqual(Expected, actual); Assert.AreEqual(expected, result);
} }
/// <summary> /// <summary>
@ -93,52 +115,102 @@ namespace ImageProcessor.Web.UnitTests
/// The filter regex unit test. /// The filter regex unit test.
/// </summary> /// </summary>
[Test] [Test]
public void TestFilterRegex() public void TestFilterRegex()
{ {
// Should really write more for the other filters. Dictionary<string, IMatrixFilter> data = new Dictionary<string, IMatrixFilter>
const string Querystring = "filter=lomograph"; {
IMatrixFilter expected = MatrixFilters.Lomograph; {
"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(); Processors.Filter filter = new Processors.Filter();
filter.MatchRegexIndex(Querystring); foreach (KeyValuePair<string, IMatrixFilter> item in data)
{
IMatrixFilter actual = filter.Processor.DynamicParameter; filter.MatchRegexIndex(item.Key);
IMatrixFilter result = filter.Processor.DynamicParameter;
Assert.AreEqual(expected, actual); Assert.AreEqual(item.Value, result);
}
} }
/// <summary> /// <summary>
/// The format regex unit test. /// The format regex unit test.
/// </summary> /// </summary>
/// <param name="input">
/// The input querystring.
/// </param>
/// <param name="expected">
/// The expected type.
/// </param>
[Test] [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(); Processors.Format format = new Processors.Format();
format.MatchRegexIndex(Querystring); format.MatchRegexIndex(input);
Type result = format.Processor.DynamicParameter.GetType();
ISupportedImageFormat actual = format.Processor.DynamicParameter;
Assert.AreEqual(expected, actual); Assert.AreEqual(expected, result);
} }
/// <summary> /// <summary>
/// The quality regex unit test. /// The quality regex unit test.
/// </summary> /// </summary>
/// <param name="input">
/// The input.
/// </param>
/// <param name="expected">
/// The expected result.
/// </param>
[Test] [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(); Processors.Quality quality = new Processors.Quality();
quality.MatchRegexIndex(Querystring); quality.MatchRegexIndex(input);
int result = quality.Processor.DynamicParameter;
int actual = quality.Processor.DynamicParameter;
Assert.AreEqual(Expected, actual); Assert.AreEqual(expected, result);
} }
/// <summary> /// <summary>
@ -161,18 +233,25 @@ namespace ImageProcessor.Web.UnitTests
/// <summary> /// <summary>
/// The rotate regex unit test. /// The rotate regex unit test.
/// </summary> /// </summary>
/// <param name="input">
/// The input string.
/// </param>
/// <param name="expected">
/// The expected result.
/// </param>
[Test] [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(); 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> /// <summary>
@ -181,14 +260,26 @@ namespace ImageProcessor.Web.UnitTests
[Test] [Test]
public void TestRoundedCornersRegex() public void TestRoundedCornersRegex()
{ {
const string Querystring = "roundedcorners=30"; Dictionary<string, RoundedCornerLayer> data = new Dictionary<string, RoundedCornerLayer>
RoundedCornerLayer expected = new RoundedCornerLayer(30, true, true, true, true); {
Processors.RoundedCorners roundedCorners = new Processors.RoundedCorners(); {
roundedCorners.MatchRegexIndex(Querystring); "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; Processors.RoundedCorners roundedCorners = new Processors.RoundedCorners();
foreach (KeyValuePair<string, RoundedCornerLayer> item in data)
Assert.AreEqual(expected, actual); {
roundedCorners.MatchRegexIndex(item.Key);
RoundedCornerLayer result = roundedCorners.Processor.DynamicParameter;
Assert.AreEqual(item.Value, result);
}
} }
/// <summary> /// <summary>

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

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

8
src/ImageProcessor/Configuration/ImageProcessorBootstrapper.cs

@ -73,13 +73,6 @@ namespace ImageProcessor.Configuration
try try
{ {
Type type = typeof(ISupportedImageFormat); 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. // Get any referenced but not used assemblies.
Assembly executingAssembly = Assembly.GetExecutingAssembly(); Assembly executingAssembly = Assembly.GetExecutingAssembly();
@ -88,6 +81,7 @@ namespace ImageProcessor.Configuration
// ReSharper disable once AssignNullToNotNullAttribute // ReSharper disable once AssignNullToNotNullAttribute
FileInfo[] files = new DirectoryInfo(targetBasePath).GetFiles("*.dll", SearchOption.AllDirectories); FileInfo[] files = new DirectoryInfo(targetBasePath).GetFiles("*.dll", SearchOption.AllDirectories);
HashSet<string> found = new HashSet<string>();
foreach (FileInfo fileInfo in files) foreach (FileInfo fileInfo in files)
{ {
AssemblyName assemblyName = AssemblyName.GetAssemblyName(fileInfo.FullName); AssemblyName assemblyName = AssemblyName.GetAssemblyName(fileInfo.FullName);

Loading…
Cancel
Save