public override void TestRestoreManipulationsCore()
        {
            var image = new CodedImage {
                Size = new Size(30, 20), Palette = new CodedPalette()
            };

            image.CompletePalette();
            for (int x = 0; x < 30; x++)
            {
                for (int y = 0; y < 20; y++)
                {
                    image[x, y] = new CodedColor((byte)(x * 8), (byte)(y * 12), (byte)((x + y) * 5));
                }
            }

            var dummyManipulator = new ImageManipulatorTest.DummyManipulator(image);
            var colorer          = new ImageColorsManipulator(dummyManipulator);
            var childManipulator = new ImageManipulatorTest.DummyManipulator(colorer);

            colorer.QuantizeColors(3);
            Assert.AreEqual(3, colorer.ManipulatedImage.Palette.Count);

            colorer.ManipulatedImage.Palette.Add(new CodedColor(254, 254, 254));
            childManipulator.RestoreManipulationsCoreFired = false;

            Assert.AreEqual(4, colorer.ManipulatedImage.Palette.Count, "Precondition");
            Assert.IsFalse(childManipulator.RestoreManipulationsCoreFired);

            dummyManipulator.CallOnImageChanged();

            Assert.AreEqual(3, colorer.ManipulatedImage.Palette.Count);
            Assert.IsFalse(childManipulator.RestoreManipulationsCoreFired);
            Assert.NotNull(childManipulator.ManipulatedImage);
            Assert.IsTrue(childManipulator.RestoreManipulationsCoreFired);
        }
 protected void AssertActionCallsOnImageChanged(ImageManipulatorTest.DummyManipulator childManipulator, Action action)
 {
     Assert.NotNull(childManipulator.ManipulatedImage);
     childManipulator.RestoreManipulationsCoreFired = false;
     Assert.IsFalse(childManipulator.RestoreManipulationsCoreFired, "Precondition");
     action();
     Assert.IsTrue(childManipulator.RestoreManipulationsCoreFired);
 }
        public void TestOperationsCallsOnImageChanged()
        {
            var image = new CodedImage {
                Size = new Size(30, 20)
            };
            var colorer          = new ImageColorsManipulator(image);
            var childManipulator = new ImageManipulatorTest.DummyManipulator(colorer);

            AssertActionCallsOnImageChanged(childManipulator, () => colorer.QuantizeColors(3));
        }
        public void TestOperationsCallsOnImageChanged()
        {
            var image = new CodedImage {
                Size = new Size(5, 5)
            };
            var resizer          = new ImageSizeManipulator(image);
            var childManipulator = new ImageManipulatorTest.DummyManipulator(resizer);

            AssertActionCallsOnImageChanged(childManipulator, () => resizer.Resize(new Size(3, 3), ImageResampler.FilterType.Box, ImageSizeManipulator.SizeLockType.KeepWidthAndHeight));
        }
        public void TestOperationsCallsOnImageChanged()
        {
            var imageSetter      = new ImageSetterManipulator();
            var childManipulator = new ImageManipulatorTest.DummyManipulator(imageSetter);

            var newImage = new CodedImage {
                Size = new Size(5, 5)
            };

            AssertActionCallsOnImageChanged(childManipulator, () => imageSetter.SetNewImage(newImage));
        }
        public void TestOperationsCallsOnImageChanged()
        {
            var image = new CodedImage {
                Size = new Size(5, 5)
            };
            var cropper          = new ImageCropManipulator(image);
            var childManipulator = new ImageManipulatorTest.DummyManipulator(cropper);

            AssertActionCallsOnImageChanged(childManipulator, () => cropper.CropRect(new Rectangle(1, 1, 3, 3)));
            AssertActionCallsOnImageChanged(childManipulator, () => cropper.CropArc(new Rectangle(1, 1, 3, 3)));
        }
Пример #7
0
        public void TestOperationsCallsOnImageChanged()
        {
            var image = new CodedImage {
                Size = new Size(2, 2)
            };
            var rotator          = new ImageRotateManipulator(image);
            var childManipulator = new ImageManipulatorTest.DummyManipulator(rotator);

            AssertActionCallsOnImageChanged(childManipulator, rotator.RotateCW);
            AssertActionCallsOnImageChanged(childManipulator, rotator.RotateCCW);
            AssertActionCallsOnImageChanged(childManipulator, rotator.FlipHorizontally);
            AssertActionCallsOnImageChanged(childManipulator, rotator.FlipVertically);
        }
        void AssertResizeWithLastSettingsOnParentImageChanged(Size initialSize, Size changedSize, ImageSizeManipulator.SizeLockType sizeLockBy, Size newSize, Size expectedSize)
        {
            var dummyManipulator = new ImageManipulatorTest.DummyManipulator(new CodedImage {
                Size = initialSize
            });
            var resizer = new ImageSizeManipulator(dummyManipulator);

            Assert.AreEqual(initialSize, resizer.ManipulatedImage.Size, "Precondition");

            resizer.Resize(changedSize, ImageResampler.FilterType.Box, sizeLockBy);
            Assert.AreEqual(changedSize, resizer.ManipulatedImage.Size, "Precondition 2");

            dummyManipulator.ManipulatedImage.Size = newSize;
            Assert.AreEqual(changedSize, resizer.ManipulatedImage.Size, "Not changed yet");

            dummyManipulator.CallOnImageChanged();
            Assert.AreEqual(expectedSize, resizer.ManipulatedImage.Size);
        }