public void IsSideCutMode()
        {
            ImageProvider.AddImage(TestUtil.DummyBitmapSource(4, 4));
            var viewModel = new ImageSettingsViewModel(Messenger, ImageProvider);

            using (var ph = new PropertyChangedHistory(viewModel))
            {
                ph.Should().Equal(new Dictionary <string, int> {
                });
                viewModel.IsSideCutMode.Should().BeFalse();
                viewModel.IsSideCutMode = true;
                viewModel.IsSideCutMode.Should().BeTrue();
                ph.Should().Equal(new Dictionary <string, int>
                {
                    { "IsSideCutMode", 1 },
                });
            }
            using (var ph = new PropertyChangedHistory(viewModel))
            {
                ImageProvider.AddImage(TestUtil.DummyBitmapSource(4, 4));
                viewModel.IsSideCutMode.Should().BeTrue();
                ph.Should().Equal(new Dictionary <string, int>
                {
                    { "SelectedImage", 1 },
                });
            }
        }
        public void WidthPercentage()
        {
            ImageProvider.AddImage(TestUtil.DummyBitmapSource(4, 4));
            var viewModel = new ImageSettingsViewModel(Messenger, ImageProvider);

            using (var ph = new PropertyChangedHistory(viewModel))
            {
                ph.Should().Equal(new Dictionary <string, int> {
                });
                viewModel.WidthPercentage = 180;
                viewModel.Width.Should().Be(7);
                viewModel.WidthPercentage.Should().Be(180.0);
                viewModel.HeightPercentage.Should().Be(180.0);
                ph.Should().Equal(new Dictionary <string, int>
                {
                    { "Width", 1 },
                    { "WidthPercentage", 1 },
                    { "Height", 1 },
                    { "HeightPercentage", 1 },
                });
            }
            using (var ph = new PropertyChangedHistory(viewModel))
            {
                ImageProvider.AddImage(TestUtil.DummyBitmapSource(6, 6));
                viewModel.WidthPercentage.Should().Be(180.0);
                viewModel.HeightPercentage.Should().Be(180.0);
                ph.Should().Equal(new Dictionary <string, int>
                {
                    { "Width", 1 },
                    { "Height", 1 },
                    { "SelectedImage", 1 },
                });
            }
        }
        public void ImageKind()
        {
            ImageProvider.AddImage(TestUtil.DummyBitmapSource(4, 4));
            var viewModel = new ImageSettingsViewModel(Messenger, ImageProvider);

            using (var ph = new PropertyChangedHistory(viewModel))
            {
                ph.Should().Equal(new Dictionary <string, int> {
                });
                viewModel.ImageKind.Should().Be(Images.ImageKind.JPG);
                viewModel.ImageKind = Images.ImageKind.PNG;
                viewModel.ImageKind.Should().Be(Images.ImageKind.PNG);
                ph.Should().Equal(new Dictionary <string, int>
                {
                    { "ImageKind", 1 },
                });
            }
            using (var ph = new PropertyChangedHistory(viewModel))
            {
                ImageProvider.AddImage(TestUtil.DummyBitmapSource(4, 4));
                viewModel.ImageKind.Should().Be(Images.ImageKind.PNG);
                ph.Should().Equal(new Dictionary <string, int>
                {
                    { "SelectedImage", 1 },
                });
            }
        }
        public void Visibility()
        {
            var clipboardMock = new Mock <IClipboardManager>();
            var viewModel     = new ImagePreviewWindowViewModel(Messenger, new CaptureImageService(), clipboardMock.Object, ImageProvider);

            using (var ph = new PropertyChangedHistory(viewModel))
            {
                viewModel.Visibility.Should().Be(System.Windows.Visibility.Collapsed);
                ph.Should().Equal(new Dictionary <string, int> {
                });
                ImageProvider.AddImage(TestUtil.DummyBitmapSource(4, 4));
                viewModel.Visibility.Should().Be(System.Windows.Visibility.Visible);
                ph.Should().Equal(new Dictionary <string, int>
                {
                    { "Visibility", 1 },
                    { "SelectedImage", 1 },
                });
                ImageProvider.Images.Clear();
                viewModel.Visibility.Should().Be(System.Windows.Visibility.Collapsed);
                ph.Should().Equal(new Dictionary <string, int>
                {
                    { "Visibility", 2 },
                    { "SelectedImage", 2 },
                });
            }
        }
