public void RaisePostBackEvent_WhenCalledWithValidArguments_ResizesAndSavesImage()
        {
            // Arrange
            var toolCanvasSize = new ToolCanvasSize();

            _imageEditor.Toolbar.Tools.Add(toolCanvasSize);
            _imageEditor.DirectWrite = true;

            // RaisePostBackEvent method eventArgument parameter scheme
            // int width; int height; AnchorType anchor
            // AnchorType values: TopLeft, TopCenter, TopRight, MiddleLeft, MiddleCenter, MiddleRight, BottomLeft, BottomCenter, BottomRight

            // resize
            // width: 100, height: 50
            var raisePostBackEventArgs = "100;50;TopLeft;";

            // Act
            toolCanvasSize.RaisePostBackEvent(raisePostBackEventArgs);

            // Assert
            var imagePath = _shimHttpServerUtility.Instance.MapPath(_imageEditor.ImageURL);

            using (var image = ActivePixToolsTestHelper.LoadImage(imagePath))
            {
                image.Width.ShouldBe(100);
                image.Height.ShouldBe(50);
            }
        }
Beispiel #2
0
        public void CropClicked_IfDirectWriteSetAsTrueAndX1Y1OfSelectionSetAsZero_CropsAndSavesImageDirectly()
        {
            // Arrange
            var toolCrop = new ToolCrop();
            var toolCropPrivateWrapper = new MsUnitTesting.PrivateObject(toolCrop);

            _imageEditor.Toolbar.Tools.Add(toolCrop);
            _imageEditor.DirectWrite = true;

            // Values for cropping the black section
            _imageEditor.Selection.X1 = 0;
            _imageEditor.Selection.Y1 = 0;
            _imageEditor.Selection.X2 = 50;
            _imageEditor.Selection.Y2 = 50;

            // Act
            toolCropPrivateWrapper.Invoke("CropClicked", null, EventArgs.Empty);

            // Assert
            var imagePath = _shimHttpServerUtility.Instance.MapPath(_imageEditor.ImageURL);

            using (var image = ActivePixToolsTestHelper.LoadImage(imagePath))
            {
                image.Width.ShouldBe(50);
                image.Height.ShouldBe(50);

                var firstPixelOfTheImage = image.GetPixel(0, 0);

                firstPixelOfTheImage.A.ShouldBe(Color.Black.A);
                firstPixelOfTheImage.R.ShouldBe(Color.Black.R);
                firstPixelOfTheImage.G.ShouldBe(Color.Black.G);
                firstPixelOfTheImage.B.ShouldBe(Color.Black.B);
            }
        }
Beispiel #3
0
        public void RaisePostBackEvent_IfEventArgumentIsSetForRotateDegreesAnd180Degrees_Rotates180DegreesAndSavesImage()
        {
            // Arrange
            var toolRotate = new ToolRotate();

            _imageEditor.Toolbar.Tools.Add(toolRotate);
            _imageEditor.DirectWrite = true;

            // RaisePostBackEvent method eventArgument parameter scheme
            // bool rotateLeft; bool rotateRight; bool rotateDegrees; float degrees

            // rotateDegrees: true; degrees: 180
            var raisePostBackEventArgs = "false;false;true;180";

            // Act
            toolRotate.RaisePostBackEvent(raisePostBackEventArgs);

            // Assert
            var imagePath = _shimHttpServerUtility.Instance.MapPath(_imageEditor.ImageURL);

            using (var image = ActivePixToolsTestHelper.LoadImage(imagePath))
            {
                image.Width.ShouldBe(InitialImageWidth);
                image.Height.ShouldBe(InitialImageHeight);

                var firstPixelOfImage = image.GetPixel(0, 0);

                firstPixelOfImage.A.ShouldBe(Color.Gray.A);
                firstPixelOfImage.R.ShouldBe(Color.Gray.R);
                firstPixelOfImage.G.ShouldBe(Color.Gray.G);
                firstPixelOfImage.B.ShouldBe(Color.Gray.B);
            }
        }
        public void RaisePostBackEvent_IfDirectWriteSetAsTrue_SavesImageDirectly()
        {
            // Arrange
            var toolCanvasSize = new ToolCanvasSize();

            _imageEditor.Toolbar.Tools.Add(toolCanvasSize);
            _imageEditor.DirectWrite = true;

            // RaisePostBackEvent method eventArgument parameter scheme
            // int width; int height; AnchorType anchor
            // AnchorType values: TopLeft, TopCenter, TopRight, MiddleLeft, MiddleCenter, MiddleRight, BottomLeft, BottomCenter, BottomRight

            // make no changes
            var raisePostBackEventArgs = string.Format("{0};{1};TopLeft", InitialImageWidth, InitialImageHeight);

            // Act
            toolCanvasSize.RaisePostBackEvent(raisePostBackEventArgs);

            // Assert
            var imagePath = _shimHttpServerUtility.Instance.MapPath(_imageEditor.ImageURL);

            using (var image = ActivePixToolsTestHelper.LoadImage(imagePath))
            {
                image.ShouldNotBeNull();
            }
        }
