public void OnMainFormClosed_InvokeWithThreadExit_CallsHandler(object sender, EventArgs e) { var context = new SubApplicationContext(); int callCount = 0; EventHandler handler = (actualSender, actualE) => { Assert.Same(context, actualSender); Assert.Same(EventArgs.Empty, actualE); callCount++; }; context.ThreadExit += handler; // Call with handler. context.OnMainFormClosed(sender, e); Assert.Equal(1, callCount); // Call again. context.OnMainFormClosed(sender, e); Assert.Equal(2, callCount); // Remove handler. context.ThreadExit -= handler; context.OnMainFormClosed(sender, e); Assert.Equal(2, callCount); }
public void ExitThreadCore_InvokeWithThreadExit_CallsHandler() { var context = new SubApplicationContext(); int callCount = 0; EventHandler handler = (sender, e) => { Assert.Same(context, sender); Assert.Same(EventArgs.Empty, e); callCount++; }; context.ThreadExit += handler; // Call with handler. context.ExitThreadCore(); Assert.Equal(1, callCount); // Call again. context.ExitThreadCore(); Assert.Equal(2, callCount); // Remove handler. context.ThreadExit -= handler; context.ExitThreadCore(); Assert.Equal(2, callCount); }
public void Dispose_InvokeDisposingNoForm_Nop(bool disposing) { using var context = new SubApplicationContext(); context.Dispose(disposing); Assert.Null(context.MainForm); context.Dispose(disposing); Assert.Null(context.MainForm); }
public void Dispose_InvokeNotDisposingWithForm_Nop() { using var mainForm = new Form(); using var context = new SubApplicationContext(mainForm); context.Dispose(false); Assert.Same(mainForm, context.MainForm); Assert.False(mainForm.IsDisposed); context.Dispose(false); Assert.Same(mainForm, context.MainForm); Assert.False(mainForm.IsDisposed); }
public void Dispose_InvokeDisposingWithForm_Success() { using var mainForm = new Form(); using var context = new SubApplicationContext(mainForm); context.Dispose(true); Assert.Null(context.MainForm); Assert.True(mainForm.IsDisposed); context.Dispose(true); Assert.Null(context.MainForm); Assert.True(mainForm.IsDisposed); }