public void DesignSurface_BeginLoad_InvokeWithLoading_CallsHandler() { var surface = new SubDesignSurface(); IDesignerLoaderHost2 host = surface.Host; 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); mockLoader .Setup(l => l.BeginLoad(host)) .Verifiable(); surface.BeginLoad(mockLoader.Object); Assert.False(surface.IsLoaded); Assert.Empty(surface.LoadErrors); Assert.True(surface.Host.Loading); 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()); // Begin again. surface.BeginLoad(mockLoader.Object); Assert.False(surface.IsLoaded); Assert.Empty(surface.LoadErrors); Assert.True(surface.Host.Loading); Assert.Equal(2, loadingCallCount); Assert.Equal(0, loadedCallCount); Assert.Equal(0, unloadingCallCount); Assert.Equal(0, unloadedCallCount); Assert.Equal(0, flushedCallCount); mockLoader.Verify(l => l.BeginLoad(host), Times.Exactly(2)); }
public void DesignSurface_BeginLoad_AlreadyCalled_ThrowsInvalidOperationException() { var surface = new SubDesignSurface(); IDesignerLoaderHost2 host = surface.Host; var mockLoader = new Mock <DesignerLoader>(MockBehavior.Strict); mockLoader .Setup(l => l.BeginLoad(host)); surface.BeginLoad(mockLoader.Object); var otherMockLoader = new Mock <DesignerLoader>(MockBehavior.Strict); otherMockLoader .Setup(l => l.BeginLoad(host)); surface.BeginLoad(mockLoader.Object); Assert.Throws <InvalidOperationException>(() => surface.BeginLoad(otherMockLoader.Object)); }
public void DesignSurface_BeginLoad_InvokeWithIDesignerEventServiceWithActivated_DoesNotCallHandler() { var mockDesignerEventService = new Mock <IDesignerEventService>(MockBehavior.Strict); var mockServiceProvider = new Mock <IServiceProvider>(MockBehavior.Strict); mockServiceProvider .Setup(p => p.GetService(typeof(IDesignerEventService))) .Returns(mockDesignerEventService.Object); var surface = new SubDesignSurface(mockServiceProvider.Object); IDesignerLoaderHost2 host = surface.Host; int callCount = 0; host.Activated += (sender, e) => { Assert.Same(host, sender); Assert.Same(EventArgs.Empty, e); callCount++; }; var mockLoader = new Mock <DesignerLoader>(MockBehavior.Strict); mockLoader .Setup(l => l.BeginLoad(host)) .Verifiable(); surface.BeginLoad(mockLoader.Object); Assert.Equal(0, callCount); mockLoader.Verify(l => l.BeginLoad(host), Times.Once()); }
public void DesignSurface_BeginLoad_ThrowsExceptionWithoutMessage_SetsLoadErrors(string message) { var mockException = new Mock <Exception>(MockBehavior.Strict); mockException .Setup(e => e.Message) .Returns(message); mockException .Setup(e => e.ToString()) .Returns("ExceptionText"); var surface = new SubDesignSurface(); IDesignerLoaderHost2 host = surface.Host; var mockLoader = new Mock <DesignerLoader>(MockBehavior.Strict); mockLoader .Setup(l => l.BeginLoad(host)) .Throws(mockException.Object); mockLoader .Setup(l => l.Loading) .Returns(false); surface.BeginLoad(mockLoader.Object); Assert.False(surface.IsLoaded); Exception error = Assert.IsType <Exception>(Assert.Single(surface.LoadErrors)); Assert.Contains("ExceptionText", error.Message); Assert.False(surface.Host.Loading); }
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_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_BeginLoad_Invoke_Success(IServiceProvider parentProvider) { var surface = new SubDesignSurface(parentProvider); IDesignerLoaderHost2 host = surface.Host; var mockLoader = new Mock <DesignerLoader>(MockBehavior.Strict); mockLoader .Setup(l => l.BeginLoad(host)) .Verifiable(); surface.BeginLoad(mockLoader.Object); Assert.False(surface.IsLoaded); Assert.Empty(surface.LoadErrors); Assert.True(surface.Host.Loading); mockLoader.Verify(l => l.BeginLoad(host), Times.Once()); }
public void DesignSurface_BeginLoad_ThrowsTargetInvocationException_SetsLoadErrors() { var exception = new Exception(); var surface = new SubDesignSurface(); IDesignerLoaderHost2 host = surface.Host; var mockLoader = new Mock <DesignerLoader>(MockBehavior.Strict); mockLoader .Setup(l => l.BeginLoad(host)) .Throws(new TargetInvocationException(exception)); mockLoader .Setup(l => l.Loading) .Returns(false); surface.BeginLoad(mockLoader.Object); Assert.False(surface.IsLoaded); Assert.Same(exception, Assert.Single(surface.LoadErrors)); Assert.False(surface.Host.Loading); }
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); }
public void DesignSurface_Flush_InvokeWithHostWithLoader_CallsLoaderFlush() { var surface = new SubDesignSurface(); IDesignerLoaderHost2 host = surface.Host; var mockLoader = new Mock <DesignerLoader>(MockBehavior.Strict); mockLoader .Setup(l => l.BeginLoad(host)); mockLoader .Setup(l => l.Flush()) .Verifiable(); surface.BeginLoad(mockLoader.Object); surface.Flush(); mockLoader.Verify(l => l.Flush(), Times.Once()); // Flush again. surface.Flush(); mockLoader.Verify(l => l.Flush(), Times.Exactly(2)); }
public void DesignSurface_BeginLoad_InvokeWithoutIDesignerEventServiceWithActivated_CallsHandler() { var surface = new SubDesignSurface(); int callCount = 0; IDesignerLoaderHost2 host = surface.Host; host.Activated += (sender, e) => { Assert.Same(host, sender); Assert.Same(EventArgs.Empty, e); callCount++; }; var mockLoader = new Mock <DesignerLoader>(MockBehavior.Strict); mockLoader .Setup(l => l.BeginLoad(host)) .Verifiable(); surface.BeginLoad(mockLoader.Object); Assert.Equal(1, callCount); mockLoader.Verify(l => l.BeginLoad(host), Times.Once()); }