Beispiel #5
0
        public void MirrorClicked_IfDirectWriteSetAsFalse_MirrorsAndSavesImageToAlternativePath()
        {
            // Arrange
            var toolMirror = new ToolMirror();
            var toolMirrorPrivateWrapper = new MsUnitTesting.PrivateObject(toolMirror);

            _imageEditor.Toolbar.Tools.Add(toolMirror);
            _imageEditor.DirectWrite = false;

            // Act
            toolMirrorPrivateWrapper.Invoke("MirrorClicked", null, EventArgs.Empty);

            // Assert
            var alternativeDirectoryFileNames = Directory.GetFiles(ToolImagesAlternativeDirectory);

            alternativeDirectoryFileNames.Length.ShouldBe(1);

            var imagePath = alternativeDirectoryFileNames[0];

            using (var image = ActivePixToolsTestHelper.LoadImage(imagePath))
            {
                var firstPixelOfTheImage = image.GetPixel(0, 0);

                firstPixelOfTheImage.A.ShouldBe(Color.Gray.A);
                firstPixelOfTheImage.R.ShouldBe(Color.Gray.R);
                firstPixelOfTheImage.G.ShouldBe(Color.Gray.G);
                firstPixelOfTheImage.B.ShouldBe(Color.Gray.B);
            }
        }
Beispiel #6
0
        public void RaisePostBackEvent_IfDirectWriteSetAsTrue_SavesImageDirectly()
        {
            // Arrange
            var toolRotate = new ToolRotate();

            _imageEditor.Toolbar.Tools.Add(toolRotate);
            _imageEditor.DirectWrite = true;

            // RaisePostBackEvent method eventArgument parameter scheme
            // bool rotateLeft; bool rotateRight; bool rotateDegrees; float degrees

            // just save in current state
            var raisePostBackEventArgs = "false;false;false;0";

            // Act
            toolRotate.RaisePostBackEvent(raisePostBackEventArgs);

            // Assert
            var imagePath = _shimHttpServerUtility.Instance.MapPath(_imageEditor.ImageURL);

            using (var image = ActivePixToolsTestHelper.LoadImage(imagePath))
            {
                image.ShouldNotBeNull();
            }
        }
        public void RaisePostBackEvent_IfDirectWriteSetAsTrue_ZoomsAndSavesImageDirectly()
        {
            // Arrange
            var toolZoom = new ToolZoom();

            _imageEditor.Toolbar.Tools.Add(toolZoom);
            _imageEditor.DirectWrite = true;

            // RaisePostBackEvent method eventArgument parameter scheme
            // float factor

            // zoom 4 times to test if all image is gray colored
            var raisePostBackEventArgs = "200";

            // select center point to be zoomed
            _imageEditor.Selection.X1 = 151;
            _imageEditor.Selection.Y1 = 76;

            // Act
            toolZoom.RaisePostBackEvent(raisePostBackEventArgs);

            // Assert
            var imagePath = _shimHttpServerUtility.Instance.MapPath(_imageEditor.ImageURL);

            using (var image = ActivePixToolsTestHelper.LoadImage(imagePath))
            {
                var firstPixelOfImage = image.GetPixel(0, 0);

                firstPixelOfImage.A.ShouldBe(Color.Gray.A);
                firstPixelOfImage.R.ShouldBe(Color.Gray.R);
                firstPixelOfImage.G.ShouldBe(Color.Gray.G);
                firstPixelOfImage.B.ShouldBe(Color.Gray.B);
            }
        }
