Пример #1
0
        public void Frame_Does_Not_Call_SceneBuilder_If_No_Dirty_Controls()
        {
            using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
            {
                var dispatcher   = new ImmediateDispatcher();
                var loop         = new Mock <IRenderLoop>();
                var root         = new TestRoot();
                var sceneBuilder = MockSceneBuilder(root);

                var target = new DeferredRenderer(
                    root,
                    loop.Object,
                    sceneBuilder: sceneBuilder.Object);

                target.Start();
                IgnoreFirstFrame(target, sceneBuilder);
                RunFrame(target);

                sceneBuilder.Verify(x => x.UpdateAll(It.IsAny <Scene>()), Times.Never);
                sceneBuilder.Verify(x => x.Update(It.IsAny <Scene>(), It.IsAny <Visual>()), Times.Never);
            }
        }
Пример #2
0
        public void Should_Create_Layer_For_Root()
        {
            using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
            {
                var root      = new TestRoot();
                var rootLayer = new Mock <IRenderTargetBitmapImpl>();

                var sceneBuilder = new Mock <ISceneBuilder>();

                sceneBuilder.Setup(x => x.UpdateAll(It.IsAny <Scene>()))
                .Callback <Scene>(scene =>
                {
                    scene.Size = root.ClientSize;
                    scene.Layers.Add(root).Dirty.Add(new Rect(root.ClientSize));
                });

                var renderInterface = new Mock <IPlatformRenderInterface>();
                var target          = CreateTargetAndRunFrame(root, sceneBuilder: sceneBuilder.Object);

                Assert.Single(target.Layers);
            }
        }
        public async Task Bind_With_Scheduler_Executes_On_Scheduler()
        {
            var target          = new Class1();
            var source          = new Subject <double>();
            var currentThreadId = Thread.CurrentThread.ManagedThreadId;

            var threadingInterfaceMock = new Mock <IPlatformThreadingInterface>();

            threadingInterfaceMock.SetupGet(mock => mock.CurrentThreadIsLoopThread)
            .Returns(() => Thread.CurrentThread.ManagedThreadId == currentThreadId);

            var services = new TestServices(
                scheduler: AvaloniaScheduler.Instance,
                threadingInterface: threadingInterfaceMock.Object);

            using (UnitTestApplication.Start(services))
            {
                target.Bind(Class1.QuxProperty, source);

                await Task.Run(() => source.OnNext(6.7));
            }
        }
Пример #4
0
            public void Width_Height_Should_Not_Be_NaN_After_Show_With_SizeToContent_WidthAndHeight()
            {
                using (UnitTestApplication.Start(TestServices.StyledWindow))
                {
                    var child = new Canvas
                    {
                        Width  = 400,
                        Height = 800,
                    };

                    var target = new Window()
                    {
                        SizeToContent = SizeToContent.WidthAndHeight,
                        Content       = child
                    };

                    Show(target);

                    Assert.Equal(400, target.Width);
                    Assert.Equal(800, target.Height);
                }
            }
Пример #5
0
            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]);
                }
            }
Пример #6
0
        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(screen, screen, true) });

            var windowImpl = new Mock <IWindowImpl>();

            windowImpl.Setup(x => x.Screen).Returns(screenImpl.Object);

            popupImpl = new Mock <IPopupImpl>();
            popupImpl.SetupGet(x => x.Scaling).Returns(1);

            var services = TestServices.StyledWindow.With(
                inputManager: new InputManager(),
                windowImpl: windowImpl.Object,
                windowingPlatform: new MockWindowingPlatform(() => windowImpl.Object, () => popupImpl.Object));

            return(UnitTestApplication.Start(services));
        }
