public void Should_Not_Have_Offset_On_Bounds_When_Content_Larger_Than_Max_Window_Size() { // Issue #3784. using (UnitTestApplication.Start(TestServices.StyledWindow)) { var window = new Window(); var popupImpl = MockWindowingPlatform.CreatePopupMock(window.PlatformImpl); var child = new Canvas { Width = 400, Height = 1344, }; var target = CreateTarget(window, popupImpl.Object); target.Content = child; target.Show(); Assert.Equal(new Size(400, 1024), target.Bounds.Size); // Issue #3784 causes this to be (0, 160) which makes no sense as Window has no // parent control to be offset against. Assert.Equal(new Point(0, 0), target.Bounds.Position); } }
public void Window_Should_Be_Centered_When_WindowStartupLocation_Is_CenterScreen() { var screen1 = new Mock <Screen>(1.0, new PixelRect(new PixelSize(1920, 1080)), new PixelRect(new PixelSize(1920, 1040)), true); var screen2 = new Mock <Screen>(1.0, new PixelRect(new PixelSize(1366, 768)), new PixelRect(new PixelSize(1366, 728)), false); var screens = new Mock <IScreenImpl>(); screens.Setup(x => x.AllScreens).Returns(new Screen[] { screen1.Object, screen2.Object }); var windowImpl = MockWindowingPlatform.CreateWindowMock(); windowImpl.Setup(x => x.ClientSize).Returns(new Size(800, 480)); windowImpl.Setup(x => x.Scaling).Returns(1); windowImpl.Setup(x => x.Screen).Returns(screens.Object); using (UnitTestApplication.Start(TestServices.StyledWindow)) { var window = new Window(windowImpl.Object); window.WindowStartupLocation = WindowStartupLocation.CenterScreen; window.Position = new PixelPoint(60, 40); window.Show(); var expectedPosition = new PixelPoint( (int)(screen1.Object.WorkingArea.Size.Width / 2 - window.ClientSize.Width / 2), (int)(screen1.Object.WorkingArea.Size.Height / 2 - window.ClientSize.Height / 2)); Assert.Equal(window.Position, expectedPosition); } }
public void Setting_Width_Should_Resize_WindowImpl() { // Issue #3796 using (UnitTestApplication.Start(TestServices.StyledWindow)) { var window = new Window(); var popupImpl = MockWindowingPlatform.CreatePopupMock(window.PlatformImpl); var positioner = new Mock <IPopupPositioner>(); popupImpl.Setup(x => x.PopupPositioner).Returns(positioner.Object); var target = CreateTarget(window, popupImpl.Object); target.Width = 400; target.Height = 800; target.Show(); Assert.Equal(400, target.Width); Assert.Equal(800, target.Height); target.Width = 410; target.LayoutManager.ExecuteLayoutPass(); positioner.Verify(x => x.Update(It.Is <PopupPositionerParameters>(x => x.Size.Width == 410))); Assert.Equal(410, target.Width); } }
public void Window_Should_Be_Sized_To_MinSize_If_InitialSize_Less_Than_MinSize() { var screen1 = new Mock <Screen>(1.75, new PixelRect(new PixelSize(1920, 1080)), new PixelRect(new PixelSize(1920, 966)), true); var screens = new Mock <IScreenImpl>(); screens.Setup(x => x.AllScreens).Returns(new Screen[] { screen1.Object }); screens.Setup(x => x.ScreenFromPoint(It.IsAny <PixelPoint>())).Returns(screen1.Object); var windowImpl = MockWindowingPlatform.CreateWindowMock(400, 300); windowImpl.Setup(x => x.DesktopScaling).Returns(1.75); windowImpl.Setup(x => x.RenderScaling).Returns(1.75); windowImpl.Setup(x => x.Screen).Returns(screens.Object); using (UnitTestApplication.Start(TestServices.StyledWindow)) { var window = new Window(windowImpl.Object); window.WindowStartupLocation = WindowStartupLocation.CenterScreen; window.MinWidth = 720; window.MinHeight = 480; window.Show(); Assert.Equal(new PixelPoint(330, 63), window.Position); Assert.Equal(new Size(720, 480), window.Bounds.Size); } }
private IDisposable CreateServicesWithFocus() { return(UnitTestApplication.Start(TestServices.StyledWindow.With(windowingPlatform: new MockWindowingPlatform(null, x => { return MockWindowingPlatform.CreatePopupMock(x).Object; }), focusManager: new FocusManager(), keyboardDevice: () => new KeyboardDevice()))); }
private IDisposable CreateServices() { return(UnitTestApplication.Start(TestServices.StyledWindow.With(windowingPlatform: new MockWindowingPlatform(null, x => { if (UsePopupHost) { return null; } return MockWindowingPlatform.CreatePopupMock(x).Object; })))); }
public void Setting_Title_Should_Set_Impl_Title() { var windowImpl = new Mock <IWindowImpl>(); var windowingPlatform = new MockWindowingPlatform(() => windowImpl.Object); using (UnitTestApplication.Start(new TestServices(windowingPlatform: windowingPlatform))) { var target = new Window(); target.Title = "Hello World"; windowImpl.Verify(x => x.SetTitle("Hello World")); } }
public void Child_Should_Be_Measured_With_MaxAutoSizeHint() { using (UnitTestApplication.Start(TestServices.StyledWindow)) { var child = new ChildControl(); var window = new Window(); var popupImpl = MockWindowingPlatform.CreatePopupMock(window.PlatformImpl); popupImpl.Setup(x => x.MaxAutoSizeHint).Returns(new Size(1200, 1000)); var target = CreateTarget(window, popupImpl.Object); target.Content = child; target.Show(); Assert.Equal(1, child.MeasureSizes.Count); Assert.Equal(new Size(1200, 1000), child.MeasureSizes[0]); } }
public void Window_Should_Be_Centered_Relative_To_Owner_When_WindowStartupLocation_Is_CenterOwner() { var parentWindowImpl = MockWindowingPlatform.CreateWindowMock(); parentWindowImpl.Setup(x => x.ClientSize).Returns(new Size(800, 480)); parentWindowImpl.Setup(x => x.MaxAutoSizeHint).Returns(new Size(1920, 1080)); parentWindowImpl.Setup(x => x.DesktopScaling).Returns(1); parentWindowImpl.Setup(x => x.RenderScaling).Returns(1); var windowImpl = MockWindowingPlatform.CreateWindowMock(); windowImpl.Setup(x => x.ClientSize).Returns(new Size(320, 200)); windowImpl.Setup(x => x.MaxAutoSizeHint).Returns(new Size(1920, 1080)); windowImpl.Setup(x => x.DesktopScaling).Returns(1); windowImpl.Setup(x => x.RenderScaling).Returns(1); var parentWindowServices = TestServices.StyledWindow.With( windowingPlatform: new MockWindowingPlatform(() => parentWindowImpl.Object)); var windowServices = TestServices.StyledWindow.With( windowingPlatform: new MockWindowingPlatform(() => windowImpl.Object)); using (UnitTestApplication.Start(parentWindowServices)) { var parentWindow = new Window(); parentWindow.Position = new PixelPoint(60, 40); parentWindow.Show(); using (UnitTestApplication.Start(windowServices)) { var window = new Window(); window.WindowStartupLocation = WindowStartupLocation.CenterOwner; window.Position = new PixelPoint(60, 40); window.ShowDialog(parentWindow); var expectedPosition = new PixelPoint( (int)(parentWindow.Position.X + parentWindow.ClientSize.Width / 2 - window.ClientSize.Width / 2), (int)(parentWindow.Position.Y + parentWindow.ClientSize.Height / 2 - window.ClientSize.Height / 2)); Assert.Equal(window.Position, expectedPosition); } } }
public void Child_Should_Be_Measured_With_ClientSize_If_SizeToContent_Is_Manual_And_No_Width_Height_Specified() { using (UnitTestApplication.Start(TestServices.StyledWindow)) { var windowImpl = MockWindowingPlatform.CreateWindowMock(); windowImpl.Setup(x => x.ClientSize).Returns(new Size(550, 450)); var child = new ChildControl(); var target = new Window(windowImpl.Object) { SizeToContent = SizeToContent.Manual, Content = child }; target.Show(); Assert.Equal(new Size(550, 450), child.MeasureSize); } }
private IDisposable Application() { var screen = new PixelRect(new PixelPoint(), new PixelSize(100, 100)); var screenImpl = new Mock<IScreenImpl>(); screenImpl.Setup(x => x.ScreenCount).Returns(1); screenImpl.Setup(X => X.AllScreens).Returns( new[] { new Screen(1, screen, screen, true) }); popupImpl = MockWindowingPlatform.CreatePopupMock(); popupImpl.SetupGet(x => x.Scaling).Returns(1); var windowImpl = MockWindowingPlatform.CreateWindowMock(() => popupImpl.Object); windowImpl.Setup(x => x.Screen).Returns(screenImpl.Object); var services = TestServices.StyledWindow.With( inputManager: new InputManager(), windowImpl: windowImpl.Object, windowingPlatform: new MockWindowingPlatform(() => windowImpl.Object, () => popupImpl.Object)); return UnitTestApplication.Start(services); }
public void Child_Should_Be_Measured_With_MaxAutoSizeHint_If_SizeToContent_Is_WidthAndHeight() { using (UnitTestApplication.Start(TestServices.StyledWindow)) { var windowImpl = MockWindowingPlatform.CreateWindowMock(); windowImpl.Setup(x => x.MaxAutoSizeHint).Returns(new Size(1200, 1000)); var child = new ChildControl(); var target = new Window(windowImpl.Object) { Width = 100, Height = 50, SizeToContent = SizeToContent.WidthAndHeight, Content = child }; target.Show(); Assert.Equal(1, child.MeasureSizes.Count); Assert.Equal(new Size(1200, 1000), child.MeasureSizes[0]); } }
public void Should_Not_Have_Offset_On_Bounds_When_Content_Larger_Than_Max_Window_Size() { // Issue #3784. using (UnitTestApplication.Start(TestServices.StyledWindow)) { var windowImpl = MockWindowingPlatform.CreateWindowMock(); var clientSize = new Size(200, 200); var maxClientSize = new Size(480, 480); windowImpl.Setup(x => x.Resize(It.IsAny <Size>(), It.IsAny <PlatformResizeReason>())) .Callback <Size, PlatformResizeReason>((size, reason) => { clientSize = size.Constrain(maxClientSize); windowImpl.Object.Resized?.Invoke(clientSize, reason); }); windowImpl.Setup(x => x.ClientSize).Returns(() => clientSize); var child = new Canvas { Width = 400, Height = 800, }; var target = new Window(windowImpl.Object) { SizeToContent = SizeToContent.WidthAndHeight, Content = child }; Show(target); Assert.Equal(new Size(400, 480), target.Bounds.Size); // Issue #3784 causes this to be (0, 160) which makes no sense as Window has no // parent control to be offset against. Assert.Equal(new Point(0, 0), target.Bounds.Position); } }
public void MinWidth_MinHeight_Should_Be_Respected() { // Issue #3796 using (UnitTestApplication.Start(TestServices.StyledWindow)) { var window = new Window(); var popupImpl = MockWindowingPlatform.CreatePopupMock(window.PlatformImpl); var target = CreateTarget(window, popupImpl.Object); target.MinWidth = 400; target.MinHeight = 800; target.Content = new Border { Width = 100, Height = 100, }; target.Show(); Assert.Equal(new Rect(0, 0, 400, 800), target.Bounds); Assert.Equal(new Size(400, 800), target.ClientSize); Assert.Equal(new Size(400, 800), target.PlatformImpl.ClientSize); } }