Exemplo n.º 1
0
        public void ApplyCustomLocation_ShouldCreateRect(int?horizontalLocation, int?verticalLocation)
        {
            // Prepare
            Rect?createdRect = default;

            var eventAggregatorMock = new Mock <IEventAggregator>();
            var activeWindowsSelectionChangedEventMock = new Mock <ActiveWindowsSelectionChangedEvent>();

            eventAggregatorMock.Setup(x => x.GetEvent <ActiveWindowsSelectionChangedEvent>()).Returns(activeWindowsSelectionChangedEventMock.Object);

            var windowServiceMock = new Mock <IWindowService>();

            windowServiceMock.Setup(x => x.RelocateWindow(It.IsAny <Domain.Windows.Window>(), It.IsAny <Rect>()))
            .Callback <Domain.Windows.Window, Rect>((window, rect) => createdRect = rect);

            var displayServiceMock = new Mock <IDisplayService>();

            var viewModel = new LocatorViewModel(eventAggregatorMock.Object, windowServiceMock.Object, displayServiceMock.Object)
            {
                NewHorizontalLocation = horizontalLocation.ToString() ?? string.Empty,
                NewVerticalLocation   = verticalLocation.ToString() ?? string.Empty
            };

            viewModel.SelectedWindows.Add(new Domain.Windows.Window());

            // Act
            viewModel.ApplyCustomLocation();

            // Assert
            windowServiceMock.Verify(x => x.RelocateWindow(It.IsAny <Domain.Windows.Window>(), It.IsAny <Rect>()), Times.AtLeastOnce());
            Assert.Equal(horizontalLocation ?? 0, createdRect?.Left);
            Assert.Equal(verticalLocation ?? 0, createdRect?.Top);
        }
Exemplo n.º 2
0
        public void ApplyCustomLocation_NoSelectedWindows_ShouldNotCallResizeWindow()
        {
            // Prepare
            var eventAggregatorMock = new Mock <IEventAggregator>();
            var activeWindowsSelectionChangedEventMock = new Mock <ActiveWindowsSelectionChangedEvent>();

            eventAggregatorMock.Setup(x => x.GetEvent <ActiveWindowsSelectionChangedEvent>()).Returns(activeWindowsSelectionChangedEventMock.Object);

            var windowServiceMock  = new Mock <IWindowService>();
            var displayServiceMock = new Mock <IDisplayService>();

            var viewModel = new LocatorViewModel(eventAggregatorMock.Object, windowServiceMock.Object, displayServiceMock.Object);

            // Act
            viewModel.ApplyCustomLocation();

            // Assert
            windowServiceMock.Verify(x => x.RelocateWindow(It.IsAny <Domain.Windows.Window>(), It.IsAny <Rect>()), Times.Never());
        }