Пример #7
0
        public void Subscribes_To_Geometry_Changes()
        {
            using var app = UnitTestApplication.Start(TestServices.MockPlatformRenderInterface);

            var geometry = new EllipseGeometry {
                Rect = new Rect(0, 0, 10, 10)
            };
            var target = new Path {
                Data = geometry
            };

            var root = new TestRoot(target);

            target.Measure(Size.Infinity);
            Assert.True(target.IsMeasureValid);

            geometry.Rect = new Rect(0, 0, 20, 20);

            Assert.False(target.IsMeasureValid);

            root.Child = null;
        }
Пример #8
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);
            }
        }
Пример #9
0
        public void Adding_Nested_Style_Should_Attach_To_Control()
        {
            using (UnitTestApplication.Start(TestServices.RealStyler))
            {
                var border = new Border();
                var root   = new TestRoot
                {
                    Styles =
                    {
                        new Styles
                        {
                            new Style(x => x.OfType <Border>())
                            {
                                Setters =
                                {
                                    new Setter(Border.BorderThicknessProperty, new Thickness(4)),
                                }
                            }
                        }
                    },
                    Child = border,
                };

                root.Measure(Size.Infinity);
                Assert.Equal(new Thickness(4), border.BorderThickness);

                ((Styles)root.Styles[0]).Add(new Style(x => x.OfType <Border>())
                {
                    Setters =
                    {
                        new Setter(Border.BorderThicknessProperty, new Thickness(6)),
                    }
                });

                root.Measure(Size.Infinity);
                Assert.Equal(new Thickness(6), border.BorderThickness);
            }
        }
Пример #10
0
        public void Should_Work_Inside_Of_Tooltip()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var window = new Window();
                var source = new Button
                {
                    Template = new FuncControlTemplate <Button>((parent, _) =>
                                                                new Decorator
                    {
                        [ToolTip.TipProperty] = new TextBlock
                        {
                            [~TextBlock.TextProperty] = new TemplateBinding(ContentControl.ContentProperty)
                        }
                    }),
                };

                window.Content = source;
                window.Show();
                try
                {
                    var templateChild = (Decorator)source.GetVisualChildren().Single();
                    ToolTip.SetIsOpen(templateChild, true);

                    var target = (TextBlock)ToolTip.GetTip(templateChild) !;

                    Assert.Null(target.Text);
                    source.Content = "foo";
                    Assert.Equal("foo", target.Text);
                    source.Content = "bar";
                    Assert.Equal("bar", target.Text);
                }
                finally
                {
                    window.Close();
                }
            }
        }
Пример #11
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);
                }
            }
Пример #12
0
        public void Transition_Is_Not_Applied_To_Initial_Style()
        {
            using (UnitTestApplication.Start(TestServices.RealStyler))
            {
                var target  = CreateTarget();
                var control = new Control
                {
                    Transitions = new Transitions {
                        target.Object
                    },
                };

                var root = new TestRoot
                {
                    Styles =
                    {
                        new Style(x => x.OfType <Control>())
                        {
                            Setters =
                            {
                                new Setter(Visual.OpacityProperty, 0.8),
                            }
                        }
                    }
                };

                root.Child = control;

                Assert.Equal(0.8, control.Opacity);

                target.Verify(x => x.Apply(
                                  It.IsAny <Control>(),
                                  It.IsAny <IClock>(),
                                  It.IsAny <object>(),
                                  It.IsAny <object>()),
                              Times.Never);
            }
        }
Пример #13
0
        public void Disposing_Scene_Releases_DrawOperation_References()
        {
            using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
            {
                var bitmap = RefCountable.Create(Mock.Of <IBitmapImpl>(
                                                     x => x.PixelSize == new PixelSize(100, 100) &&
                                                     x.Dpi == new Vector(96, 96)));

                Image img;
                var   tree = new TestRoot
                {
                    Child = img = new Image
                    {
                        Source = new Bitmap(bitmap),
                        Height = 100,
                        Width  = 100
                    }
                };

                tree.Measure(Size.Infinity);
                tree.Arrange(new Rect(new Size(100, 100)));

                Assert.Equal(2, bitmap.RefCount);
                IRef <IDrawOperation> operation;

                using (var scene = new Scene(tree))
                {
                    var sceneBuilder = new SceneBuilder();
                    sceneBuilder.UpdateAll(scene);
                    operation = scene.FindNode(img).DrawOperations[0];
                    Assert.Equal(1, operation.RefCount);

                    Assert.Equal(3, bitmap.RefCount);
                }
                Assert.Equal(0, operation.RefCount);
                Assert.Equal(2, bitmap.RefCount);
            }
        }
Пример #14
0
        public void MaxLength_Works_Properly(
            string initalText,
            string textInput,
            int maxLength,
            int selectionStart,
            int selectionEnd,
            bool fromClipboard,
            string expected)
        {
            using (UnitTestApplication.Start(Services))
            {
                var target = new TextBox
                {
                    Template       = CreateTemplate(),
                    Text           = initalText,
                    MaxLength      = maxLength,
                    SelectionStart = selectionStart,
                    SelectionEnd   = selectionEnd
                };

                if (fromClipboard)
                {
                    AvaloniaLocator.CurrentMutable.Bind <IClipboard>().ToSingleton <ClipboardStub>();

                    var clipboard = AvaloniaLocator.CurrentMutable.GetService <IClipboard>();
                    clipboard.SetTextAsync(textInput).GetAwaiter().GetResult();

                    RaiseKeyEvent(target, Key.V, KeyModifiers.Control);
                    clipboard.ClearAsync().GetAwaiter().GetResult();
                }
                else
                {
                    RaiseTextEvent(target, textInput);
                }

                Assert.Equal(expected, target.Text);
            }
        }
Пример #15
0
        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
                        {
                            ClipToBounds = true,
                            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.CloneScene();
                Assert.True(sceneBuilder.Update(result, canvas));

                canvasNode = result.FindNode(canvas);
                Assert.Equal(new Rect(10, 20, 160, 240), canvasNode.ClipBounds);
            }
        }
Пример #16
0
        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, KeyModifiers.Control);
                Assert.Equal("First Second Third ", textBox.Text);

                // (First Second |Third )
                textBox.CaretIndex = 13;
                RaiseKeyEvent(textBox, Key.Delete, KeyModifiers.Control);
                Assert.Equal("First Second ", textBox.Text);

                // (First Sec|ond )
                textBox.CaretIndex = 9;
                RaiseKeyEvent(textBox, Key.Delete, KeyModifiers.Control);
                Assert.Equal("First Sec", textBox.Text);

                // (Fi[rs]t Sec )
                textBox.SelectionStart = 2;
                textBox.SelectionEnd   = 4;

                RaiseKeyEvent(textBox, Key.Delete, KeyModifiers.Control);
                Assert.Equal("Fit Sec", textBox.Text);

                // (Fit Sec| )
                textBox.Text      += " ";
                textBox.CaretIndex = 7;
                RaiseKeyEvent(textBox, Key.Delete, KeyModifiers.Control);
                Assert.Equal("Fit Sec", textBox.Text);
            }
        }
Пример #17
0
        public void GetVisualsAt_Should_Return_Top_Controls_First()
        {
            using (UnitTestApplication.Start(new TestServices(renderInterface: new MockRenderInterface())))
            {
                var container = new Panel
                {
                    Width    = 200,
                    Height   = 200,
                    Children = new Controls.Controls
                    {
                        new Border
                        {
                            Width  = 100,
                            Height = 100,
                            HorizontalAlignment = HorizontalAlignment.Center,
                            VerticalAlignment   = VerticalAlignment.Center
                        },
                        new Border
                        {
                            Width  = 50,
                            Height = 50,
                            HorizontalAlignment = HorizontalAlignment.Center,
                            VerticalAlignment   = VerticalAlignment.Center
                        }
                    }
                };

                container.Measure(Size.Infinity);
                container.Arrange(new Rect(container.DesiredSize));

                var context = new DrawingContext(Mock.Of <IDrawingContextImpl>());
                context.Render(container);

                var result = container.GetVisualsAt(new Point(100, 100));

                Assert.Equal(new[] { container.Children[1], container.Children[0], container }, result);
            }
        }