示例#5
0
        public void ImageVisibility()
        {
            var viewModel = new WindowCapturerViewModel(Messenger, new CaptureImageService(), ImageProvider);

            using (var ph = new PropertyChangedHistory(viewModel))
            {
                ph.Should().Equal(new Dictionary <string, int> {
                });
                viewModel.ImageVisibility.Should().Be(Visibility.Collapsed);
                ImageProvider.AddImage(TestUtil.DummyBitmapSource(2, 2));
                viewModel.ImageVisibility.Should().Be(Visibility.Visible);
                ImageProvider.AddImage(TestUtil.DummyBitmapSource(2, 2));
                viewModel.ImageVisibility.Should().Be(Visibility.Visible);
                ph.Should().Equal(new Dictionary <string, int>
                {
                    { "ImageVisibility", 1 }
                });
                ImageProvider.Images.Clear();
                viewModel.ImageVisibility.Should().Be(Visibility.Collapsed);
                ph.Should().Equal(new Dictionary <string, int>
                {
                    { "ImageVisibility", 2 }
                });
            }
            using (var ph = new PropertyChangedHistory(viewModel))
            {
                ph.Should().Equal(new Dictionary <string, int> {
                });
                viewModel.AlwaysImageArea = true;
                viewModel.ImageVisibility.Should().Be(Visibility.Visible);
                ph.Should().Equal(new Dictionary <string, int>
                {
                    { "AlwaysImageArea", 1 },
                    { "ImageVisibility", 1 }
                });
                ImageProvider.AddImage(TestUtil.DummyBitmapSource(2, 2));
                viewModel.ImageVisibility.Should().Be(Visibility.Visible);
                ph.Should().Equal(new Dictionary <string, int>
                {
                    { "AlwaysImageArea", 1 },
                    { "ImageVisibility", 1 }
                });
            }
        }
        public void SelectedChanged()
        {
            var viewModel = new ImageSettingsViewModel(Messenger, ImageProvider);

            viewModel.HasImage.Should().BeFalse();
            viewModel.SelectedImage.Should().BeNull();
            viewModel.Width.Should().Be(0);
            viewModel.Height.Should().Be(0);
            viewModel.WidthPercentage.Should().Be(0);
            viewModel.HeightPercentage.Should().Be(0);
            viewModel.ImageKind.Should().Be(Images.ImageKind.JPG);
            viewModel.IsSideCutMode.Should().BeFalse();

            using (var ph = new PropertyChangedHistory(viewModel))
            {
                ImageProvider.AddImage(TestUtil.DummyBitmapSource(4, 4));
                viewModel.HasImage.Should().BeTrue();
                viewModel.SelectedImage.Should().NotBeNull();
                viewModel.Width.Should().Be(4);
                viewModel.Height.Should().Be(4);
                viewModel.WidthPercentage.Should().Be(100);
                viewModel.HeightPercentage.Should().Be(100);
                viewModel.ImageKind.Should().Be(Images.ImageKind.JPG);
                viewModel.IsSideCutMode.Should().BeFalse();
                ph.Should().Equal(new Dictionary <string, int>
                {
                    { "HasImage", 1 },
                    { "SelectedImage", 1 },
                    { "Width", 1 },
                    { "Height", 1 },
                    { "WidthPercentage", 1 },
                    { "HeightPercentage", 1 },
                    { "ImageKind", 1 },
                    { "IsSideCutMode", 1 },
                });
            }

            ImageProvider.AddImage(TestUtil.DummyBitmapSource(5, 5));
            viewModel.HasImage.Should().BeTrue();
            viewModel.SelectedImage.Should().NotBeNull();
            viewModel.Width         = 9;
            viewModel.Height        = 3;
            viewModel.ImageKind     = Images.ImageKind.PNG;
            viewModel.IsSideCutMode = true;
            viewModel.Width.Should().Be(9);
            viewModel.Height.Should().Be(3);
            viewModel.WidthPercentage.Should().Be(180);
            viewModel.HeightPercentage.Should().Be(60);
            viewModel.ImageKind.Should().Be(Images.ImageKind.PNG);
            viewModel.IsSideCutMode.Should().BeTrue();

            using (var ph = new PropertyChangedHistory(viewModel))
            {
                ImageProvider.SelectedImageIndex = 0;
                ph.Should().Equal(new Dictionary <string, int>
                {
                    { "SelectedImage", 1 },
                    { "Width", 1 },
                    { "Height", 1 },
                    { "WidthPercentage", 1 },
                    { "HeightPercentage", 1 },
                    { "ImageKind", 1 },
                    { "IsSideCutMode", 1 },
                });
                viewModel.HasImage.Should().BeTrue();
                viewModel.SelectedImage.Should().NotBeNull();
                viewModel.Width.Should().Be(4);
                viewModel.Height.Should().Be(4);
                viewModel.WidthPercentage.Should().Be(100);
                viewModel.HeightPercentage.Should().Be(100);
                viewModel.ImageKind.Should().Be(Images.ImageKind.JPG);
                viewModel.IsSideCutMode.Should().BeFalse();


                ImageProvider.SelectedImageIndex = 1;
                ph.Should().Equal(new Dictionary <string, int>
                {
                    { "SelectedImage", 2 },
                    { "Width", 2 },
                    { "Height", 2 },
                    { "WidthPercentage", 2 },
                    { "HeightPercentage", 2 },
                    { "ImageKind", 2 },
                    { "IsSideCutMode", 2 },
                });
                viewModel.HasImage.Should().BeTrue();
                viewModel.SelectedImage.Should().NotBeNull();
                viewModel.Width.Should().Be(9);
                viewModel.Height.Should().Be(3);
                viewModel.WidthPercentage.Should().Be(180);
                viewModel.HeightPercentage.Should().Be(60);
                viewModel.ImageKind.Should().Be(Images.ImageKind.PNG);
                viewModel.IsSideCutMode.Should().BeTrue();
            }

            using (var ph = new PropertyChangedHistory(viewModel))
            {
                ImageProvider.Images.Clear();
                ph.Should().Equal(new Dictionary <string, int>
                {
                    { "HasImage", 1 },
                    { "SelectedImage", 1 },
                });
                viewModel.HasImage.Should().BeFalse();
                viewModel.SelectedImage.Should().BeNull();
                viewModel.Width.Should().Be(0);
                viewModel.Height.Should().Be(0);
                viewModel.WidthPercentage.Should().Be(0);
                viewModel.HeightPercentage.Should().Be(0);
                viewModel.ImageKind.Should().Be(Images.ImageKind.JPG);
                viewModel.IsSideCutMode.Should().BeFalse();
            }
        }
