mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 16:59:35 +01:00
Beefed up unit tests
This commit is contained in:
@@ -25,14 +25,19 @@ public class OrientationTests
|
||||
|
||||
public bool CancelOnOrientationChanging { get; set; }
|
||||
|
||||
public bool OnOrientationChangingCalled { get; private set; }
|
||||
public bool OnOrientationChangedCalled { get; private set; }
|
||||
|
||||
public bool OnOrientationChanging (Orientation currentOrientation, Orientation newOrientation)
|
||||
{
|
||||
OnOrientationChangingCalled = true;
|
||||
// Custom logic before orientation changes
|
||||
return CancelOnOrientationChanging; // Return true to cancel the change
|
||||
}
|
||||
|
||||
public void OnOrientationChanged (Orientation oldOrientation, Orientation newOrientation)
|
||||
{
|
||||
OnOrientationChangedCalled = true;
|
||||
// Custom logic after orientation has changed
|
||||
}
|
||||
}
|
||||
@@ -87,4 +92,45 @@ public class OrientationTests
|
||||
Assert.False (orientationChanged, "OrientationChanged event was invoked despite cancellation.");
|
||||
Assert.Equal (Orientation.Vertical, customView.Orientation); // Assuming Vertical is the default orientation
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void OrientationChanging_VirtualMethodCalledBeforeEvent ()
|
||||
{
|
||||
// Arrange
|
||||
var radioGroup = new CustomView ();
|
||||
bool eventCalled = false;
|
||||
|
||||
radioGroup.OrientationChanging += (sender, e) =>
|
||||
{
|
||||
eventCalled = true;
|
||||
Assert.True (radioGroup.OnOrientationChangingCalled, "OnOrientationChanging was not called before the event.");
|
||||
};
|
||||
|
||||
// Act
|
||||
radioGroup.Orientation = Orientation.Horizontal;
|
||||
|
||||
// Assert
|
||||
Assert.True (eventCalled, "OrientationChanging event was not called.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OrientationChanged_VirtualMethodCalledBeforeEvent ()
|
||||
{
|
||||
// Arrange
|
||||
var radioGroup = new CustomView ();
|
||||
bool eventCalled = false;
|
||||
|
||||
radioGroup.OrientationChanged += (sender, e) =>
|
||||
{
|
||||
eventCalled = true;
|
||||
Assert.True (radioGroup.OnOrientationChangedCalled, "OnOrientationChanged was not called before the event.");
|
||||
};
|
||||
|
||||
// Act
|
||||
radioGroup.Orientation = Orientation.Horizontal;
|
||||
|
||||
// Assert
|
||||
Assert.True (eventCalled, "OrientationChanged event was not called.");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user