public void Dispose_SiteEventHandler_InvokesEventHandlerAndRemovesSiteFromComponent() { bool calledDisposed = false; var site = new Site(); var component = new MarshalByValueComponent() { Site = site }; component.Disposed += (sender, e) => { Assert.Same(component, sender); Assert.Same(EventArgs.Empty, e); calledDisposed = true; }; Assert.False(calledDisposed); site.Container.Add(component); component.Dispose(); Assert.True(calledDisposed); Assert.Empty(site.Container.Components); // Call multiple times. component.Site = site; site.Container = null; calledDisposed = false; component.Dispose(); Assert.True(calledDisposed); }
public void Disposed_AddRemoveEventHandler_Success() { bool calledDisposedHandler = false; void Handler(object sender, EventArgs e) => calledDisposedHandler = true; var component = new MarshalByValueComponent(); component.Disposed += Handler; component.Disposed -= Handler; component.Dispose(); Assert.False(calledDisposedHandler); }