Fixes #4167. Add Accepted event to View (#4452)

* Initial plan

* Add Accepted event to View and remove duplicate implementations

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Update RaiseAccepting to call RaiseAccepted and add comprehensive tests

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Fix code style violations - use explicit types and target-typed new

Co-authored-by: tig <585482+tig@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tig <585482+tig@users.noreply.github.com>
Co-authored-by: Tig <tig@users.noreply.github.com>
This commit is contained in:
Copilot
2025-12-06 09:36:32 -07:00
committed by GitHub
parent 5e3175cd9d
commit 7a8b6e4465
5 changed files with 166 additions and 108 deletions

View File

@@ -124,9 +124,124 @@ public class ViewCommandTests
Assert.Equal (0, view.OnAcceptedCount);
}
#endregion OnAccept/Accept tests
#region Accepted tests
[Fact]
public void Accepted_Event_Is_Raised_After_Accepting_When_Handled ()
{
View view = new ();
var acceptingInvoked = false;
var acceptedInvoked = false;
view.Accepting += (sender, e) =>
{
acceptingInvoked = true;
e.Handled = true;
};
view.Accepted += (sender, e) =>
{
acceptedInvoked = true;
Assert.True (acceptingInvoked); // Accepting should be raised first
};
bool? ret = view.InvokeCommand (Command.Accept);
Assert.True (ret);
Assert.True (acceptingInvoked);
Assert.True (acceptedInvoked);
}
[Fact]
public void Accepted_Event_Not_Raised_When_Accepting_Not_Handled ()
{
View view = new ();
var acceptingInvoked = false;
var acceptedInvoked = false;
view.Accepting += (sender, e) =>
{
acceptingInvoked = true;
e.Handled = false;
};
view.Accepted += (sender, e) =>
{
acceptedInvoked = true;
};
// When not handled, Accept bubbles to SuperView, so returns false (no superview)
bool? ret = view.InvokeCommand (Command.Accept);
Assert.False (ret);
Assert.True (acceptingInvoked);
Assert.False (acceptedInvoked); // Should not be invoked when not handled
}
[Fact]
public void Accepted_Event_Cannot_Be_Cancelled ()
{
View view = new ();
var acceptedInvoked = false;
view.Accepting += (sender, e) =>
{
e.Handled = true;
};
view.Accepted += (sender, e) =>
{
acceptedInvoked = true;
// Accepted event has Handled property but it doesn't affect flow
e.Handled = false;
};
bool? ret = view.InvokeCommand (Command.Accept);
Assert.True (ret);
Assert.True (acceptedInvoked);
}
[Fact]
public void OnAccepted_Called_When_Accepting_Handled ()
{
OnAcceptedTestView view = new ();
view.Accepting += (sender, e) =>
{
e.Handled = true;
};
view.InvokeCommand (Command.Accept);
Assert.Equal (1, view.OnAcceptedCallCount);
}
[Fact]
public void OnAccepted_Not_Called_When_Accepting_Not_Handled ()
{
OnAcceptedTestView view = new ();
view.Accepting += (sender, e) =>
{
e.Handled = false;
};
view.InvokeCommand (Command.Accept);
Assert.Equal (0, view.OnAcceptedCallCount);
}
private class OnAcceptedTestView : View
{
public int OnAcceptedCallCount { get; private set; }
protected override void OnAccepted (CommandEventArgs args)
{
OnAcceptedCallCount++;
base.OnAccepted (args);
}
}
#endregion Accepted tests
#region OnSelect/Select tests
[Theory]