Ejemplo n.º 1
0
        public void Attached_ContextMenu_Is_Freed()
        {
            using (Start())
            {
                void AttachShowAndDetachContextMenu(Control control)
                {
                    var contextMenu = new ContextMenu
                    {
                        Items = new[]
                        {
                            new MenuItem {
                                Header = "Foo"
                            },
                            new MenuItem {
                                Header = "Foo"
                            },
                        }
                    };

                    control.ContextMenu = contextMenu;
                    contextMenu.Open(control);
                    contextMenu.Close();
                    control.ContextMenu = null;
                }

                var window = new Window();
                window.Show();

                Assert.Same(window, FocusManager.Instance.Current);

                // Context menu in resources means the baseline may not be 0.
                var initialMenuCount     = 0;
                var initialMenuItemCount = 0;
                dotMemory.Check(memory =>
                {
                    initialMenuCount     = memory.GetObjects(where => where.Type.Is <ContextMenu>()).ObjectsCount;
                    initialMenuItemCount = memory.GetObjects(where => where.Type.Is <MenuItem>()).ObjectsCount;
                });

                AttachShowAndDetachContextMenu(window);

                Mock.Get(ValidatingWindowImpl.Unwrap(window.PlatformImpl)).Invocations.Clear();
                dotMemory.Check(memory =>
                                Assert.Equal(initialMenuCount, memory.GetObjects(where => where.Type.Is <ContextMenu>()).ObjectsCount));
                dotMemory.Check(memory =>
                                Assert.Equal(initialMenuItemCount, memory.GetObjects(where => where.Type.Is <MenuItem>()).ObjectsCount));
            }
        }
Ejemplo n.º 2
0
            public void Setting_Width_Should_Resize_WindowImpl()
            {
                // Issue #3796
                using (UnitTestApplication.Start(TestServices.StyledWindow))
                {
                    var target = new Window()
                    {
                        Width  = 400,
                        Height = 800,
                    };

                    Show(target);

                    Assert.Equal(400, target.Width);
                    Assert.Equal(800, target.Height);

                    target.Width = 410;
                    target.LayoutManager.ExecuteLayoutPass();

                    var windowImpl = Mock.Get(ValidatingWindowImpl.Unwrap(target.PlatformImpl));
                    windowImpl.Verify(x => x.Resize(new Size(410, 800), PlatformResizeReason.Application));
                    Assert.Equal(410, target.Width);
                }
            }