public void DesignSurface_Dispose_HasHost_ThrowsInvalidOperationException() { var surface = new SubDesignSurface(); IDesignerLoaderHost2 host = surface.Host; var mockLoader = new Mock <DesignerLoader>(MockBehavior.Strict); mockLoader .Setup(l => l.BeginLoad(host)) .Verifiable(); surface.BeginLoad(mockLoader.Object); Assert.Throws <InvalidOperationException>(() => surface.Dispose()); // Should not throw again. surface.Dispose(); }
public void DesignSurface_ServiceContainer_GetDisposed_ThrowsObjectDisposedException() { var surface = new SubDesignSurface(); surface.Dispose(); Assert.Throws <ObjectDisposedException>(() => surface.ServiceContainer); }
public void DesignSurface_BeginLoad_DisposeInBeginLoadThrowsException_DoesCallFlush() { var surface = new SubDesignSurface(); int loadingCallCount = 0; surface.Loading += (sender, e) => { Assert.Same(surface, sender); Assert.Same(EventArgs.Empty, e); loadingCallCount++; }; int loadedCallCount = 0; surface.Loaded += (sender, e) => loadedCallCount++; int unloadingCallCount = 0; surface.Unloading += (sender, e) => unloadingCallCount++; int unloadedCallCount = 0; surface.Unloaded += (sender, e) => unloadedCallCount++; int flushedCallCount = 0; surface.Flushed += (sender, e) => flushedCallCount++; var mockLoader = new Mock <DesignerLoader>(MockBehavior.Strict); IDesignerLoaderHost2 host = surface.Host; mockLoader .Setup(l => l.BeginLoad(host)) .Callback(() => { // Catch the InvalidOperationException thrown. try { surface.Dispose(); } catch { } throw new Exception(); }); surface.BeginLoad(mockLoader.Object); Assert.Equal(1, loadingCallCount); Assert.Equal(0, loadedCallCount); Assert.Equal(0, unloadingCallCount); Assert.Equal(0, unloadedCallCount); Assert.Equal(0, flushedCallCount); mockLoader.Verify(l => l.BeginLoad(host), Times.Once()); }
public void DesignSurface_BeginLoad_DisposeInLoading_DoesCallFlush() { var surface = new SubDesignSurface(); int loadingCallCount = 0; surface.Loading += (sender, e) => { // Catch the InvalidOperationException thrown. try { surface.Dispose(); } catch { } Assert.Same(surface, sender); Assert.Same(EventArgs.Empty, e); loadingCallCount++; }; int loadedCallCount = 0; surface.Loaded += (sender, e) => loadedCallCount++; int unloadingCallCount = 0; surface.Unloading += (sender, e) => unloadingCallCount++; int unloadedCallCount = 0; surface.Unloaded += (sender, e) => unloadedCallCount++; int flushedCallCount = 0; surface.Flushed += (sender, e) => flushedCallCount++; var mockLoader = new Mock <DesignerLoader>(MockBehavior.Strict); surface.BeginLoad(mockLoader.Object); Assert.Equal(1, loadingCallCount); Assert.Equal(0, loadedCallCount); Assert.Equal(0, unloadingCallCount); Assert.Equal(0, unloadedCallCount); Assert.Equal(0, flushedCallCount); }