public void DesignSurface_OnUnloading_Invoke_Success(EventArgs eventArgs) { var surface = new SubDesignSurface(); // No handler. surface.OnUnloading(eventArgs); // Handler. int callCount = 0; EventHandler handler = (sender, e) => { Assert.Equal(surface, sender); Assert.Same(eventArgs, e); callCount++; }; surface.Unloading += handler; surface.OnUnloading(eventArgs); Assert.Equal(1, callCount); // Should not call if the handler is removed. surface.Unloading -= handler; surface.OnUnloading(eventArgs); Assert.Equal(1, callCount); }
public void ServiceContainer_GetIExtenderProviderService_ReturnsExpected() { var surface = new SubDesignSurface(); ServiceContainer container = surface.ServiceContainer; Assert.IsAssignableFrom <IExtenderProviderService>(container.GetService(typeof(IExtenderProviderService))); }
public void DesignSurface_ServiceContainer_GetDisposed_ThrowsObjectDisposedException() { var surface = new SubDesignSurface(); surface.Dispose(); Assert.Throws <ObjectDisposedException>(() => surface.ServiceContainer); }
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_ServiceContainer_RemoveNullServiceType_ThrowsArgumentNullException() { var surface = new SubDesignSurface(); ServiceContainer container = surface.ServiceContainer; Assert.Throws <ArgumentNullException>("serviceType", () => container.RemoveService(null)); }
public void DesignSurface_ServiceContainer_GetFixedService_ReturnsExpected(Type serviceType) { var surface = new SubDesignSurface(); ServiceContainer container = surface.ServiceContainer; Assert.Same(surface.Host, container.GetService(serviceType)); }
public void DesignSurface_ServiceContainer_RemoveFixedService_ThrowsInvalidOperationException(Type serviceType) { var surface = new SubDesignSurface(); ServiceContainer container = surface.ServiceContainer; Assert.Throws <InvalidOperationException>(() => container.RemoveService(serviceType)); }
public void DesignSurface_ServiceContainer_GetInstanceTypeService_ReturnsExpected() { var surface = new SubDesignSurface(); ServiceContainer container = surface.ServiceContainer; Assert.Same(container, container.GetService(container.GetType())); }
public void DesignSurface_ServiceContainer_GetDesignSurfaceService_ReturnsExpected() { var surface = new SubDesignSurface(); ServiceContainer container = surface.ServiceContainer; Assert.Same(surface, container.GetService(typeof(DesignSurface))); }
public void DesignSurface_ServiceContainer_GetIReferenceService_ReturnsExpected() { var surface = new SubDesignSurface(); ServiceContainer container = surface.ServiceContainer; Assert.IsAssignableFrom <IReferenceService>(container.GetService(typeof(IReferenceService))); }
public void DesignSurface_ServiceContainer_GetITypeDescriptorFilterService_ReturnsExpected() { var surface = new SubDesignSurface(); ServiceContainer container = surface.ServiceContainer; Assert.IsAssignableFrom <ITypeDescriptorFilterService>(container.GetService(typeof(ITypeDescriptorFilterService))); }
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_ServiceContainer_Get_ReturnsSame() { var surface = new SubDesignSurface(); ServiceContainer container = surface.ServiceContainer; Assert.NotNull(container); Assert.Same(container, surface.ServiceContainer); }
public void DesignSurface_ServiceContainer_GetISelectionService_ReturnsExpected() { var surface = new SubDesignSurface(); ServiceContainer container = surface.ServiceContainer; ISelectionService service = Assert.IsAssignableFrom <ISelectionService>(container.GetService(typeof(ISelectionService))); Assert.Null(service.PrimarySelection); Assert.Equal(0, service.SelectionCount); }
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_ServiceContainer_RemoveNonFixedServiceType_ThrowsArgumentNullException(Type serviceType) { var surface = new SubDesignSurface(); ServiceContainer container = surface.ServiceContainer; Assert.NotNull(container.GetService(serviceType)); container.RemoveService(serviceType); Assert.Null(container.GetService(serviceType)); // Remove again. container.RemoveService(serviceType); Assert.Null(container.GetService(serviceType)); }
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_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_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_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_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_Ctor_IServiceProvider(IServiceProvider parentProvider) { var surface = new SubDesignSurface(parentProvider); Assert.NotNull(surface.ComponentContainer); Assert.Empty(surface.ComponentContainer.Components); Assert.False(surface.DtelLoading); Assert.False(surface.Host.CanReloadWithErrors); Assert.Same(surface.Host, surface.Host.Container); Assert.False(surface.Host.Loading); Assert.False(surface.Host.IgnoreErrorsDuringReload); Assert.False(surface.Host.InTransaction); Assert.False(((IDesignerHostTransactionState)surface.Host).IsClosingTransaction); Assert.Null(surface.Host.RootComponent); Assert.Null(surface.Host.RootComponentClassName); Assert.Null(surface.Host.TransactionDescription); Assert.False(surface.IsLoaded); Assert.Empty(surface.LoadErrors); Assert.NotNull(surface.ServiceContainer); Assert.Throws <InvalidOperationException>(() => surface.View); }
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()); }