Пример #18
0
        public void Does_Not_Focus_Non_Focusable_Item_On_Key_Down()
        {
            using (UnitTestApplication.Start(TestServices.RealFocus))
            {
                var items = new object[]
                {
                    new Button(),
                    new Button {
                        Focusable = false
                    },
                    new Button(),
                };

                var target = new ItemsControl
                {
                    Template = GetTemplate(),
                    Items    = items,
                };

                var root = new TestRoot {
                    Child = target
                };

                target.ApplyTemplate();
                target.Presenter.ApplyTemplate();
                target.Presenter.Panel.Children[0].Focus();

                target.RaiseEvent(new KeyEventArgs
                {
                    RoutedEvent = InputElement.KeyDownEvent,
                    Key         = Key.Down,
                });

                Assert.Equal(
                    target.Presenter.Panel.Children[2],
                    FocusManager.Instance.Current);
            }
        }
Пример #19
0
        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 Setter_Exceptions_Should_Set_DataValidationErrors_Errors()
        {
            using (UnitTestApplication.Start(Services))
            {
                var target = new TextBox
                {
                    DataContext             = new ExceptionTest(),
                    [!TextBox.TextProperty] = new Binding(nameof(ExceptionTest.LessThan10), BindingMode.TwoWay),
                    Template = CreateTemplate(),
                };

                target.ApplyTemplate();

                Assert.Null(DataValidationErrors.GetErrors(target));
                target.Text = "20";

                IEnumerable <object> errors = DataValidationErrors.GetErrors(target);
                Assert.Single(errors);
                Assert.IsType <InvalidOperationException>(errors.Single());
                target.Text = "1";
                Assert.Null(DataValidationErrors.GetErrors(target));
            }
        }
Пример #21
0
        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);
            }
        }
Пример #22
0
        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);
            }
        }
Пример #23
0
        public void Binding_To_First_Ancestor_With_Shorthand_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 $parent.Name}'/>
      </Border>
    </Border>
</Window>";
                var loader = new AvaloniaXamlLoader();
                var window = (Window)loader.Load(xaml);
                var button = window.FindControl <Button>("button");

                window.ApplyTemplate();

                Assert.Equal("border2", button.Content);
            }
        }
Пример #24
0
        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);
            }
        }
Пример #25
0
        public void ShouldPersistState_Should_Fire_On_App_Exit_When_SuspensionDriver_Is_Initialized()
        {
            using (UnitTestApplication.Start(TestServices.MockWindowingPlatform))
                using (var lifetime = new ClassicDesktopStyleApplicationLifetime(Application.Current))
                {
                    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 Attaching_PopupRoot_To_Parent_Logical_Tree_Raises_DetachedFromLogicalTree_And_AttachedToLogicalTree()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var child         = new Decorator();
                var window        = new Window();
                var target        = CreateTarget(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);
            }
        }
Пример #27
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,
                    target,
                    RawKeyEventType.KeyDown,
                    Key.A, RawInputModifiers.None);
                impl.Object.Input(input);

                inputManagerMock.Verify(x => x.ProcessInput(input));
            }
        }
Пример #28
0
        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)));
            }
        }
Пример #29
0
        public void Binding_Method_With_Parameter_To_Command_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'>
    <Button Name='button' Command='{Binding Method1}' CommandParameter='5'/>
</Window>";
                var loader = new AvaloniaXamlLoader();
                var window = (Window)loader.Load(xaml);
                var button = window.FindControl <Button>("button");
                var vm     = new ViewModel();

                button.DataContext = vm;
                window.ApplyTemplate();

                Assert.NotNull(button.Command);
                PerformClick(button);
                Assert.Equal("Called 5", vm.Value);
            }
        }
Пример #30
0
        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);
            }
        }