Ejemplo n.º 1
0
        public void Bounds_Should_Be_Set_After_Layout_Pass()
        {
            using (Locator.CurrentMutable.WithResolver())
            {
                this.RegisterServices();
                Locator.CurrentMutable.RegisterConstant(new LayoutManager(), typeof(ILayoutManager));

                var impl = new Mock<ITopLevelImpl>();
                impl.SetupProperty(x => x.ClientSize);
                impl.SetupProperty(x => x.Resized);

                var target = new TestTopLevel(impl.Object)
                {
                    Template = new ControlTemplate<TestTopLevel>(x =>
                        new ContentPresenter
                        {
                            [~ContentPresenter.ContentProperty] = x[~TestTopLevel.ContentProperty],
                        }),
                    Content = new TextBlock
                    {
                        Width = 321,
                        Height = 432,
                    }
                };

                target.LayoutManager.ExecuteLayoutPass();

                Assert.Equal(new Rect(0, 0, 321, 432), target.Bounds);
            }
        }
Ejemplo n.º 2
0
        public void Height_Should_Not_Be_Set_On_Construction()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var impl = new Mock<ITopLevelImpl>();
                impl.Setup(x => x.ClientSize).Returns(new Size(123, 456));

                var target = new TestTopLevel(impl.Object);

                Assert.Equal(double.NaN, target.Height);
            }
        }
Ejemplo n.º 3
0
        public void Activate_Should_Call_Impl_Activate()
        {
            using (Locator.CurrentMutable.WithResolver())
            {
                this.RegisterServices();

                var impl = new Mock<ITopLevelImpl>();
                var target = new TestTopLevel(impl.Object);

                target.Activate();

                impl.Verify(x => x.Activate());
            }
        }
Ejemplo n.º 4
0
        public void Width_Should_Not_Be_Set_On_Construction()
        {
            using (Locator.CurrentMutable.WithResolver())
            {
                RegisterServices();

                var impl = new Mock<ITopLevelImpl>();
                impl.Setup(x => x.ClientSize).Returns(new Size(123, 456));

                var target = new TestTopLevel(impl.Object);

                Assert.Equal(double.NaN, target.Width);
            }
        }
Ejemplo n.º 5
0
        public void Width_Should_Not_Be_Set_On_Construction()
        {
            using (Locator.CurrentMutable.WithResolver())
            {
                RegisterServices();

                var impl = new Mock <ITopLevelImpl>();
                impl.Setup(x => x.ClientSize).Returns(new Size(123, 456));

                var target = new TestTopLevel(impl.Object);

                Assert.Equal(double.NaN, target.Width);
            }
        }
Ejemplo n.º 6
0
        public void Layout_Pass_Should_Not_Be_Automatically_Scheduled()
        {
            var services = TestServices.StyledWindow.With(layoutManager: Mock.Of<ILayoutManager>());

            using (UnitTestApplication.Start(services))
            {
                var impl = new Mock<ITopLevelImpl>();
                var target = new TestTopLevel(impl.Object);

                // The layout pass should be scheduled by the derived class.
                var layoutManagerMock = Mock.Get(LayoutManager.Instance);
                layoutManagerMock.Verify(x => x.ExecuteLayoutPass(), Times.Never);
            }
        }
Ejemplo n.º 7
0
        public void Activate_Should_Call_Impl_Activate()
        {
            using (Locator.CurrentMutable.WithResolver())
            {
                RegisterServices();

                var impl   = new Mock <ITopLevelImpl>();
                var target = new TestTopLevel(impl.Object);

                target.Activate();

                impl.Verify(x => x.Activate());
            }
        }
Ejemplo n.º 8
0
        public void Height_Should_Not_Be_Set_On_Construction()
        {
            using (PerspexLocator.EnterScope())
            {
                RegisterServices();

                var impl = new Mock<ITopLevelImpl>();
                impl.Setup(x => x.ClientSize).Returns(new Size(123, 456));

                var target = new TestTopLevel(impl.Object);

                Assert.Equal(double.NaN, target.Height);
            }
        }
