public void GetViewInfosFor_SingleDirectMatch_ReturnSingleMatchingViewInfo() { // Setup var mocks = new MockRepository(); var dialogParent = mocks.Stub <IWin32Window>(); var viewHost = mocks.StrictMock <IViewHost>(); viewHost.Stub(vh => vh.ViewClosed += null).IgnoreArguments(); viewHost.Stub(vh => vh.ViewClosed -= null).IgnoreArguments(); mocks.ReplayAll(); var viewInfos = new ViewInfo[] { new ViewInfo <A, TestView>(), new ViewInfo <int, TestView>(), new ViewInfo <string, TestView>() }; using (var documentViewController = new DocumentViewController(viewHost, viewInfos, dialogParent)) { const int data = default(int); // Call ViewInfo[] matchedViewInfos = documentViewController.GetViewInfosFor(data).ToArray(); // Assert CollectionAssert.AreEqual(new[] { viewInfos[1] }, matchedViewInfos); } mocks.VerifyAll(); }
public void GetViewInfosFor_NoViewInfosRegistered_ReturnEmpty() { // Setup var mocks = new MockRepository(); var dialogParent = mocks.Stub <IWin32Window>(); var viewHost = mocks.StrictMock <IViewHost>(); viewHost.Stub(vh => vh.ViewClosed += null).IgnoreArguments(); viewHost.Stub(vh => vh.ViewClosed -= null).IgnoreArguments(); mocks.ReplayAll(); using (var documentViewController = new DocumentViewController(viewHost, Enumerable.Empty <ViewInfo>(), dialogParent)) { var data = new object(); // Call IEnumerable <ViewInfo> matchedViewInfos = documentViewController.GetViewInfosFor(data); // Assert CollectionAssert.IsEmpty(matchedViewInfos); } mocks.VerifyAll(); }
public void OpenViewForData_NoViewInfoRegistered_ReturnFalse(bool forceShowDialog) { // Setup var mocks = new MockRepository(); var dialogParent = mocks.Stub <IWin32Window>(); var viewHost = mocks.StrictMock <IViewHost>(); viewHost.Stub(vh => vh.ViewClosed += null).IgnoreArguments(); viewHost.Stub(vh => vh.ViewClosed -= null).IgnoreArguments(); mocks.ReplayAll(); var viewInfos = new ViewInfo[0]; using (var documentViewController = new DocumentViewController(viewHost, viewInfos, dialogParent)) { // Call bool result = documentViewController.OpenViewForData(new object(), forceShowDialog); // Assert Assert.IsFalse(result); } mocks.VerifyAll(); }
void ResetMainWindow() { Window.MakeKeyAndOrderFront(Self); var controller = Window.ContentViewController as NSTabViewController; controller.SelectedTabViewItemIndex = 0; DocumentViewController.ClearAllProgress(); }
public void OpenViewForData_SelectDifferentDefaultViewAndClickOkInOpenedDialog_ReturnTrueViewAddedToViewHostAndDefaultViewTypesUpdated() { // Setup TestView view = null; var mocks = new MockRepository(); var dialogParent = mocks.Stub <IWin32Window>(); var viewHost = mocks.StrictMock <IViewHost>(); viewHost.Stub(vh => vh.ViewClosed += null).IgnoreArguments(); viewHost.Stub(vh => vh.ViewClosed -= null).IgnoreArguments(); viewHost.Stub(vh => vh.DocumentViews).Return(new IView[0]); viewHost.Expect(vm => vm.AddDocumentView(Arg <TestView> .Is.NotNull, Arg <string> .Is.Anything, Arg <string> .Is.Null, Arg <FontFamily> .Is.Null)) .WhenCalled(invocation => { view = invocation.Arguments[0] as TestView; }); mocks.ReplayAll(); var data = new object(); var viewInfos = new ViewInfo[] { new ViewInfo <object, TestViewDerivative>(), new ViewInfo <object, TestView>() }; using (var documentViewController = new DocumentViewController(viewHost, viewInfos, dialogParent)) { documentViewController.DefaultViewTypes[typeof(object)] = typeof(TestViewDerivative); DialogBoxHandler = (name, wnd) => { var buttonOk = new ControlTester("buttonOk"); var listBox = new ListBoxTester("listBox"); var checkBox = new CheckBoxTester("checkBoxDefault"); listBox.SetSelected(0, true); checkBox.Check(); buttonOk.Click(); }; // Call bool result = documentViewController.OpenViewForData(data, true); // Assert Assert.IsTrue(result); Assert.AreEqual(data, view.Data); Assert.IsEmpty(view.Text); Assert.IsTrue(documentViewController.DefaultViewTypes.ContainsKey(typeof(object))); Assert.AreEqual(documentViewController.DefaultViewTypes[typeof(object)], typeof(TestView)); } mocks.VerifyAll(); }
public void CloseAllViews_Always_RemoveViews() { // Setup var data1 = new A(); var data2 = new InheritedFromA(); var mocks = new MockRepository(); var dialogParent = mocks.Stub <IWin32Window>(); var viewHost = mocks.StrictMock <IViewHost>(); var documentViews = new List <IView>(); viewHost.Stub(vh => vh.ViewClosed += null).IgnoreArguments(); viewHost.Stub(vh => vh.ViewClosed -= null).IgnoreArguments(); viewHost.Stub(vh => vh.DocumentViews).Return(documentViews); viewHost.Expect(vm => vm.AddDocumentView(Arg <TestView> .Is.NotNull, Arg <string> .Is.Anything, Arg <string> .Is.Null, Arg <FontFamily> .Is.Null)) .WhenCalled(invocation => { documentViews.Add(invocation.Arguments[0] as TestView); }) .Repeat.Twice(); viewHost.Expect(vh => vh.Remove(Arg <TestView> .Is.NotNull)) .WhenCalled(invocation => { documentViews.Remove(invocation.Arguments[0] as TestView); }) .Repeat.Twice(); mocks.ReplayAll(); var viewInfos = new ViewInfo[] { new ViewInfo <A, TestView>(), new ViewInfo <InheritedFromA, TestViewDerivative>() }; using (var documentViewController = new DocumentViewController(viewHost, viewInfos, dialogParent)) { documentViewController.OpenViewForData(data1); documentViewController.OpenViewForData(data2); // Call documentViewController.CloseAllViews(); } // Assert CollectionAssert.IsEmpty(documentViews); mocks.VerifyAll(); }
public void OpenViewForData_ClickOkInOpenedDialog_ReturnTrueAndViewAddedToViewHost() { // Setup TestView view = null; var mocks = new MockRepository(); var dialogParent = mocks.Stub <IWin32Window>(); var viewHost = mocks.StrictMock <IViewHost>(); viewHost.Stub(vh => vh.ViewClosed += null).IgnoreArguments(); viewHost.Stub(vh => vh.ViewClosed -= null).IgnoreArguments(); viewHost.Stub(vh => vh.DocumentViews).Return(new IView[0]); viewHost.Expect(vm => vm.AddDocumentView(Arg <TestView> .Is.NotNull, Arg <string> .Is.Anything, Arg <string> .Is.Null, Arg <FontFamily> .Is.Null)) .WhenCalled(invocation => { view = invocation.Arguments[0] as TestView; }); mocks.ReplayAll(); var data = new object(); var viewInfos = new ViewInfo[] { new ViewInfo <object, TestViewDerivative>(), new ViewInfo <object, TestView>() }; using (var documentViewController = new DocumentViewController(viewHost, viewInfos, dialogParent)) { DialogBoxHandler = (name, wnd) => { var buttonOk = new ControlTester("buttonOk"); buttonOk.Click(); }; // Call bool result = documentViewController.OpenViewForData(data); // Assert Assert.IsTrue(result); Assert.AreEqual(data, view.Data); Assert.IsEmpty(view.Text); } mocks.VerifyAll(); }
public void OpenViewForData_DataHasMultipleSingleMatches_UseAdditionalDataCheckAndReturnTrueAndAddToViewHost() { // Setup TestViewDerivative view = null; var mocks = new MockRepository(); var dialogParent = mocks.Stub <IWin32Window>(); var viewHost = mocks.StrictMock <IViewHost>(); viewHost.Stub(vh => vh.ViewClosed += null).IgnoreArguments(); viewHost.Stub(vh => vh.ViewClosed -= null).IgnoreArguments(); viewHost.Stub(vh => vh.DocumentViews).Return(new IView[0]); viewHost.Expect(vm => vm.AddDocumentView(Arg <TestViewDerivative> .Is.NotNull, Arg <string> .Is.Anything, Arg <string> .Is.Null, Arg <FontFamily> .Is.Null)) .WhenCalled(invocation => { view = invocation.Arguments[0] as TestViewDerivative; }); mocks.ReplayAll(); var data = new object(); var viewInfos = new ViewInfo[] { new ViewInfo <object, TestViewDerivative> { AdditionalDataCheck = o => true }, new ViewInfo <object, TestView> { AdditionalDataCheck = o => false } }; using (var documentViewController = new DocumentViewController(viewHost, viewInfos, dialogParent)) { // Call bool result = documentViewController.OpenViewForData(data); // Assert Assert.IsTrue(result); Assert.AreEqual(data, view.Data); Assert.IsEmpty(view.Text); } mocks.VerifyAll(); }
public void OpenViewForData_ViewInfosForInheritedData_ResolveToMostSpecializedForDataAndReturnTrueAndAddToViewHost() { // Setup TestView view = null; var mocks = new MockRepository(); var dialogParent = mocks.Stub <IWin32Window>(); var viewHost = mocks.StrictMock <IViewHost>(); viewHost.Stub(vh => vh.ViewClosed += null).IgnoreArguments(); viewHost.Stub(vh => vh.ViewClosed -= null).IgnoreArguments(); viewHost.Stub(vh => vh.DocumentViews).Return(new IView[0]); viewHost.Expect(vm => vm.AddDocumentView(Arg <TestView> .Is.NotNull, Arg <string> .Is.Anything, Arg <string> .Is.Null, Arg <FontFamily> .Is.Null)) .WhenCalled(invocation => { view = invocation.Arguments[0] as TestView; }); mocks.ReplayAll(); var data = new A(); var viewInfos = new ViewInfo[] { new ViewInfo <InheritedFromA, TestViewDerivative>(), // Should not be matched as A does not inherit from InheritedFromA! new ViewInfo <A, TestView>() }; using (var documentViewController = new DocumentViewController(viewHost, viewInfos, dialogParent)) { // Call bool result = documentViewController.OpenViewForData(data); // Assert Assert.IsTrue(result); Assert.AreEqual(data, view.Data); Assert.IsEmpty(view.Text); } mocks.VerifyAll(); }
public void GetViewInfosFor_ViewInfosWithAdditionalDataCheck_ReturnMatchesWithAdditionalDataCheckTrue() { // Setup var mocks = new MockRepository(); var dialogParent = mocks.Stub <IWin32Window>(); var viewHost = mocks.StrictMock <IViewHost>(); viewHost.Stub(vh => vh.ViewClosed += null).IgnoreArguments(); viewHost.Stub(vh => vh.ViewClosed -= null).IgnoreArguments(); mocks.ReplayAll(); var viewInfos = new ViewInfo[] { new ViewInfo <A, TestView> { AdditionalDataCheck = a => true }, new ViewInfo <InheritedFromA, TestView>(), new ViewInfo <object, TestView> { AdditionalDataCheck = o => false } }; using (var documentViewController = new DocumentViewController(viewHost, viewInfos, dialogParent)) { var data = new InheritedFromA(); // Call ViewInfo[] matchedViewInfos = documentViewController.GetViewInfosFor(data).ToArray(); // Assert ViewInfo[] expected = { viewInfos[0], viewInfos[1] }; CollectionAssert.AreEqual(expected, matchedViewInfos); } mocks.VerifyAll(); }
public void CloseAllViewsFor_DataIsNull_DoNothing() { // Setup var data1 = new A(); var data2 = new InheritedFromA(); var testView = new TestView { Data = data1 }; var testViewDerivative = new TestViewDerivative { Data = data2 }; var mocks = new MockRepository(); var dialogParent = mocks.Stub <IWin32Window>(); var viewHost = mocks.StrictMock <IViewHost>(); viewHost.Stub(vh => vh.ViewClosed += null).IgnoreArguments(); viewHost.Stub(vh => vh.ViewClosed -= null).IgnoreArguments(); viewHost.Stub(vh => vh.DocumentViews).Return(new[] { testView, testViewDerivative }); mocks.ReplayAll(); var viewInfos = new ViewInfo[] { new ViewInfo <A, TestView>(), new ViewInfo <InheritedFromA, TestViewDerivative>() }; using (var documentViewController = new DocumentViewController(viewHost, viewInfos, dialogParent)) { // Call documentViewController.CloseAllViewsFor(null); } // Assert mocks.VerifyAll(); }
public void OpenViewForData_ClickCancelInOpenedDialog_ReturnFalseAndNoViewAddedToViewHost() { // Setup var mocks = new MockRepository(); var dialogParent = mocks.Stub <IWin32Window>(); var viewHost = mocks.StrictMock <IViewHost>(); viewHost.Stub(vh => vh.ViewClosed += null).IgnoreArguments(); viewHost.Stub(vh => vh.ViewClosed -= null).IgnoreArguments(); viewHost.Stub(vh => vh.DocumentViews).Return(new IView[0]); mocks.ReplayAll(); var data = new object(); var viewInfos = new ViewInfo[] { new ViewInfo <object, TestViewDerivative>(), new ViewInfo <object, TestView>() }; using (var documentViewController = new DocumentViewController(viewHost, viewInfos, dialogParent)) { DialogBoxHandler = (name, wnd) => { var buttonCancel = new ControlTester("buttonCancel"); buttonCancel.Click(); }; // Call bool result = documentViewController.OpenViewForData(data); // Assert Assert.IsFalse(result); } mocks.VerifyAll(); }
public void OpenViewForData_OpeningViewForAlreadyOpenedButInactiveView_ActivateDocumentView() { // Setup var viewList = new List <IView>(); var data = new object(); var mocks = new MockRepository(); var dialogParent = mocks.Stub <IWin32Window>(); var viewHost = mocks.StrictMock <IViewHost>(); viewHost.Stub(vh => vh.ViewClosed += null).IgnoreArguments(); viewHost.Stub(vh => vh.ViewClosed -= null).IgnoreArguments(); viewHost.Stub(vh => vh.DocumentViews).Return(viewList); viewHost.Expect(vm => vm.AddDocumentView(Arg <TestView> .Is.NotNull, Arg <string> .Is.Anything, Arg <string> .Is.Null, Arg <FontFamily> .Is.Null)) .WhenCalled(invocation => viewList.Add(invocation.Arguments[0] as TestView)); viewHost.Expect(vh => vh.BringToFront(Arg <TestView> .Matches(c => c == viewList.First()))); mocks.ReplayAll(); var viewInfos = new ViewInfo[] { new ViewInfo <object, TestView>() }; using (var documentViewController = new DocumentViewController(viewHost, viewInfos, dialogParent)) { // Open view documentViewController.OpenViewForData(data); // Call documentViewController.OpenViewForData(data); } // Assert mocks.VerifyAll(); }
public void OpenViewForData_OpenSameViewForTwoDifferentDataInstances_OpenTwoViews() { // Setup var data1 = new object(); var data2 = new object(); var mocks = new MockRepository(); var dialogParent = mocks.Stub <IWin32Window>(); var viewHost = mocks.StrictMock <IViewHost>(); viewHost.Stub(vh => vh.ViewClosed += null).IgnoreArguments(); viewHost.Stub(vh => vh.ViewClosed -= null).IgnoreArguments(); viewHost.Stub(vh => vh.DocumentViews).Return(new IView[0]); viewHost.Expect(vm => vm.AddDocumentView(Arg <TestView> .Matches(c => c.Data == data1), Arg <string> .Is.Anything, Arg <string> .Is.Null, Arg <FontFamily> .Is.Null)); viewHost.Expect(vm => vm.AddDocumentView(Arg <TestView> .Matches(c => c.Data == data2), Arg <string> .Is.Anything, Arg <string> .Is.Null, Arg <FontFamily> .Is.Null)); mocks.ReplayAll(); var viewInfos = new ViewInfo[] { new ViewInfo <object, TestView>() }; using (var documentViewController = new DocumentViewController(viewHost, viewInfos, dialogParent)) { // Call documentViewController.OpenViewForData(data1); documentViewController.OpenViewForData(data2); } // Assert mocks.VerifyAll(); }
private void InitializeWindows() { InitializeMainWindow(); ViewHost = mainWindow.ViewHost; ViewHost.ViewClosed += OnViewClosed; ViewHost.ActiveViewChanged += OnActiveViewChanged; DocumentViewController = new DocumentViewController(ViewHost, Plugins.SelectMany(p => p.GetViewInfos()), mainWindow); PropertyResolver = new PropertyResolver(Plugins.SelectMany(p => p.GetPropertyInfos()) .Concat(ChartPropertyInfoFactory.Create()) .Concat(MapPropertyInfoFactory.Create())); applicationFeatureCommands = new ApplicationFeatureCommandHandler(PropertyResolver, mainWindow); mainWindow.InitializeToolWindows(); foreach (StateInfo stateInfo in Plugins.SelectMany(pluginGui => pluginGui.GetStateInfos())) { stateInfoLookup[mainWindow.AddStateButton(stateInfo.Name, stateInfo.Symbol, stateInfo.FontFamily, stateInfo.GetRootData)] = stateInfo; } mainWindow.SubscribeToGui(); }
public void ParameteredConstructor_ExpectedValues() { // Setup var mocks = new MockRepository(); var dialogParent = mocks.Stub <IWin32Window>(); var viewHost = mocks.StrictMock <IViewHost>(); viewHost.Stub(vh => vh.ViewClosed += null).IgnoreArguments(); viewHost.Stub(vh => vh.ViewClosed -= null).IgnoreArguments(); mocks.ReplayAll(); // Call using (var documentViewController = new DocumentViewController(viewHost, Enumerable.Empty <ViewInfo>(), dialogParent)) { // Assert Assert.IsInstanceOf <IDocumentViewController>(documentViewController); CollectionAssert.IsEmpty(documentViewController.DefaultViewTypes); } mocks.VerifyAll(); }
/// <summary> /// Opens view assotiated with row /// </summary> private void OpenDocument(int rowId) { var docViewController = new DocumentViewController(PDFFile.PDFFiles[rowId].Id, PDFFile.PDFFiles[rowId].Name, PDFFile.PDFFiles[rowId].FilePath); _Controller.NavigationController.PushViewController(docViewController, true); }
protected virtual void Dispose(bool disposing) { if (disposing) { projectObserver.Dispose(); foreach (PluginBase plugin in Plugins.ToArray()) { DeactivatePlugin(plugin); } isExiting = true; mainWindow.UnsubscribeFromGui(); Selection = null; if (ViewHost != null) { ViewHost.Dispose(); ViewHost.ViewClosed -= OnViewClosed; ViewHost.ActiveViewChanged -= OnActiveViewChanged; } if (currentSelectionProvider != null) { currentSelectionProvider.SelectionChanged -= OnSelectionChanged; } if (mainWindow != null && !mainWindow.IsWindowDisposed) { mainWindow.Dispose(); mainWindow = null; } if (DocumentViewController != null) { DocumentViewController.Dispose(); DocumentViewController = null; } MessageWindowLogAppender.Instance.MessageWindow = null; RemoveLogging(); } #region Prevent nasty Windows.Forms memory leak (keeps references to databinding objects / controls Assembly systemAssembly = typeof(Component).Assembly; Type reflectTypeDescriptionProviderType = systemAssembly.GetType("System.ComponentModel.ReflectTypeDescriptionProvider"); FieldInfo propertyCacheInfo = reflectTypeDescriptionProviderType.GetField("_propertyCache", BindingFlags.Static | BindingFlags.NonPublic); var propertyCache = (Hashtable)propertyCacheInfo?.GetValue(null); propertyCache?.Clear(); FieldInfo extendedPropertyCacheInfo = reflectTypeDescriptionProviderType.GetField( "_extendedPropertyCache", BindingFlags.Static | BindingFlags.NonPublic); var extendedPropertyCache = extendedPropertyCacheInfo?.GetValue(null) as Hashtable; extendedPropertyCache?.Clear(); FieldInfo eventCacheInfo = reflectTypeDescriptionProviderType.GetField("_eventCache", BindingFlags.Static | BindingFlags.NonPublic); var eventCache = eventCacheInfo?.GetValue(null) as Hashtable; eventCache?.Clear(); FieldInfo attributeCacheInfo = reflectTypeDescriptionProviderType.GetField("_attributeCache", BindingFlags.Static | BindingFlags.NonPublic); var attributeCache = attributeCacheInfo?.GetValue(null) as Hashtable; attributeCache?.Clear(); Type typeDescriptorType = systemAssembly.GetType("System.ComponentModel.TypeDescriptor"); FieldInfo providerTableInfo = typeDescriptorType.GetField("_providerTable", BindingFlags.Static | BindingFlags.NonPublic); var providerTable = providerTableInfo?.GetValue(null) as Hashtable; providerTable?.Clear(); FieldInfo providerTypeTableInfo = typeDescriptorType.GetField("_providerTypeTable", BindingFlags.Static | BindingFlags.NonPublic); var providerTypeTable = providerTypeTableInfo?.GetValue(null) as Hashtable; providerTypeTable?.Clear(); FieldInfo defaultProvidersInfo = typeDescriptorType.GetField("_defaultProviders", BindingFlags.Static | BindingFlags.NonPublic); var defaultProviders = defaultProvidersInfo?.GetValue(null) as Hashtable; defaultProviders?.Clear(); #endregion GC.Collect(); }
public void CloseAllViewsFor_DataDoesNotCorrespondToOpenedViewsButCloseForDataReturnsTrue_RemoveViews() { // Setup var data1 = new A(); var data2 = new InheritedFromA(); var unusedViewData = new object(); var mocks = new MockRepository(); var dialogParent = mocks.Stub <IWin32Window>(); var viewHost = mocks.StrictMock <IViewHost>(); var documentViews = new List <IView>(); viewHost.Stub(vh => vh.ViewClosed += null).IgnoreArguments(); viewHost.Stub(vh => vh.ViewClosed -= null).IgnoreArguments(); viewHost.Stub(vh => vh.DocumentViews).Return(documentViews); viewHost.Expect(vm => vm.AddDocumentView(Arg <TestView> .Is.NotNull, Arg <string> .Is.Anything, Arg <string> .Is.Null, Arg <FontFamily> .Is.Null)) .WhenCalled(invocation => { documentViews.Add(invocation.Arguments[0] as TestView); }) .Repeat.Twice(); viewHost.Expect(vh => vh.Remove(Arg <TestView> .Is.NotNull)) .WhenCalled(invocation => { documentViews.Remove(invocation.Arguments[0] as TestView); }) .Repeat.Twice(); mocks.ReplayAll(); var viewInfos = new ViewInfo[] { new ViewInfo <A, TestView> { CloseForData = (view, o) => { Assert.IsInstanceOf <TestView>(view); Assert.AreSame(data1, view.Data); Assert.AreSame(unusedViewData, o); return(true); } }, new ViewInfo <InheritedFromA, TestViewDerivative> { CloseForData = (view, o) => { Assert.IsInstanceOf <TestView>(view); Assert.AreSame(data2, view.Data); Assert.AreSame(unusedViewData, o); return(true); } } }; using (var documentViewController = new DocumentViewController(viewHost, viewInfos, dialogParent)) { documentViewController.OpenViewForData(data1); documentViewController.OpenViewForData(data2); // Call documentViewController.CloseAllViewsFor(unusedViewData); } // Assert mocks.VerifyAll(); }
public void CloseAllViewsFor_DataCorrespondsToOpenedViewWithViewInfoThatBindsToSameViews_RemoveCorrectView() { // Setup var data = new A(); var viewData = new object(); var mocks = new MockRepository(); var dialogParent = mocks.Stub <IWin32Window>(); var viewHost = mocks.StrictMock <IViewHost>(); var documentViews = new List <IView>(); viewHost.Stub(vh => vh.ViewClosed += null).IgnoreArguments(); viewHost.Stub(vh => vh.ViewClosed -= null).IgnoreArguments(); viewHost.Stub(vh => vh.DocumentViews).Return(documentViews); viewHost.Expect(vm => vm.AddDocumentView(Arg <TestView> .Is.NotNull, Arg <string> .Is.Anything, Arg <string> .Is.Null, Arg <FontFamily> .Is.Null)) .WhenCalled(invocation => { documentViews.Add(invocation.Arguments[0] as TestView); }); viewHost.Expect(vh => vh.Remove(Arg <TestView> .Is.NotNull)) .WhenCalled(invocation => { documentViews.Remove(invocation.Arguments[0] as TestView); }); mocks.ReplayAll(); var viewClosed = false; var viewInfos = new ViewInfo[] { new ViewInfo <B, object, TestView> { CloseForData = (v, o) => { Assert.Fail("Incorrect CloseForData called."); return(true); } }, new ViewInfo <A, object, TestView> { CloseForData = (v, o) => { if (o == viewData) { viewClosed = true; return(true); } return(false); } } }; using (var documentViewController = new DocumentViewController(viewHost, viewInfos, dialogParent)) { documentViewController.OpenViewForData(data); // Call documentViewController.CloseAllViewsFor(viewData); } // Assert Assert.IsTrue(viewClosed); mocks.VerifyAll(); }
public void OpenViewForData_DataHasSingleMatchOnBaseType_ReturnTrueAndAddToViewHost() { // Setup TestView view = null; var mocks = new MockRepository(); var dialogParent = mocks.Stub <IWin32Window>(); var viewHost = mocks.StrictMock <IViewHost>(); const string viewName = "<cool view name>"; viewHost.Stub(vh => vh.ViewClosed += null).IgnoreArguments(); viewHost.Stub(vh => vh.ViewClosed -= null).IgnoreArguments(); viewHost.Stub(vh => vh.DocumentViews).Return(new IView[0]); viewHost.Expect(vm => vm.AddDocumentView(Arg <TestView> .Is.NotNull, Arg <string> .Is.Equal(viewName), Arg <string> .Is.Null, Arg <FontFamily> .Is.Null)) .WhenCalled(invocation => { view = invocation.Arguments[0] as TestView; }); mocks.ReplayAll(); var data = new InheritedFromA(); var afterCreateCalled = false; var viewInfos = new ViewInfo[] { new ViewInfo <DocumentViewControllerTest, TestView>(), new ViewInfo <A, TestView> { AfterCreate = (v, o) => { Assert.IsInstanceOf <TestView>(v); Assert.AreSame(data, o); afterCreateCalled = true; }, GetViewName = (v, o) => { Assert.IsInstanceOf <TestView>(v); Assert.AreSame(data, o); return(viewName); } }, new ViewInfo <int, TestView>() }; using (var documentViewController = new DocumentViewController(viewHost, viewInfos, dialogParent)) { // Call bool result = documentViewController.OpenViewForData(data); // Assert Assert.IsTrue(result); Assert.AreEqual(data, view.Data); Assert.IsTrue(afterCreateCalled); } mocks.VerifyAll(); }