示例#7
0
        public void SizeChangeTest()
        {
            var ratioSize = new ImageRatioSize(10, 10, 50, 100);

            ratioSize.Width.Should().Be(5);
            ratioSize.Height.Should().Be(10);

            using (var popertyChangedHistory = new PropertyChangedHistory(ratioSize))
            {
                ratioSize.WidthPercentage = 80;
                ratioSize.WidthPercentage.Should().Be(80);
                ratioSize.HeightPercentage.Should().Be(100);
                ratioSize.Width.Should().Be(8);
                ratioSize.Height.Should().Be(10);
                popertyChangedHistory.Should().BeEquivalentTo(new Dictionary <string, int>
                {
                    { nameof(ratioSize.Width), 1 },
                    { nameof(ratioSize.WidthPercentage), 1 },
                });
            }

            using (var popertyChangedHistory = new PropertyChangedHistory(ratioSize))
            {
                ratioSize.HeightPercentage = 10;
                ratioSize.WidthPercentage.Should().Be(80);
                ratioSize.HeightPercentage.Should().Be(10);
                ratioSize.Width.Should().Be(8);
                ratioSize.Height.Should().Be(1);
                popertyChangedHistory.Should().BeEquivalentTo(new Dictionary <string, int>
                {
                    { nameof(ratioSize.Height), 1 },
                    { nameof(ratioSize.HeightPercentage), 1 },
                });
            }

            using (var popertyChangedHistory = new PropertyChangedHistory(ratioSize))
            {
                ratioSize.Width = 100;
                ratioSize.WidthPercentage.Should().Be(1000);
                ratioSize.HeightPercentage.Should().Be(10);
                ratioSize.Width.Should().Be(100);
                ratioSize.Height.Should().Be(1);
                popertyChangedHistory.Should().BeEquivalentTo(new Dictionary <string, int>
                {
                    { nameof(ratioSize.Width), 1 },
                    { nameof(ratioSize.WidthPercentage), 1 },
                });
            }

            using (var popertyChangedHistory = new PropertyChangedHistory(ratioSize))
            {
                ratioSize.Height = 15;
                ratioSize.WidthPercentage.Should().Be(1000);
                ratioSize.HeightPercentage.Should().Be(150);
                ratioSize.Width.Should().Be(100);
                ratioSize.Height.Should().Be(15);
                popertyChangedHistory.Should().BeEquivalentTo(new Dictionary <string, int>
                {
                    { nameof(ratioSize.Height), 1 },
                    { nameof(ratioSize.HeightPercentage), 1 },
                });
            }
        }