Ejemplo n.º 9
0
        public void Layout_Pass_Should_Not_Be_Automatically_Scheduled()
        {
            using (PerspexLocator.EnterScope())
            {
                RegisterServices();

                var impl = new Mock<ITopLevelImpl>();
                var target = new TestTopLevel(impl.Object);

                // The layout pass should be scheduled by the derived class.
                var layoutManagerMock = Mock.Get(target.LayoutManager);
                layoutManagerMock.Verify(x => x.ExecuteLayoutPass(), Times.Never);
            }
        }
Ejemplo n.º 10
0
        public void Width_And_Height_Should_Not_Be_Set_After_Layout_Pass()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var impl = new Mock <ITopLevelImpl>();
                impl.Setup(x => x.ClientSize).Returns(new Size(123, 456));

                var target = new TestTopLevel(impl.Object);
                target.LayoutManager.ExecuteLayoutPass();

                Assert.Equal(double.NaN, target.Width);
                Assert.Equal(double.NaN, target.Height);
            }
        }
Ejemplo n.º 11
0
        public void Activate_Should_Call_Impl_Activate()
        {
            using (PerspexLocator.EnterScope())
            {
                RegisterServices();

                var impl = new Mock<ITopLevelImpl>();
                var target = new TestTopLevel(impl.Object);

                target.Activate();

                impl.Verify(x => x.Activate());
            }
        }
Ejemplo n.º 12
0
        public void Layout_Pass_Should_Not_Be_Automatically_Scheduled()
        {
            var services = TestServices.StyledWindow.With(layoutManager: Mock.Of <ILayoutManager>());

            using (UnitTestApplication.Start(services))
            {
                var impl   = new Mock <ITopLevelImpl>();
                var target = new TestTopLevel(impl.Object);

                // The layout pass should be scheduled by the derived class.
                var layoutManagerMock = Mock.Get(LayoutManager.Instance);
                layoutManagerMock.Verify(x => x.ExecuteLayoutPass(), Times.Never);
            }
        }
Ejemplo n.º 13
0
        public void Layout_Pass_Should_Not_Be_Automatically_Scheduled()
        {
            using (PerspexLocator.EnterScope())
            {
                RegisterServices();

                var impl   = new Mock <ITopLevelImpl>();
                var target = new TestTopLevel(impl.Object);

                // The layout pass should be scheduled by the derived class.
                var layoutManagerMock = Mock.Get(target.LayoutManager);
                layoutManagerMock.Verify(x => x.ExecuteLayoutPass(), Times.Never);
            }
        }
Ejemplo n.º 14
0
        public void Height_Should_Not_Be_Set_On_Construction()
        {
            using (PerspexLocator.EnterScope())
            {
                RegisterServices();

                var impl = new Mock <ITopLevelImpl>();
                impl.Setup(x => x.ClientSize).Returns(new Size(123, 456));

                var target = new TestTopLevel(impl.Object);

                Assert.Equal(double.NaN, target.Height);
            }
        }
Ejemplo n.º 15
0
        public void Activate_Should_Call_Impl_Activate()
        {
            using (PerspexLocator.EnterScope())
            {
                RegisterServices();

                var impl   = new Mock <ITopLevelImpl>();
                var target = new TestTopLevel(impl.Object);

                target.Activate();

                impl.Verify(x => x.Activate());
            }
        }
Ejemplo n.º 16
0
        public void Close_Should_Dispose_LayoutManager()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var impl = new Mock <ITopLevelImpl>();
                impl.SetupAllProperties();

                var layoutManager = new Mock <ILayoutManager>();
                var target        = new TestTopLevel(impl.Object, layoutManager.Object);

                impl.Object.Closed();

                layoutManager.Verify(x => x.Dispose());
            }
        }
Ejemplo n.º 17
0
        public void Adding_Top_Level_As_Child_Should_Throw_Exception()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var impl = new Mock <ITopLevelImpl>();
                impl.SetupAllProperties();
                var target = new TestTopLevel(impl.Object);
                var child  = new TestTopLevel(impl.Object);

                target.Template = CreateTemplate();
                target.Content  = child;

                Assert.Throws <InvalidOperationException>(() => target.ApplyTemplate());
            }
        }
Ejemplo n.º 18
0
        public void Adding_Resource_To_Application_Should_Raise_ResourcesChanged()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var impl = new Mock <ITopLevelImpl>();
                impl.SetupAllProperties();
                var target = new TestTopLevel(impl.Object);
                var raised = false;

                target.ResourcesChanged += (_, __) => raised = true;
                Application.Current.Resources.Add("foo", "bar");

                Assert.True(raised);
            }
        }
Ejemplo n.º 19
0
        public void Width_And_Height_Should_Not_Be_Set_After_Layout_Pass()
        {
            using (PerspexLocator.EnterScope())
            {
                RegisterServices();

                var impl = new Mock <ITopLevelImpl>();
                impl.Setup(x => x.ClientSize).Returns(new Size(123, 456));

                var target = new TestTopLevel(impl.Object);
                target.LayoutManager.ExecuteLayoutPass();

                Assert.Equal(double.NaN, target.Width);
                Assert.Equal(double.NaN, target.Height);
            }
        }
Ejemplo n.º 20
0
        public void Close_Should_Notify_MouseDevice()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var impl        = new Mock <ITopLevelImpl>();
                var mouseDevice = new Mock <IMouseDevice>();
                impl.SetupAllProperties();
                impl.Setup(x => x.MouseDevice).Returns(mouseDevice.Object);

                var target = new TestTopLevel(impl.Object);

                impl.Object.Closed();

                mouseDevice.Verify(x => x.TopLevelClosed(target));
            }
        }
Ejemplo n.º 21
0
        public void Width_And_Height_Should_Be_Set_After_Window_Resize_Notification()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var impl = new Mock <ITopLevelImpl>();
                impl.SetupAllProperties();
                impl.Setup(x => x.ClientSize).Returns(new Size(123, 456));

                // The user has resized the window, so we can no longer auto-size.
                var target = new TestTopLevel(impl.Object);
                impl.Object.Resized(new Size(100, 200));

                Assert.Equal(100, target.Width);
                Assert.Equal(200, target.Height);
            }
        }
Ejemplo n.º 22
0
        public void Impl_Close_Should_Call_Raise_Closed_Event()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var impl = new Mock <ITopLevelImpl>();
                impl.SetupAllProperties();

                bool raised = false;
                var  target = new TestTopLevel(impl.Object);
                target.Closed += (s, e) => raised = true;

                impl.Object.Closed();

                Assert.True(raised);
            }
        }
Ejemplo n.º 23
0
        public void Adding_Top_Level_As_Child_Should_Throw_Exception()
        {
            using (PerspexLocator.EnterScope())
            {
                RegisterServices();

                var impl = new Mock <ITopLevelImpl>();
                impl.SetupAllProperties();
                var target = new TestTopLevel(impl.Object);
                var child  = new TestTopLevel(impl.Object);

                target.Template = CreateTemplate();
                target.Content  = child;

                Assert.Throws <InvalidOperationException>(() => target.ApplyTemplate());
            }
        }
Ejemplo n.º 24
0
        public void Adding_Top_Level_As_Child_Should_Throw_Exception()
        {
            using (PerspexLocator.EnterScope())
            {
                RegisterServices();

                var impl = new Mock<ITopLevelImpl>();
                impl.SetupAllProperties();
                var target = new TestTopLevel(impl.Object);
                var child = new TestTopLevel(impl.Object);

                target.Template = CreateTemplate();
                target.Content = child;

                Assert.Throws<InvalidOperationException>(() => target.ApplyTemplate());
            }
        }