Beispiel #8
0
        public void MirrorClicked_IfDirectWriteSetAsTrue_MirrorsAndSavesImageDirectly()
        {
            // Arrange
            var toolMirror = new ToolMirror();
            var toolMirrorPrivateWrapper = new MsUnitTesting.PrivateObject(toolMirror);

            _imageEditor.Toolbar.Tools.Add(toolMirror);
            _imageEditor.DirectWrite = true;

            // Act
            toolMirrorPrivateWrapper.Invoke("MirrorClicked", null, EventArgs.Empty);

            // Assert
            var imagePath = _shimHttpServerUtility.Instance.MapPath(_imageEditor.ImageURL);

            using (var image = ActivePixToolsTestHelper.LoadImage(imagePath))
            {
                var firstPixelOfTheImage = image.GetPixel(0, 0);

                firstPixelOfTheImage.A.ShouldBe(Color.Gray.A);
                firstPixelOfTheImage.R.ShouldBe(Color.Gray.R);
                firstPixelOfTheImage.G.ShouldBe(Color.Gray.G);
                firstPixelOfTheImage.B.ShouldBe(Color.Gray.B);
            }
        }
Beispiel #9
0
        public void RaisePostBackEvent_IfEventArgsAreProper_ResizesAndSavesImage()
        {
            // Arrange
            var toolImageSize = new ToolImageSize();

            _imageEditor.Toolbar.Tools.Add(toolImageSize);
            _imageEditor.DirectWrite = true;

            // RaisePostBackEvent method eventArgument parameter scheme
            // int width; int height; bool constrainProportions; bool resizeSmaller
            // NOTE: job.ResizeImage() method that called inside of RaisePostBackEvent only resized image if
            // new values are smaller than original. resizeSmaller parameter doesn't work!

            // resize
            // width: 100, height: 50
            var raisePostBackEventArgs = "100;50;false;false";

            // Act
            toolImageSize.RaisePostBackEvent(raisePostBackEventArgs);

            // Assert
            var imagePath = _shimHttpServerUtility.Instance.MapPath(_imageEditor.ImageURL);

            using (var image = ActivePixToolsTestHelper.LoadImage(imagePath))
            {
                image.Width.ShouldBe(100);
                image.Height.ShouldBe(50);
            }
        }
Beispiel #10
0
        public void RaisePostBackEvent_IfDirectWriteSetAsTrue_SavesImageDirectly()
        {
            // Arrange
            var toolImageSize = new ToolImageSize();

            _imageEditor.Toolbar.Tools.Add(toolImageSize);
            _imageEditor.DirectWrite = true;

            // RaisePostBackEvent method eventArgument parameter scheme
            // int width; int height; bool constrainProportions; bool resizeSmaller
            // NOTE: job.ResizeImage() method that called inside of RaisePostBackEvent only resized image if
            // new values are smaller than original. resizeSmaller parameter doesn't work!

            // Args for no changes on image
            var raisePostBackEventArgs = string.Format("{0};{1};false;false", InitialImageWidth, InitialImageHeight);

            // Act
            toolImageSize.RaisePostBackEvent(raisePostBackEventArgs);

            // Assert
            var imagePath = _shimHttpServerUtility.Instance.MapPath(_imageEditor.ImageURL);

            using (var image = ActivePixToolsTestHelper.LoadImage(imagePath))
            {
                image.ShouldNotBeNull();
            }
        }
