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_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_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_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_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_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_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()); }
protected virtual void OnEndLoad(bool successful, ICollection errors) { successful = (successful && ((errors == null) || (errors.Count == 0))) && ((this._serializationManager.Errors == null) || (this._serializationManager.Errors.Count == 0)); try { this._state[StateLoaded] = true; IDesignerLoaderHost2 host = this.GetService(typeof(IDesignerLoaderHost2)) as IDesignerLoaderHost2; if (!successful && ((host == null) || !host.IgnoreErrorsDuringReload)) { if (host != null) { host.CanReloadWithErrors = this.LoaderHost.RootComponent != null; } this.UnloadDocument(); } else { successful = true; } if (errors != null) { foreach (object obj2 in errors) { this._serializationManager.Errors.Add(obj2); } } errors = this._serializationManager.Errors; } finally { this._serializationSession.Dispose(); this._serializationSession = null; } if (successful) { IComponentChangeService service = (IComponentChangeService)this.GetService(typeof(IComponentChangeService)); if (service != null) { service.ComponentAdded += new ComponentEventHandler(this.OnComponentAdded); service.ComponentAdding += new ComponentEventHandler(this.OnComponentAdding); service.ComponentRemoving += new ComponentEventHandler(this.OnComponentRemoving); service.ComponentRemoved += new ComponentEventHandler(this.OnComponentRemoved); service.ComponentChanged += new ComponentChangedEventHandler(this.OnComponentChanged); service.ComponentChanging += new ComponentChangingEventHandler(this.OnComponentChanging); service.ComponentRename += new ComponentRenameEventHandler(this.OnComponentRename); } this.EnableComponentNotification(true); } this.LoaderHost.EndLoad(this._baseComponentClassName, successful, errors); if ((this._state[StateModifyIfErrors] && (errors != null)) && (errors.Count > 0)) { try { this.OnModifying(); this.Modified = true; } catch (CheckoutException exception) { if (exception != CheckoutException.Canceled) { throw; } } } }