Ejemplo n.º 25
0
        public void Impl_Close_Should_Call_Raise_Closed_Event()
        {
            using (Locator.CurrentMutable.WithResolver())
            {
                RegisterServices();

                var impl = new Mock <ITopLevelImpl>();
                impl.SetupAllProperties();

                bool raised = false;
                var  target = new TestTopLevel(impl.Object);
                target.Closed += (s, e) => raised = true;

                impl.Object.Closed();

                Assert.True(raised);
            }
        }
Ejemplo n.º 26
0
        public void Impl_Deactivate_Should_Call_Raise_Activated_Event()
        {
            using (PerspexLocator.EnterScope())
            {
                RegisterServices();

                var impl = new Mock <ITopLevelImpl>();
                impl.SetupAllProperties();

                bool raised = false;
                var  target = new TestTopLevel(impl.Object);
                target.Deactivated += (s, e) => raised = true;

                impl.Object.Deactivated();

                Assert.True(raised);
            }
        }
Ejemplo n.º 27
0
        public void Width_And_Height_Should_Be_Set_After_Window_Resize_Notification()
        {
            using (Locator.CurrentMutable.WithResolver())
            {
                RegisterServices();

                var impl = new Mock <ITopLevelImpl>();
                impl.SetupAllProperties();
                impl.Setup(x => x.ClientSize).Returns(new Size(123, 456));

                // The user has resized the window, so we can no longer auto-size.
                var target = new TestTopLevel(impl.Object);
                impl.Object.Resized(new Size(100, 200));

                Assert.Equal(100, target.Width);
                Assert.Equal(200, target.Height);
            }
        }
Ejemplo n.º 28
0
        public void Render_Should_Be_Scheduled_After_Layout_Pass()
        {
            using (PerspexLocator.EnterScope())
            {
                RegisterServices();
                var completed         = new Subject <Unit>();
                var layoutManagerMock = Mock.Get(PerspexLocator.Current.GetService <ILayoutManager>());
                layoutManagerMock.Setup(x => x.LayoutCompleted).Returns(completed);

                var impl = new Mock <ITopLevelImpl>();
                impl.Setup(x => x.ClientSize).Returns(new Size(123, 456));

                var target = new TestTopLevel(impl.Object);
                completed.OnNext(Unit.Default);

                var renderManagerMock = Mock.Get(PerspexLocator.Current.GetService <IRenderQueueManager>());
                renderManagerMock.Verify(x => x.InvalidateRender(target));
            }
        }
Ejemplo n.º 29
0
        public void Impl_Input_Should_Pass_Input_To_InputManager()
        {
            using (PerspexLocator.EnterScope())
            {
                RegisterServices();

                var impl = new Mock <ITopLevelImpl>();
                impl.SetupAllProperties();
                var target = new TestTopLevel(impl.Object);

                var input = new RawKeyEventArgs(
                    new Mock <IKeyboardDevice>().Object,
                    0,
                    RawKeyEventType.KeyDown,
                    Key.A, InputModifiers.None);
                impl.Object.Input(input);

                var inputManagerMock = Mock.Get(InputManager.Instance);
                inputManagerMock.Verify(x => x.Process(input));
            }
        }
Ejemplo n.º 30
0
        public void Impl_ClientSize_Should_Be_Set_After_Layout_Pass()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var impl = Mock.Of <ITopLevelImpl>(x => x.Scaling == 1);

                var target = new TestTopLevel(impl)
                {
                    Template = CreateTemplate(),
                    Content  = new TextBlock
                    {
                        Width  = 321,
                        Height = 432,
                    }
                };

                LayoutManager.Instance.ExecuteInitialLayoutPass(target);

                Mock.Get(impl).VerifySet(x => x.ClientSize = new Size(321, 432));
            }
        }
