public void Test_Coordinates() { ExceptionAssert.Throws <InvalidOperationException>(delegate() { using (var logo = Images.Logo) { TshirtScript script = new TshirtScript(); script.Execute(logo, logo); } }, "No coordinates have been set."); var invalid = new PointD[] { new PointD(-10, 10), new PointD(10, -10), new PointD(650, 10), new PointD(630, 490) }; for (int i = 0; i < invalid.Length; i++) { Test_SetCoordinates("topLeft", invalid[i], _TopRight, _BottomLeft, _BottomRight); Test_SetCoordinates("topRight", _TopLeft, invalid[i], _BottomLeft, _BottomRight); Test_SetCoordinates("bottomLeft", _TopLeft, _TopRight, invalid[i], _BottomRight); Test_SetCoordinates("bottomRight", _TopLeft, _TopRight, _BottomLeft, invalid[i]); } }
public void Execute_ImageWithAlpha_AlphaIsRestored() { var tshirtFile = GetInputFile("tshirt_gray.jpg"); var overlayFile = GetInputFile("flowers_van_gogh.jpg"); using (var tshirtImage = new MagickImage(tshirtFile)) { tshirtImage.Opaque(new MagickColor("#FEFEFE"), MagickColors.None); using (var overlayImage = new MagickImage(overlayFile)) { overlayImage.Crop(479, 479); var script = new TshirtScript { Fit = TshirtFit.Crop, Blur = 0, Lighting = 0, Sharpen = 0 }; script.SetCoordinates(new MagickGeometry(275, 175, 130, 130)); using (var scriptOutput = script.Execute(tshirtImage, overlayImage)) { AssertOutput(scriptOutput, "flowers_van_gogh_alpha.jpg"); } } } }
public void Execute_ImageWithAlpha_AlphaIsRestored() { var tshirtFile = GetInputFile("tshirt_gray.jpg"); /* LosslessCompress(tshirtFile); */ var overlayFile = GetInputFile("flowers_van_gogh.jpg"); /* LosslessCompress(overlayFile); */ using (var tshirtImage = new MagickImage(tshirtFile)) { tshirtImage.Opaque(MagickColors.White, MagickColors.None); using (var overlayImage = new MagickImage(overlayFile)) { overlayImage.Crop(479, 479); var script = new TshirtScript(); script.Fit = TshirtFit.Crop; script.Blur = 0; script.Lighting = 0; script.Sharpen = 0; script.SetCoordinates(new MagickGeometry(275, 175, 130, 130)); using (var scriptOutput = script.Execute(tshirtImage, overlayImage)) { AssertOutput(scriptOutput, "flowers_van_gogh_alpha.jpg"); } } } }
public void Excecute_TshirtNull_ThrowsException() { using (var logo = Images.Logo) { ExceptionAssert.ThrowsArgumentException <ArgumentNullException>("tshirt", () => { TshirtScript script = new TshirtScript(); script.Execute(null, logo); }); } }
public void Excecute_OverlayNull_ThrowsException() { using (var logo = Images.Logo) { ExceptionAssert.ThrowsArgumentException <ArgumentNullException>("overlay", () => { TshirtScript script = new TshirtScript(); script.Execute(logo, null); }); } }
public void Execute_NoCoordinatesSet_ThrowsException() { ExceptionAssert.Throws <InvalidOperationException>("No coordinates have been set.", () => { using (var logo = Images.Logo) { TshirtScript script = new TshirtScript(); script.Execute(logo, logo); } }); }
private static void AssertCoordinates(string paramName, PointD topLeft, PointD topRight, PointD bottomLeft, PointD bottomRight) { ExceptionAssert.ThrowsArgumentException <ArgumentOutOfRangeException>(paramName, () => { using (MagickImage logo = Images.Logo) { TshirtScript script = new TshirtScript(); script.SetCoordinates(topLeft, topRight, bottomLeft, bottomRight); script.Execute(logo, logo); } }); }
public void Test_Settings() { var script = new TshirtScript(); using (var logo = Images.Logo) { Reset(script); script.Execute(logo, logo); ExceptionAssert.Throws <InvalidOperationException>(delegate() { Reset(script); script.Gravity = Gravity.Forget; script.Execute(logo, logo); }, "Invalid Gravity specified."); ExceptionAssert.Throws <InvalidOperationException>(delegate() { Reset(script); script.Rotation = -361; script.Execute(logo, logo); }, "Invalid Rotation specified."); ExceptionAssert.Throws <InvalidOperationException>(delegate() { Reset(script); script.Rotation = 361; script.Execute(logo, logo); }, "Invalid Rotation specified."); ExceptionAssert.Throws <InvalidOperationException>(delegate() { Reset(script); script.Lighting = -1; script.Execute(logo, logo); }, "Invalid Lightning specified."); ExceptionAssert.Throws <InvalidOperationException>(delegate() { Reset(script); script.Lighting = 31; script.Execute(logo, logo); }, "Invalid Lightning specified."); ExceptionAssert.Throws <InvalidOperationException>(delegate() { Reset(script); script.Blur = -1; script.Execute(logo, logo); }, "Invalid Blur specified."); } }
private void AssertInvalidOperation(string expectedMessage, Action <TshirtScript> initAction) { var script = new TshirtScript(); using (var logo = new MagickImage(Images.Logo)) { initAction(script); ExceptionAssert.Throws <InvalidOperationException>(expectedMessage, () => { script.SetCoordinates(_topLeft, _topRight, _bottomLeft, _bottomRight); script.Execute(logo, logo); }); } }
private void Test_Execute(string tshirt, string overlay, Action <TshirtScript> action, string output) { var tshirtFile = GetInputFile(tshirt); var overlayFile = GetInputFile(overlay); using (var tshirtImage = new MagickImage(tshirtFile)) { using (var overlayImage = new MagickImage(overlayFile)) { var script = new TshirtScript(); action(script); var scriptOutput = script.Execute(tshirtImage, overlayImage); TestOutput(scriptOutput, output); } } }
public void Test_Excecute_Null() { using (var logo = Images.Logo) { ExceptionAssert.ThrowsArgumentException <ArgumentNullException>(delegate() { TshirtScript script = new TshirtScript(); script.Execute(null, logo); }, "tshirt"); ExceptionAssert.ThrowsArgumentException <ArgumentNullException>(delegate() { TshirtScript script = new TshirtScript(); script.Execute(logo, null); }, "overlay"); } }
private void AssertExecute(string tshirt, string overlay, string methodName, Action <TshirtScript> action) { var tshirtFile = GetInputFile(tshirt); /* LosslessCompress(tshirtFile); */ var overlayFile = GetInputFile(overlay); /* LosslessCompress(overlayFile); */ using (var tshirtImage = new MagickImage(tshirtFile)) { using (var overlayImage = new MagickImage(overlayFile)) { var script = new TshirtScript(); action(script); using (var scriptOutput = script.Execute(tshirtImage, overlayImage)) { string outputFile = GetOutputFile(overlay, methodName); AssertOutput(scriptOutput, outputFile); } } } }