Beispiel #11
0
        public void SetUp()
        {
            var imageFileName        = string.Format("{0}.jpg", Guid.NewGuid());
            var imageFileServerPath  = string.Format("{0}\\{1}", ToolImagesDirectory, imageFileName);
            var imageFileVirtualPath = string.Format("/{0}/{1}", ToolImagesFolderName, imageFileName);
            var image = ActivePixToolsTestHelper.CreateDummyImage(InitialImageWidth, InitialImageHeight, ActivePixToolsTestHelper.ColorsDirection.Vertical, new Color[] { Color.Black, Color.Gray });

            ActivePixToolsTestHelper.SaveImage(image, imageFileServerPath);

            var alternativeFiles = Directory.GetFiles(ToolImagesAlternativeDirectory);

            foreach (var file in alternativeFiles)
            {
                System.IO.File.Delete(file);
            }

            _imageEditor               = new ImageEditor();
            _imageEditor.Page          = _shimPage;
            _imageEditor.ImageURL      = imageFileVirtualPath;
            _imageEditor.TempURL       = imageFileVirtualPath;
            _imageEditor.TempDirectory = string.Format("/{0}/", ToolImagesAlternativeFolderName);

            _imageEditorPrivateWrapper = new MsUnitTesting.PrivateObject(_imageEditor);
            _imageEditorPrivateWrapper.Invoke("OnInit", EventArgs.Empty);
        }
        public void RaisePostBackEvent_IfDirectWriteSetAsTrue_SavesImageDirectly()
        {
            // Arrange
            var toolText = new ToolText();

            _imageEditor.Toolbar.Tools.Add(toolText);
            _imageEditor.DirectWrite = true;

            // RaisePostBackEvent method eventArgument parameter scheme
            // string text; Color forecolor; FontStyle style; int size; string font; boolean antialias; StringAlignment alignment

            // sample args to toolText
            var raisePostBackEventArgs = "lorem ipsum; White; Regular; 20; Arial; false; Near";

            // text starting point
            _imageEditor.Selection.X1 = 10;
            _imageEditor.Selection.Y1 = 10;

            // Act
            toolText.RaisePostBackEvent(raisePostBackEventArgs);

            // Assert
            var imagePath = _shimHttpServerUtility.Instance.MapPath(_imageEditor.ImageURL);

            using (var image = ActivePixToolsTestHelper.LoadImage(imagePath))
            {
                image.ShouldNotBeNull();
            }
        }
Beispiel #13
0
        public void CropClicked_IfDirectWriteSetAsFalseAndIfSelectionValuesAreProper_CropsAndSavesImageToAlternativePath()
        {
            // Arrange
            var toolCrop = new ToolCrop();
            var toolCropPrivateWrapper = new MsUnitTesting.PrivateObject(toolCrop);

            _imageEditor.Toolbar.Tools.Add(toolCrop);
            _imageEditor.DirectWrite = false;

            // Values for cropping the gray section
            _imageEditor.Selection.X1 = 150;
            _imageEditor.Selection.Y1 = 50;
            _imageEditor.Selection.X2 = 200;
            _imageEditor.Selection.Y2 = 100;

            // Act
            toolCropPrivateWrapper.Invoke("CropClicked", null, EventArgs.Empty);

            // Assert
            var alternativeDirectoryFileNames = Directory.GetFiles(ToolImagesAlternativeDirectory);

            alternativeDirectoryFileNames.Length.ShouldBe(1);

            var imagePath = alternativeDirectoryFileNames[0];

            using (var image = ActivePixToolsTestHelper.LoadImage(imagePath))
            {
                image.Width.ShouldBe(50);
                image.Height.ShouldBe(50);

                var firstPixelOfTheImage = image.GetPixel(0, 0);

                firstPixelOfTheImage.A.ShouldBe(Color.Gray.A);
                firstPixelOfTheImage.R.ShouldBe(Color.Gray.R);
                firstPixelOfTheImage.G.ShouldBe(Color.Gray.G);
                firstPixelOfTheImage.B.ShouldBe(Color.Gray.B);
            }
        }
        public void RaisePostBackEvent_IfDirectWriteSetAsFalse_ZoomsAndSavesImageToAlternativePath()
        {
            // Arrange
            var toolZoom = new ToolZoom();

            _imageEditor.Toolbar.Tools.Add(toolZoom);
            _imageEditor.DirectWrite = false;

            // RaisePostBackEvent method eventArgument parameter scheme
            // float factor

            // zoom 4 times to test if all image is gray colored
            var raisePostBackEventArgs = "200";

            // select center point to be zoomed
            _imageEditor.Selection.X1 = 151;
            _imageEditor.Selection.Y1 = 76;

            // Act
            toolZoom.RaisePostBackEvent(raisePostBackEventArgs);

            // Assert
            var alternativeDirectoryFileNames = Directory.GetFiles(ToolImagesAlternativeDirectory);

            alternativeDirectoryFileNames.Length.ShouldBe(1);

            var imagePath = alternativeDirectoryFileNames[0];

            using (var image = ActivePixToolsTestHelper.LoadImage(imagePath))
            {
                var firstPixelOfImage = image.GetPixel(0, 0);

                firstPixelOfImage.A.ShouldBe(Color.Gray.A);
                firstPixelOfImage.R.ShouldBe(Color.Gray.R);
                firstPixelOfImage.G.ShouldBe(Color.Gray.G);
                firstPixelOfImage.B.ShouldBe(Color.Gray.B);
            }
        }