Ejemplo n.º 31
0
        public void Impl_Input_Should_Pass_Input_To_InputManager()
        {
            var inputManagerMock = new Mock <IInputManager>();
            var services         = TestServices.StyledWindow.With(inputManager: inputManagerMock.Object);

            using (UnitTestApplication.Start(services))
            {
                var impl = new Mock <ITopLevelImpl>();
                impl.SetupAllProperties();

                var target = new TestTopLevel(impl.Object);

                var input = new RawKeyEventArgs(
                    new Mock <IKeyboardDevice>().Object,
                    0,
                    RawKeyEventType.KeyDown,
                    Key.A, InputModifiers.None);
                impl.Object.Input(input);

                inputManagerMock.Verify(x => x.ProcessInput(input));
            }
        }
Ejemplo n.º 32
0
        public void Reacts_To_Changes_In_Global_Styles()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var impl = new Mock <ITopLevelImpl>();
                impl.SetupGet(x => x.Scaling).Returns(1);

                var child = new Border {
                    Classes = { "foo" }
                };
                var target = new TestTopLevel(impl.Object)
                {
                    Template = CreateTemplate(),
                    Content  = child,
                };

                target.LayoutManager.ExecuteInitialLayoutPass(target);

                Assert.Equal(new Thickness(0), child.BorderThickness);

                var style = new Style(x => x.OfType <Border>().Class("foo"))
                {
                    Setters =
                    {
                        new Setter(Border.BorderThicknessProperty, new Thickness(2))
                    }
                };

                Application.Current.Styles.Add(style);
                target.LayoutManager.ExecuteInitialLayoutPass(target);

                Assert.Equal(new Thickness(2), child.BorderThickness);

                Application.Current.Styles.Remove(style);

                Assert.Equal(new Thickness(0), child.BorderThickness);
            }
        }
Ejemplo n.º 33
0
        public void Bounds_Should_Be_Set_After_Layout_Pass()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var impl = new Mock <ITopLevelImpl>();
                impl.SetupProperty(x => x.Resized);
                impl.SetupGet(x => x.Scaling).Returns(1);

                var target = new TestTopLevel(impl.Object)
                {
                    Template = CreateTemplate(),
                    Content  = new TextBlock
                    {
                        Width  = 321,
                        Height = 432,
                    }
                };

                LayoutManager.Instance.ExecuteInitialLayoutPass(target);

                Assert.Equal(new Rect(0, 0, 321, 432), target.Bounds);
            }
        }
Ejemplo n.º 34
0
        public void Impl_Close_Should_Raise_DetachedFromLogicalTree_Event()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var impl = new Mock <ITopLevelImpl>();
                impl.SetupAllProperties();

                var target = new TestTopLevel(impl.Object);
                var raised = 0;

                target.DetachedFromLogicalTree += (s, e) =>
                {
                    Assert.Same(target, e.Root);
                    Assert.Same(target, e.Source);
                    Assert.Null(e.Parent);
                    ++raised;
                };

                impl.Object.Closed();

                Assert.Equal(1, raised);
            }
        }
Ejemplo n.º 35
0
        public void Impl_ClientSize_Should_Be_Set_After_Layout_Pass()
        {
            using (PerspexLocator.EnterScope())
            {
                RegisterServices();
                PerspexLocator.CurrentMutable.Bind <ILayoutManager>().ToConstant(new LayoutManager());

                var impl = new Mock <ITopLevelImpl>();

                var target = new TestTopLevel(impl.Object)
                {
                    Template = CreateTemplate(),
                    Content  = new TextBlock
                    {
                        Width  = 321,
                        Height = 432,
                    }
                };

                target.LayoutManager.ExecuteLayoutPass();

                impl.VerifySet(x => x.ClientSize = new Size(321, 432));
            }
        }
