mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
- Add _isInitialized flag to prevent multiple event subscriptions - Skip re-initialization in FrmOptions_Load when form is reused - Properly clean up Application.Idle handler in FormClosing - Add test to verify form can be shown/hidden multiple times Co-authored-by: Kvarkas <3611964+Kvarkas@users.noreply.github.com>
64 lines
2.1 KiB
C#
64 lines
2.1 KiB
C#
using NUnit.Framework;
|
|
using System.Threading;
|
|
using System.Windows.Forms;
|
|
using mRemoteNGTests.TestHelpers;
|
|
|
|
namespace mRemoteNGTests.UI.Forms
|
|
{
|
|
[TestFixture]
|
|
[Apartment(ApartmentState.STA)]
|
|
public class OptionsFormTests : OptionsFormSetupAndTeardown
|
|
{
|
|
[Test]
|
|
public void ClickingCloseButtonClosesTheForm()
|
|
{
|
|
bool eventFired = false;
|
|
_optionsForm.FormClosed += (o, e) => eventFired = true;
|
|
Button cancelButton = _optionsForm.FindControl<Button>("btnCancel");
|
|
cancelButton.PerformClick();
|
|
Assert.That(eventFired, Is.True);
|
|
}
|
|
|
|
[Test]
|
|
public void ClickingOKButtonSetsDialogResult()
|
|
{
|
|
Button cancelButton = _optionsForm.FindControl<Button>("btnOK");
|
|
cancelButton.PerformClick();
|
|
Assert.That(_optionsForm.DialogResult, Is.EqualTo(DialogResult.OK));
|
|
}
|
|
|
|
[Test]
|
|
public void ListViewContainsOptionsPages()
|
|
{
|
|
ListViewTester listViewTester = new("lstOptionPages", _optionsForm);
|
|
Assert.That(listViewTester.Items.Count, Is.EqualTo(12));
|
|
}
|
|
|
|
[Test]
|
|
public void FormCanBeHiddenAndShownMultipleTimes()
|
|
{
|
|
// First show (already done in Setup)
|
|
Assert.That(_optionsForm.Visible, Is.True);
|
|
|
|
// Hide the form
|
|
_optionsForm.Hide();
|
|
Assert.That(_optionsForm.Visible, Is.False);
|
|
|
|
// Show it again
|
|
_optionsForm.Show();
|
|
Assert.That(_optionsForm.Visible, Is.True);
|
|
|
|
// Verify pages are still loaded correctly
|
|
ListViewTester listViewTester = new("lstOptionPages", _optionsForm);
|
|
Assert.That(listViewTester.Items.Count, Is.EqualTo(12));
|
|
|
|
// Hide and show one more time
|
|
_optionsForm.Hide();
|
|
_optionsForm.Show();
|
|
Assert.That(_optionsForm.Visible, Is.True);
|
|
|
|
// Verify pages are still there
|
|
Assert.That(listViewTester.Items.Count, Is.EqualTo(12));
|
|
}
|
|
}
|
|
} |