public void Should_Be_Styled_As_UserControl() { using (UnitTestApplication.Start(TestServices.RealStyler)) { var target = new UserControl(); var root = new TestRoot { Styles = { new Style(x => x.OfType <UserControl>()) { Setters = new[] { new Setter(TemplatedControl.TemplateProperty, GetTemplate()) } } }, Child = target, }; Assert.NotNull(target.Template); } }
public void ListBoxItem_Containers_Should_Be_Generated() { using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface)) { var items = new[] { "Foo", "Bar", "Baz " }; var target = new ListBox { Template = ListBoxTemplate(), Items = items, }; Prepare(target); var text = target.Presenter.Panel.Children .OfType <ListBoxItem>() .Select(x => x.Presenter.Child) .OfType <TextBlock>() .Select(x => x.Text) .ToList(); Assert.Equal(items, text); } }
public void ShouldPersistState_Should_Fire_On_App_Exit_When_SuspensionDriver_Is_Initialized() { using (UnitTestApplication.Start(TestServices.MockWindowingPlatform)) using (var lifetime = new ClassicDesktopStyleApplicationLifetime()) { var shouldPersistReceived = false; var application = AvaloniaLocator.Current.GetService <Application>(); application.ApplicationLifetime = lifetime; // Initialize ReactiveUI Suspension as in real-world scenario. var suspension = new AutoSuspendHelper(application.ApplicationLifetime); RxApp.SuspensionHost.CreateNewAppState = () => new AppState { Example = "Foo" }; RxApp.SuspensionHost.ShouldPersistState.Subscribe(_ => shouldPersistReceived = true); RxApp.SuspensionHost.SetupDefaultSuspendResume(new DummySuspensionDriver()); suspension.OnFrameworkInitializationCompleted(); lifetime.Shutdown(); Assert.True(shouldPersistReceived); Assert.Equal("Foo", RxApp.SuspensionHost.GetAppState <AppState>().Example); } }
public void Can_Bind_To_DataContext_Of_Anchor_On_Non_Control() { using (UnitTestApplication.Start(TestServices.MockWindowingPlatform)) { var xaml = @" <Window xmlns='https://github.com/avaloniaui' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:local='clr-namespace:Avalonia.Markup.Xaml.UnitTests.Xaml;assembly=Avalonia.Markup.Xaml.UnitTests'> <Button Name='button'> <Button.Tag> <local:NonControl String='{Binding Foo}'/> </Button.Tag> </Button> </Window>"; var loader = new AvaloniaXamlLoader(); var window = (Window)loader.Load(xaml); var button = window.FindControl <Button>("button"); button.DataContext = new { Foo = "foo" }; Assert.Equal("foo", ((NonControl)button.Tag).String); } }
public void Binding_To_Second_Ancestor_Works() { using (UnitTestApplication.Start(TestServices.StyledWindow)) { var xaml = @" <Window xmlns='https://github.com/avaloniaui' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:local='clr-namespace:Avalonia.Markup.Xaml.UnitTests.Xaml;assembly=Avalonia.Markup.Xaml.UnitTests'> <Border Name='border1'> <Border Name='border2'> <Button Name='button' Content='{Binding Name, RelativeSource={RelativeSource AncestorType=Border, AncestorLevel=2}}'/> </Border> </Border> </Window>"; var loader = new AvaloniaXamlLoader(); var window = (Window)loader.Load(xaml); var button = window.FindControl <Button>("button"); window.ApplyTemplate(); Assert.Equal("border1", button.Content); } }
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) }); var windowImpl = MockWindowingPlatform.CreateWindowMock(); popupImpl = MockWindowingPlatform.CreatePopupMock(windowImpl.Object); popupImpl.SetupGet(x => x.RenderScaling).Returns(1); windowImpl.Setup(x => x.CreatePopup()).Returns(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, x => popupImpl.Object)); return(UnitTestApplication.Start(services)); }
public void StyleInclude_Is_Built() { using (UnitTestApplication.Start(TestServices.StyledWindow)) { var xaml = @" <Styles xmlns='https://github.com/avaloniaui' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'> <StyleInclude Source='resm:Avalonia.Themes.Default.ContextMenu.xaml?assembly=Avalonia.Themes.Default'/> </Styles>"; var styles = AvaloniaXamlLoader.Parse <Styles>(xaml); Assert.True(styles.Count == 1); var styleInclude = styles.First() as StyleInclude; Assert.NotNull(styleInclude); var style = styleInclude.Loaded; Assert.NotNull(style); } }
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); } }
public void StyleResource_Can_Be_Found_Across_Xaml_Files() { using (UnitTestApplication.Start(TestServices.StyledWindow)) { var xaml = @" <Window xmlns='https://github.com/avaloniaui' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'> <Window.Styles> <StyleInclude Source='resm:Avalonia.Markup.Xaml.UnitTests.Xaml.Style1.xaml?assembly=Avalonia.Markup.Xaml.UnitTests'/> <StyleInclude Source='resm:Avalonia.Markup.Xaml.UnitTests.Xaml.Style2.xaml?assembly=Avalonia.Markup.Xaml.UnitTests'/> </Window.Styles> <Border Name='border' Background='{StyleResource RedBrush}'/> </Window>"; var loader = new AvaloniaXamlLoader(); var window = (Window)loader.Load(xaml); var border = window.FindControl <Border>("border"); var borderBrush = (ISolidColorBrush)border.Background; Assert.NotNull(borderBrush); Assert.Equal(0xffff0000, borderBrush.Color.ToUint32()); } }
public void StyleInclude_Is_Built() { using (UnitTestApplication.Start(TestServices.StyledWindow .With(theme: () => new Styles()))) { var xaml = @" <ContentControl xmlns='https://github.com/avaloniaui'> <ContentControl.Styles> <StyleInclude Source='resm:Avalonia.Markup.Xaml.UnitTests.Xaml.Style1.xaml?assembly=Avalonia.Markup.Xaml.UnitTests'/> </ContentControl.Styles> </ContentControl>"; var window = AvaloniaXamlLoader.Parse <ContentControl>(xaml); Assert.Equal(1, window.Styles.Count); var styleInclude = window.Styles[0] as StyleInclude; Assert.NotNull(styleInclude); Assert.NotNull(styleInclude.Source); Assert.NotNull(styleInclude.Loaded); } }
public void Attaching_PopupRoot_To_Parent_Logical_Tree_Raises_DetachedFromLogicalTree_And_AttachedToLogicalTree() { using (UnitTestApplication.Start(TestServices.StyledWindow)) { var child = new Decorator(); var target = CreateTarget(); var window = new Window(); var detachedCount = 0; var attachedCount = 0; target.Content = child; target.DetachedFromLogicalTree += (s, e) => ++ detachedCount; child.DetachedFromLogicalTree += (s, e) => ++ detachedCount; target.AttachedToLogicalTree += (s, e) => ++ attachedCount; child.AttachedToLogicalTree += (s, e) => ++ attachedCount; ((ISetLogicalParent)target).SetParent(window); Assert.Equal(2, detachedCount); Assert.Equal(2, attachedCount); } }
public void Setter_Can_Set_Attached_Property() { using (UnitTestApplication.Start(TestServices.StyledWindow)) { var xaml = @" <Window xmlns='https://github.com/avaloniaui' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:local='clr-namespace:Avalonia.Markup.Xaml.UnitTests.Xaml;assembly=Avalonia.Markup.Xaml.UnitTests'> <Window.Styles> <Style Selector='TextBlock'> <Setter Property='DockPanel.Dock' Value='Right'/> </Style> </Window.Styles> <TextBlock/> </Window>"; var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); var textBlock = (TextBlock)window.Content; window.ApplyTemplate(); Assert.Equal(Dock.Right, DockPanel.GetDock(textBlock)); } }
public void Should_Push_Opacity_For_Controls_With_Less_Than_1_Opacity() { using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface)) { var root = new TestRoot { Width = 100, Height = 100, Child = new Border { Background = Brushes.Red, Opacity = 0.5, } }; root.Measure(Size.Infinity); root.Arrange(new Rect(root.DesiredSize)); var target = CreateTargetAndRunFrame(root); var context = GetLayerContext(target, root); var animation = new BehaviorSubject <double>(0.5); context.Verify(x => x.PushOpacity(0.5), Times.Once); context.Verify(x => x.DrawRectangle(Brushes.Red, null, new Rect(0, 0, 100, 100), default), Times.Once); context.Verify(x => x.PopOpacity(), Times.Once); } }
public void DataTemplate_Can_Be_Empty() { using (UnitTestApplication.Start(TestServices.StyledWindow)) { var xaml = @" <Window xmlns='https://github.com/avaloniaui' xmlns:sys='clr-namespace:System;assembly=netstandard' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'> <Window.DataTemplates> <DataTemplate DataType='{x:Type sys:String}' /> </Window.DataTemplates> <ContentControl Name='target' Content='Foo'/> </Window>"; var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); var target = window.FindControl <ContentControl>("target"); window.ApplyTemplate(); target.ApplyTemplate(); ((ContentPresenter)target.Presenter).UpdateChild(); Assert.Null(target.Presenter.Child); } }
public void AddDirty_Call_RenderRoot_Invalidate() { using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface)) { var visual = new Mock <Visual>(); var child = new Mock <Visual>() { CallBase = true }; var renderRoot = visual.As <IRenderRoot>(); visual.As <IVisual>().Setup(v => v.Bounds).Returns(new Rect(0, 0, 400, 400)); child.As <IVisual>().Setup(v => v.Bounds).Returns(new Rect(10, 10, 100, 100)); child.As <IVisual>().Setup(v => v.VisualParent).Returns(visual.Object); var target = new ImmediateRenderer(visual.Object); target.AddDirty(child.Object); renderRoot.Verify(v => v.Invalidate(new Rect(10, 10, 100, 100))); } }
public void Impl_Closing_Should_Remove_Window_From_OpenWindows() { var windowImpl = new Mock <IWindowImpl>(); windowImpl.SetupProperty(x => x.Closed); windowImpl.Setup(x => x.DesktopScaling).Returns(1); windowImpl.Setup(x => x.RenderScaling).Returns(1); var services = TestServices.StyledWindow.With( windowingPlatform: new MockWindowingPlatform(() => windowImpl.Object)); using (UnitTestApplication.Start(services)) using (var lifetime = new ClassicDesktopStyleApplicationLifetime()) { var window = new Window(); window.Show(); Assert.Equal(1, lifetime.Windows.Count); windowImpl.Object.Closed(); Assert.Empty(lifetime.Windows); } }
public void AutoScrollToSelectedItem_On_Reset_Works() { // Issue #3148 using (UnitTestApplication.Start(TestServices.StyledWindow)) { var items = new ResettingCollection(100); var target = new ListBox { Items = items, ItemTemplate = new FuncDataTemplate <string>((x, _) => new TextBlock { Text = x, Width = 100, Height = 10 }), AutoScrollToSelectedItem = true, VirtualizationMode = ItemVirtualizationMode.Simple, }; var root = new TestRoot(true, target); root.Measure(new Size(100, 100)); root.Arrange(new Rect(0, 0, 100, 100)); Assert.True(target.Presenter.Panel.Children.Count > 0); Assert.True(target.Presenter.Panel.Children.Count < 100); target.SelectedItem = "Item99"; // #3148 triggered here. items.Reset(new[] { "Item99" }); Assert.Equal(0, target.SelectedIndex); Assert.Equal(1, target.Presenter.Panel.Children.Count); } }
public void Should_Respect_Margin_For_ClipBounds() { using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface)) { Canvas canvas; var tree = new TestRoot { Width = 200, Height = 300, Child = new Border { Margin = new Thickness(10, 20, 30, 40), Child = canvas = new Canvas { Background = Brushes.AliceBlue, } } }; tree.Measure(Size.Infinity); tree.Arrange(new Rect(tree.DesiredSize)); var result = new Scene(tree); var sceneBuilder = new SceneBuilder(); sceneBuilder.UpdateAll(result); var canvasNode = result.FindNode(canvas); Assert.Equal(new Rect(10, 20, 160, 240), canvasNode.ClipBounds); // Initial ClipBounds are correct, make sure they're still correct after updating canvas. result = result.Clone(); Assert.True(sceneBuilder.Update(result, canvas)); canvasNode = result.FindNode(canvas); Assert.Equal(new Rect(10, 20, 160, 240), canvasNode.ClipBounds); } }
public void Control_Backspace_Should_Remove_The_Word_Before_The_Caret_If_There_Is_No_Selection() { using (UnitTestApplication.Start(Services)) { TextBox textBox = new TextBox { Text = "First Second Third Fourth", CaretIndex = 5 }; // (First| Second Third Fourth) RaiseKeyEvent(textBox, Key.Back, KeyModifiers.Control); Assert.Equal(" Second Third Fourth", textBox.Text); // ( Second |Third Fourth) textBox.CaretIndex = 8; RaiseKeyEvent(textBox, Key.Back, KeyModifiers.Control); Assert.Equal(" Third Fourth", textBox.Text); // ( Thi|rd Fourth) textBox.CaretIndex = 4; RaiseKeyEvent(textBox, Key.Back, KeyModifiers.Control); Assert.Equal(" rd Fourth", textBox.Text); // ( rd F[ou]rth) textBox.SelectionStart = 5; textBox.SelectionEnd = 7; RaiseKeyEvent(textBox, Key.Back, KeyModifiers.Control); Assert.Equal(" rd Frth", textBox.Text); // ( |rd Frth) textBox.CaretIndex = 1; RaiseKeyEvent(textBox, Key.Back, KeyModifiers.Control); Assert.Equal("rd Frth", textBox.Text); } }
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>())).Callback <Size>(size => { clientSize = size.Constrain(maxClientSize); windowImpl.Object.Resized?.Invoke(clientSize); }); 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 Control_Delete_Should_Remove_The_Word_After_The_Caret_If_There_Is_No_Selection() { using (UnitTestApplication.Start(Services)) { TextBox textBox = new TextBox { Text = "First Second Third Fourth", CaretIndex = 19 }; // (First Second Third |Fourth) RaiseKeyEvent(textBox, Key.Delete, InputModifiers.Control); Assert.Equal("First Second Third ", textBox.Text); // (First Second| Third ) textBox.CaretIndex = 12; RaiseKeyEvent(textBox, Key.Delete, InputModifiers.Control); Assert.Equal("First Second ", textBox.Text); // (First Sec|ond ) textBox.CaretIndex = 9; RaiseKeyEvent(textBox, Key.Delete, InputModifiers.Control); Assert.Equal("First Sec ", textBox.Text); // (Fi[rs]t Sec ) textBox.SelectionStart = 2; textBox.SelectionEnd = 4; RaiseKeyEvent(textBox, Key.Delete, InputModifiers.Control); Assert.Equal("Fit Sec ", textBox.Text); // (Fit Sec| ) textBox.CaretIndex = 7; RaiseKeyEvent(textBox, Key.Delete, InputModifiers.Control); Assert.Equal("Fit Sec", textBox.Text); } }
public void ListBox_After_Scroll_IndexOutOfRangeException_Shouldnt_Be_Thrown() { using (UnitTestApplication.Start(TestServices.StyledWindow)) { var items = Enumerable.Range(0, 11).Select(x => $"{x}").ToArray(); var target = new ListBox { Template = ListBoxTemplate(), Items = items, ItemTemplate = new FuncDataTemplate <string>((x, _) => new TextBlock { Height = 11 }) }; Prepare(target); var panel = target.Presenter.Panel as IVirtualizingPanel; var listBoxItems = panel.Children.OfType <ListBoxItem>(); //virtualization should have created exactly 10 items Assert.Equal(10, listBoxItems.Count()); Assert.Equal("0", listBoxItems.First().DataContext); Assert.Equal("9", listBoxItems.Last().DataContext); //instead pixeloffset > 0 there could be pretty complex sequence for repro //it involves add/remove/scroll to end multiple actions //which i can't find so far :(, but this is the simplest way to add it to unit test panel.PixelOffset = 1; //here scroll to end -> IndexOutOfRangeException is thrown target.Scroll.Offset = new Vector(0, 2); Assert.True(true); } }
public void GeometryClip_Should_Affect_Child_Layers() { using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface)) { var clip = StreamGeometry.Parse("M100,0 L0,100 100,100"); Decorator decorator; Border border; var tree = new TestRoot { Child = decorator = new Decorator { Clip = clip, Margin = new Thickness(12, 16), Child = border = new Border { Opacity = 0.5, Child = new Canvas(), } } }; var layout = tree.LayoutManager; layout.ExecuteInitialLayoutPass(); var animation = new BehaviorSubject <double>(0.5); border.Bind(Border.OpacityProperty, animation, BindingPriority.Animation); var scene = new Scene(tree); var sceneBuilder = new SceneBuilder(); sceneBuilder.UpdateAll(scene); var borderLayer = scene.Layers[border]; Assert.Equal( Matrix.CreateTranslation(12, 16), ((MockStreamGeometryImpl)borderLayer.GeometryClip).Transform); } }
public void PopupRoot_Should_Have_Template_Applied() { using (UnitTestApplication.Start(TestServices.StyledWindow)) { var window = new Window(); var target = new Popup { PlacementMode = PlacementMode.Pointer }; var child = new Control(); window.Content = target; window.ApplyTemplate(); target.Open(); Assert.Single(((Visual)target.Host).GetVisualChildren()); var templatedChild = ((Visual)target.Host).GetVisualChildren().Single(); Assert.IsType <LayoutTransformControl>(templatedChild); var panel = templatedChild.GetVisualChildren().Single(); Assert.IsType <Panel>(panel); var visualLayerManager = panel.GetVisualChildren().Skip(1).Single(); Assert.IsType <VisualLayerManager>(visualLayerManager); var contentPresenter = visualLayerManager.VisualChildren.Single(); Assert.IsType <ContentPresenter>(contentPresenter); Assert.Equal((PopupRoot)target.Host, ((IControl)templatedChild).TemplatedParent); Assert.Equal((PopupRoot)target.Host, ((IControl)contentPresenter).TemplatedParent); } }
public void Style_Can_Use_NthLastChild_Selector_After_Reoder() { using (UnitTestApplication.Start(TestServices.StyledWindow)) { var xaml = @" <Window xmlns='https://github.com/avaloniaui' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'> <Window.Styles> <Style Selector='Border:nth-last-child(2n)'> <Setter Property='Background' Value='Red'/> </Style> </Window.Styles> <StackPanel x:Name='parent'> <Border x:Name='b1' /> <Border x:Name='b2' /> </StackPanel> </Window>"; var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); var parent = window.FindControl <StackPanel>("parent"); var b1 = window.FindControl <Border>("b1"); var b2 = window.FindControl <Border>("b2"); Assert.Equal(Brushes.Red, b1.Background); Assert.Null(b2.Background); parent.Children.Remove(b1); Assert.Null(b1.Background); Assert.Null(b2.Background); parent.Children.Add(b1); Assert.Null(b1.Background); Assert.Equal(Brushes.Red, b2.Background); } }
public void Inactive_Values_Should_Not_Be_Made_Active_During_Style_Detach() { using var app = UnitTestApplication.Start(TestServices.RealStyler); var root = new TestRoot { Styles = { new Style(x => x.OfType <Class1>()) { Setters = { new Setter(Class1.FooProperty, "Foo"), }, }, new Style(x => x.OfType <Class1>()) { Setters = { new Setter(Class1.FooProperty, "Bar"), }, } } }; var target = new Class1(); root.Child = target; var values = new List <string>(); target.GetObservable(Class1.FooProperty).Subscribe(x => values.Add(x)); root.Child = null; Assert.Equal(new[] { "Bar", "foodefault" }, values); }
public void ScrollViewer_With_Content_Is_Freed() { using (UnitTestApplication.Start(TestServices.StyledWindow)) { Func <Window> run = () => { var window = new Window { Content = new ScrollViewer { Content = new Canvas() } }; // Do a layout and make sure that ScrollViewer gets added to visual tree and its // template applied. LayoutManager.Instance.ExecuteInitialLayoutPass(window); Assert.IsType <ScrollViewer>(window.Presenter.Child); Assert.IsType <Canvas>(((ScrollViewer)window.Presenter.Child).Presenter.Child); // Clear the content and ensure the ScrollViewer is removed. window.Content = null; LayoutManager.Instance.ExecuteLayoutPass(); Assert.Null(window.Presenter.Child); return(window); }; var result = run(); PurgeMoqReferences(); dotMemory.Check(memory => Assert.Equal(0, memory.GetObjects(where => where.Type.Is <TextBox>()).ObjectsCount)); dotMemory.Check(memory => Assert.Equal(0, memory.GetObjects(where => where.Type.Is <Canvas>()).ObjectsCount)); } }
public void Capture_Is_Transferred_To_Parent_When_Control_Removed() { using var app = UnitTestApplication.Start(new TestServices(inputManager: new InputManager())); var renderer = new Mock <IRenderer>(); var device = new MouseDevice(); var impl = CreateTopLevelImplMock(renderer.Object); Canvas control; Panel rootChild; var root = CreateInputRoot(impl.Object, rootChild = new Panel { Children = { (control = new Canvas()) } }); // Synthesize event to receive a pointer. IPointer result = null; root.PointerMoved += (_, a) => { result = a.Pointer; }; SetHit(renderer, control); impl.Object.Input !(CreateRawPointerMovedArgs(device, root)); Assert.NotNull(result); result.Capture(control); Assert.Same(control, result.Captured); rootChild.Children.Clear(); Assert.Same(rootChild, result.Captured); }
public void LastWindow_Closed_Shutdown_Should_Be_Cancellable() { using (UnitTestApplication.Start(TestServices.StyledWindow)) using (var lifetime = new ClassicDesktopStyleApplicationLifetime()) { lifetime.ShutdownMode = ShutdownMode.OnLastWindowClose; var hasExit = false; lifetime.Exit += (_, _) => hasExit = true; var windowA = new Window(); windowA.Show(); var windowB = new Window(); windowB.Show(); var raised = 0; lifetime.ShutdownRequested += (_, e) => { e.Cancel = true; ++raised; }; windowA.Close(); Assert.False(hasExit); windowB.Close(); Assert.Equal(1, raised); Assert.False(hasExit); } }
public void Should_Set_Child_LogicalParent_After_Removing_And_Adding_Back_To_Logical_Tree() { using (UnitTestApplication.Start(TestServices.RealStyler)) { var target = new ContentControl(); var root = new TestRoot { Styles = { new Style(x => x.OfType <ContentControl>()) { Setters = { new Setter(ContentControl.TemplateProperty, GetTemplate()), } } }, Child = target }; target.Content = "Foo"; target.ApplyTemplate(); target.Presenter.ApplyTemplate(); Assert.Equal(target, target.Presenter.Child.LogicalParent); root.Child = null; Assert.Null(target.Template); target.Content = null; root.Child = target; target.Content = "Bar"; Assert.Equal(target, target.Presenter.Child.LogicalParent); } }