Ejemplo n.º 36
0
        public void Render_Should_Be_Scheduled_After_Layout_Pass()
        {
            using (Locator.CurrentMutable.WithResolver())
            {
                this.RegisterServices();
                var completed = new Subject<Unit>();
                var layoutManagerMock = Mock.Get(Locator.Current.GetService<ILayoutManager>());
                layoutManagerMock.Setup(x => x.LayoutCompleted).Returns(completed);

                var impl = new Mock<ITopLevelImpl>();
                impl.Setup(x => x.ClientSize).Returns(new Size(123, 456));

                var target = new TestTopLevel(impl.Object);
                completed.OnNext(Unit.Default);

                var renderManagerMock = Mock.Get(Locator.Current.GetService<IRenderManager>());
                renderManagerMock.Verify(x => x.InvalidateRender(target));
            }
        }
Ejemplo n.º 37
0
        public void Impl_Deactivate_Should_Call_Raise_Activated_Event()
        {
            using (Locator.CurrentMutable.WithResolver())
            {
                this.RegisterServices();

                var impl = new Mock<ITopLevelImpl>();
                impl.SetupAllProperties();

                bool raised = false;
                var target = new TestTopLevel(impl.Object);
                target.Deactivated += (s, e) => raised = true;

                impl.Object.Deactivated();

                Assert.True(raised);
            }
        }
Ejemplo n.º 38
0
        public void Impl_Input_Should_Pass_Input_To_InputManager()
        {
            using (Locator.CurrentMutable.WithResolver())
            {
                this.RegisterServices();

                var impl = new Mock<ITopLevelImpl>();
                impl.SetupAllProperties();
                var target = new TestTopLevel(impl.Object);

                var input = new RawKeyEventArgs(
                    new Mock<IKeyboardDevice>().Object,
                    0,
                    RawKeyEventType.KeyDown,
                    Key.A,
                    "A");
                impl.Object.Input(input);

                var inputManagerMock = Mock.Get(InputManager.Instance);
                inputManagerMock.Verify(x => x.Process(input));
            }
        }
Ejemplo n.º 39
0
        public void Bounds_Should_Be_Set_After_Layout_Pass()
        {
            using (PerspexLocator.EnterScope())
            {
                RegisterServices();
                PerspexLocator.CurrentMutable.Bind<ILayoutManager>().ToConstant(new LayoutManager());

                var impl = new Mock<ITopLevelImpl>();
                impl.SetupProperty(x => x.ClientSize);
                impl.SetupProperty(x => x.Resized);

                var target = new TestTopLevel(impl.Object)
                {
                    Template = CreateTemplate(),
                    Content = new TextBlock
                    {
                        Width = 321,
                        Height = 432,
                    }
                };

                target.LayoutManager.ExecuteLayoutPass();

                Assert.Equal(new Rect(0, 0, 321, 432), target.Bounds);
            }
        }
Ejemplo n.º 40
0
        public void Bounds_Should_Be_Set_After_Layout_Pass()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var impl = new Mock<ITopLevelImpl>();
                impl.SetupProperty(x => x.ClientSize);
                impl.SetupProperty(x => x.Resized);
                impl.SetupGet(x => x.Scaling).Returns(1);

                var target = new TestTopLevel(impl.Object)
                {
                    Template = CreateTemplate(),
                    Content = new TextBlock
                    {
                        Width = 321,
                        Height = 432,
                    }
                };

                LayoutManager.Instance.ExecuteInitialLayoutPass(target);

                Assert.Equal(new Rect(0, 0, 321, 432), target.Bounds);
            }
        }
Ejemplo n.º 41
0
        public void Impl_ClientSize_Should_Be_Set_After_Layout_Pass()
        {
            using (PerspexLocator.EnterScope())
            {
                RegisterServices();
                PerspexLocator.CurrentMutable.Bind<ILayoutManager>().ToConstant(new LayoutManager());

                var impl = new Mock<ITopLevelImpl>();

                var target = new TestTopLevel(impl.Object)
                {
                    Template = CreateTemplate(),
                    Content = new TextBlock
                    {
                        Width = 321,
                        Height = 432,
                    }
                };

                target.LayoutManager.ExecuteLayoutPass();

                impl.VerifySet(x => x.ClientSize = new Size(321, 432));
            }
        }
