public void RemoveSelectedImageCommand()
        {
            var clipboardMock = new Mock <IClipboardManager>();
            var viewModel     = new ImageListViewModel(Messenger, new CaptureImageService(), clipboardMock.Object, ImageProvider);

            viewModel.RemoveSelectedImageCommand.CanExecute(null).Should().BeFalse();

            ImageProvider.AddImage(TestUtil.DummyBitmapSource(10, 10));
            viewModel.RemoveSelectedImageCommand.CanExecute(null).Should().BeTrue();
            viewModel.RemoveSelectedImageCommand.Execute(null);
            ImageProvider.SelectedImage.Should().BeNull();
            ImageProvider.Images.Should().BeEmpty();
        }
        public void CopyToClipboardCommand()
        {
            ImageProvider.AddImage(TestUtil.DummyBitmapSource(10, 10));
            var img = ImageProvider.Images[0];

            img.ImageRatioSize.WidthPercentage = 200;
            var clipboardMock = new Mock <IClipboardManager>();
            var viewModel     = new ImagePreviewWindowViewModel(Messenger, new CaptureImageService(), clipboardMock.Object, ImageProvider);

            BitmapSource called = null;

            clipboardMock.Setup(c => c.SetImage(It.IsAny <BitmapSource>())).Callback <BitmapSource>(img => called = img);

            viewModel.CopyToClipboardCommand.Execute(img);
            clipboardMock.Verify(c => c.SetImage(It.IsAny <BitmapSource>()), Times.Once());
            called.Should().Be(img.TransformedImage);
        }
Esempio n. 3
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 Width()
        {
            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.Width = 5;
                viewModel.WidthPercentage.Should().Be(100.0 * 5 / 4);
                ph.Should().Equal(new Dictionary <string, int>
                {
                    { "Width", 1 },
                    { "WidthPercentage", 1 },
                });
            }
            using (var ph = new PropertyChangedHistory(viewModel))
            {
                ImageProvider.AddImage(TestUtil.DummyBitmapSource(6, 6));
                ph.Should().Equal(new Dictionary <string, int>
                {
                    { "Width", 1 },
                    { "Height", 1 },
                    { "SelectedImage", 1 },
                });
            }
        }