Fixes #3956. MessageBox doesn't return the index of IsDefault button (#3958)

* Fixes #3956. MessageBox doesn't return the index of IsDefault button

* Change to Theory test.

* Fix unit test 'Error opening terminal: unknown.'

* Remove RunningUnitTests = true because constructor already set it.

---------

Co-authored-by: Tig <tig@users.noreply.github.com>
This commit is contained in:
BDisp
2025-03-06 21:06:51 +00:00
committed by GitHub
parent 7162ed850c
commit 85cf6619ed
2 changed files with 25 additions and 1 deletions

View File

@@ -374,6 +374,10 @@ public static class MessageBox
{
Clicked = (int)btn.Data!;
}
else
{
Clicked = defaultButton;
}
e.Cancel = true;
Application.RequestStop ();

View File

@@ -504,5 +504,25 @@ public class MessageBoxTests
Application.Run (top);
top.Dispose ();
}
}
[Theory]
[SetupFakeDriver]
[MemberData (nameof (AcceptingKeys))]
public void Button_IsDefault_True_Return_His_Index_On_Accepting (Key key)
{
Application.Init ();
Application.Iteration += (_, _) => Assert.True (Application.RaiseKeyDownEvent (key));
int res = MessageBox.Query ("hey", "IsDefault", "Yes", "No");
Assert.Equal (0, res);
Application.Shutdown ();
}
public static IEnumerable<object []> AcceptingKeys ()
{
yield return [Key.Enter];
yield return [Key.Space];
}
}