Ejemplo n.º 42
0
        public void Impl_ClientSize_Should_Be_Set_After_Layout_Pass()
        {
            using (Locator.CurrentMutable.WithResolver())
            {
                this.RegisterServices();
                Locator.CurrentMutable.RegisterConstant(new LayoutManager(), typeof(ILayoutManager));

                var impl = new Mock<ITopLevelImpl>();

                var target = new TestTopLevel(impl.Object)
                {
                    Template = ControlTemplate.Create<TestTopLevel>(x =>
                        new ContentPresenter
                        {
                            [~ContentPresenter.ContentProperty] = x[~TestTopLevel.ContentProperty],
                        }),
                    Content = new TextBlock
                    {
                        Width = 321,
                        Height = 432,
                    }
                };

                target.LayoutManager.ExecuteLayoutPass();

                impl.VerifySet(x => x.ClientSize = new Size(321, 432));
            }
        }
Ejemplo n.º 43
0
        public void Impl_Input_Should_Pass_Input_To_InputManager()
        {
            using (PerspexLocator.EnterScope())
            {
                RegisterServices();

                var impl = new Mock<ITopLevelImpl>();
                impl.SetupAllProperties();
                var target = new TestTopLevel(impl.Object);

                var input = new RawKeyEventArgs(
                    new Mock<IKeyboardDevice>().Object,
                    0,
                    RawKeyEventType.KeyDown,
                    Key.A, InputModifiers.None);
                impl.Object.Input(input);

                var inputManagerMock = Mock.Get(InputManager.Instance);
                inputManagerMock.Verify(x => x.Process(input));
            }
        }
Ejemplo n.º 44
0
        public void Adding_Top_Level_As_Child_Should_Throw_Exception()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var impl = new Mock<ITopLevelImpl>();
                impl.SetupAllProperties();
                var target = new TestTopLevel(impl.Object);
                var child = new TestTopLevel(impl.Object);

                target.Template = CreateTemplate();
                target.Content = child;

                Assert.Throws<InvalidOperationException>(() => target.ApplyTemplate());
            }
        }
Ejemplo n.º 45
0
        public void Activate_Should_Call_Impl_Activate()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var impl = new Mock<ITopLevelImpl>();
                var target = new TestTopLevel(impl.Object);

                target.Activate();

                impl.Verify(x => x.Activate());
            }
        }
Ejemplo n.º 46
0
        public void Width_And_Height_Should_Not_Be_Set_After_Layout_Pass()
        {
            using (PerspexLocator.EnterScope())
            {
                RegisterServices();

                var impl = new Mock<ITopLevelImpl>();
                impl.Setup(x => x.ClientSize).Returns(new Size(123, 456));

                var target = new TestTopLevel(impl.Object);
                LayoutManager.Instance.ExecuteLayoutPass();

                Assert.Equal(double.NaN, target.Width);
                Assert.Equal(double.NaN, target.Height);
            }
        }
Ejemplo n.º 47
0
        public void Width_And_Height_Should_Be_Set_After_Window_Resize_Notification()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var impl = new Mock<ITopLevelImpl>();
                impl.SetupAllProperties();
                impl.Setup(x => x.ClientSize).Returns(new Size(123, 456));

                // The user has resized the window, so we can no longer auto-size.
                var target = new TestTopLevel(impl.Object);
                impl.Object.Resized(new Size(100, 200));

                Assert.Equal(100, target.Width);
                Assert.Equal(200, target.Height);
            }
        }
Ejemplo n.º 48
0
        public void Width_And_Height_Should_Not_Be_Set_After_Layout_Pass()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var impl = new Mock<ITopLevelImpl>();
                impl.Setup(x => x.ClientSize).Returns(new Size(123, 456));

                var target = new TestTopLevel(impl.Object);
                LayoutManager.Instance.ExecuteLayoutPass();

                Assert.Equal(double.NaN, target.Width);
                Assert.Equal(double.NaN, target.Height);
            }
        }
Ejemplo n.º 49
0
        public void Impl_ClientSize_Should_Be_Set_After_Layout_Pass()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var impl = Mock.Of<ITopLevelImpl>(x => x.Scaling == 1);

                var target = new TestTopLevel(impl)
                {
                    Template = CreateTemplate(),
                    Content = new TextBlock
                    {
                        Width = 321,
                        Height = 432,
                    }
                };

                LayoutManager.Instance.ExecuteInitialLayoutPass(target);

                Mock.Get(impl).VerifySet(x => x.ClientSize = new Size(321, 432));
            }
        }
Ejemplo n.º 50
0
        public void Width_And_Height_Should_Be_Set_After_Window_Resize_Notification()
        {
            using (Locator.CurrentMutable.WithResolver())
            {
                this.RegisterServices();

                var impl = new Mock<ITopLevelImpl>();
                impl.SetupAllProperties();
                impl.Setup(x => x.ClientSize).Returns(new Size(123, 456));

                // The user has resized the window, so we can no longer auto-size.
                var target = new TestTopLevel(impl.Object);
                impl.Object.Resized(new Size(100, 200));

                Assert.Equal(100, target.Width);
                Assert.Equal(200, target.Height);
            }
        }
Ejemplo n.º 51
0
 public void Exiting_Application_Notifies_Top_Level()
 {
     using (UnitTestApplication.Start(TestServices.StyledWindow))
     {
         var impl = new Mock<ITopLevelImpl>();
         impl.SetupAllProperties();
         var target = new TestTopLevel(impl.Object);
         UnitTestApplication.Current.Exit();
         Assert.True(target.IsClosed);
     }
 }
Ejemplo n.º 52
0
        public void Width_And_Height_Should_Not_Be_Set_After_Layout_Pass()
        {
            using (Locator.CurrentMutable.WithResolver())
            {
                this.RegisterServices();

                var impl = new Mock<ITopLevelImpl>();
                impl.Setup(x => x.ClientSize).Returns(new Size(123, 456));

                var target = new TestTopLevel(impl.Object);
                target.LayoutManager.ExecuteLayoutPass();

                Assert.Equal(double.NaN, target.Width);
                Assert.Equal(double.NaN, target.Height);
            }
        }
Ejemplo n.º 53
0
        public void Impl_Deactivate_Should_Call_Raise_Activated_Event()
        {
            using (PerspexLocator.EnterScope())
            {
                RegisterServices();

                var impl = new Mock<ITopLevelImpl>();
                impl.SetupAllProperties();

                bool raised = false;
                var target = new TestTopLevel(impl.Object);
                target.Deactivated += (s, e) => raised = true;

                impl.Object.Deactivated();

                Assert.True(raised);
            }
        }
Ejemplo n.º 54
0
        public void Impl_Deactivate_Should_Call_Raise_Activated_Event()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var impl = new Mock<ITopLevelImpl>();
                impl.SetupAllProperties();

                bool raised = false;
                var target = new TestTopLevel(impl.Object);
                target.Deactivated += (s, e) => raised = true;

                impl.Object.Deactivated();

                Assert.True(raised);
            }
        }
Ejemplo n.º 55
0
        public void Impl_Input_Should_Pass_Input_To_InputManager()
        {
            var inputManagerMock = new Mock<IInputManager>();
            var services = TestServices.StyledWindow.With(inputManager: inputManagerMock.Object);

            using (UnitTestApplication.Start(services))
            {
                var impl = new Mock<ITopLevelImpl>();
                impl.SetupAllProperties();

                var target = new TestTopLevel(impl.Object);

                var input = new RawKeyEventArgs(
                    new Mock<IKeyboardDevice>().Object,
                    0,
                    RawKeyEventType.KeyDown,
                    Key.A, InputModifiers.None);
                impl.Object.Input(input);

                inputManagerMock.Verify(x => x.ProcessInput(input));
            }
        }