test: add failing test case for issue 460.
This commit is contained in:
@@ -0,0 +1,44 @@
|
|||||||
|
using Avalonia.Headless.XUnit;
|
||||||
|
using Ursa.Controls;
|
||||||
|
|
||||||
|
namespace HeadlessTest.Ursa.Controls.UrsaWindowTests;
|
||||||
|
|
||||||
|
public class UrsaWindowTest
|
||||||
|
{
|
||||||
|
[AvaloniaFact]
|
||||||
|
public void Default_UrsaWindow_Closing_Is_Called_Once()
|
||||||
|
{
|
||||||
|
var ursaWindow = new UrsaWindow();
|
||||||
|
ursaWindow.Show();
|
||||||
|
int count = 0;
|
||||||
|
ursaWindow.Closing += (_, _) => count++;
|
||||||
|
ursaWindow.Close();
|
||||||
|
Assert.Equal(1, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
[AvaloniaFact]
|
||||||
|
public async void Inferenced_Window_Closing_Called_Once_When_Yes()
|
||||||
|
{
|
||||||
|
var window = new UrsaWindowWithCloseInference();
|
||||||
|
window.Show();
|
||||||
|
int count = 0;
|
||||||
|
window.Closing += (_, _) => count++;
|
||||||
|
window.Close();
|
||||||
|
window.DialogViewModel.CloseYes();
|
||||||
|
Assert.Equal(1, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
[AvaloniaFact]
|
||||||
|
public async void Inferenced_Window_Closing_Called_Once_When_No()
|
||||||
|
{
|
||||||
|
var window = new UrsaWindowWithCloseInference();
|
||||||
|
window.Show();
|
||||||
|
int count = 0;
|
||||||
|
window.Closing += (_, _) => count++;
|
||||||
|
window.Close();
|
||||||
|
window.DialogViewModel.Close();
|
||||||
|
Assert.Equal(1, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<u:UrsaWindow xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:u="https://irihi.tech/ursa"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="800"
|
||||||
|
d:DesignHeight="450"
|
||||||
|
x:Class="HeadlessTest.Ursa.Controls.UrsaWindowTests.UrsaWindowWithCloseInference"
|
||||||
|
Title="UrsaWindowWithCloseInference">
|
||||||
|
Hello World
|
||||||
|
</u:UrsaWindow>
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Interactivity;
|
||||||
|
using Avalonia.Markup.Xaml;
|
||||||
|
using Irihi.Avalonia.Shared.Contracts;
|
||||||
|
using Ursa.Controls;
|
||||||
|
|
||||||
|
namespace HeadlessTest.Ursa.Controls.UrsaWindowTests;
|
||||||
|
|
||||||
|
public partial class UrsaWindowWithCloseInference : UrsaWindow
|
||||||
|
{
|
||||||
|
public UrsaWindowWithCloseInference()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal TextBox TextBox = new TextBox();
|
||||||
|
internal DialogViewModel DialogViewModel = new DialogViewModel();
|
||||||
|
|
||||||
|
protected override async Task<bool> CanClose()
|
||||||
|
{
|
||||||
|
var result = await OverlayDialog.ShowModal(TextBox, DialogViewModel);
|
||||||
|
return result == DialogResult.Yes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DialogViewModel : IDialogContext
|
||||||
|
{
|
||||||
|
public void Close()
|
||||||
|
{
|
||||||
|
RequestClose?.Invoke(this, DialogResult.No);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CloseYes()
|
||||||
|
{
|
||||||
|
RequestClose?.Invoke(this, DialogResult.Yes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public event EventHandler<object?>? RequestClose;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user