Browse Source
...to `Avalonia.Markup.Xaml`. Also added tests: tests required a new instance of `AvaloniaXamlSchemaContext` for each `AvaloniaXamlLoader` as otherwise one test can affect other tests.pull/2307/head
7 changed files with 99 additions and 40 deletions
@ -1 +1 @@ |
|||
Subproject commit 5d2edfcc1b2988f80303b1b2f3dd2b7c3de53db7 |
|||
Subproject commit ab5526173722b8988bc5ca3c03c8752ce89c0975 |
|||
@ -0,0 +1,66 @@ |
|||
// Copyright (c) The Avalonia Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System; |
|||
using Avalonia.Controls; |
|||
using Avalonia.Input; |
|||
using Portable.Xaml; |
|||
using Xunit; |
|||
|
|||
namespace Avalonia.Markup.Xaml.UnitTests.Xaml |
|||
{ |
|||
public class EventTests |
|||
{ |
|||
[Fact] |
|||
public void Event_Is_Attached() |
|||
{ |
|||
var xaml = @"<Button xmlns='https://github.com/avaloniaui' Click='OnClick'/>"; |
|||
var loader = new AvaloniaXamlLoader(); |
|||
var target = new MyButton(); |
|||
|
|||
loader.Load(xaml, rootInstance: target); |
|||
RaiseClick(target); |
|||
|
|||
Assert.True(target.Clicked); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Exception_Is_Thrown_If_Event_Not_Found() |
|||
{ |
|||
var xaml = @"<Button xmlns='https://github.com/avaloniaui' Click='NotFound'/>"; |
|||
var loader = new AvaloniaXamlLoader(); |
|||
var target = new MyButton(); |
|||
|
|||
Assert.Throws<XamlObjectWriterException>(() => loader.Load(xaml, rootInstance: target)); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Exception_Is_Not_Thrown_If_Event_Not_Found_In_Design_Mode() |
|||
{ |
|||
var xaml = @"<Button xmlns='https://github.com/avaloniaui' Click='NotFound'/>"; |
|||
var loader = new AvaloniaXamlLoader { IsDesignMode = true }; |
|||
var target = new MyButton(); |
|||
|
|||
loader.Load(xaml, rootInstance: target); |
|||
} |
|||
|
|||
private void RaiseClick(MyButton target) |
|||
{ |
|||
target.RaiseEvent(new KeyEventArgs |
|||
{ |
|||
RoutedEvent = Button.KeyDownEvent, |
|||
Key = Key.Enter, |
|||
}); |
|||
} |
|||
|
|||
class MyButton : Button |
|||
{ |
|||
public bool Clicked { get; private set; } |
|||
|
|||
public void OnClick(object sender, EventArgs e) |
|||
{ |
|||
Clicked = true; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue