public void CanOpenViewFor_HasViewInfoDefinedForData_ReturnTrue(int numberOfViewDefinitions) { // Setup var viewObject = new object(); var viewInfos = new ViewInfo[numberOfViewDefinitions]; for (var i = 0; i < viewInfos.Length; i++) { viewInfos[i] = new ViewInfo(); } var mocks = new MockRepository(); var documentViewController = mocks.Stub <IDocumentViewController>(); documentViewController.Expect(r => r.GetViewInfosFor(viewObject)).Return(viewInfos); var viewController = mocks.Stub <IViewController>(); viewController.Stub(c => c.DocumentViewController).Return(documentViewController); var applicationSelection = mocks.Stub <IApplicationSelection>(); var pluginsHost = mocks.Stub <IPluginsHost>(); mocks.ReplayAll(); var commandHandler = new ViewCommandHandler(viewController, applicationSelection, pluginsHost); // Call bool hasViewDefinitionsForData = commandHandler.CanOpenViewFor(viewObject); // Assert Assert.IsTrue(hasViewDefinitionsForData); mocks.VerifyAll(); }
public void CanOpenViewFor_NoViewInfosForTarget_ReturnFalse() { // Setup var viewObject = new object(); var viewInfos = new ViewInfo[0]; var mocks = new MockRepository(); var documentViewController = mocks.Stub <IDocumentViewController>(); documentViewController.Expect(r => r.GetViewInfosFor(viewObject)).Return(viewInfos); var viewController = mocks.Stub <IViewController>(); viewController.Stub(c => c.DocumentViewController).Return(documentViewController); var applicationSelection = mocks.Stub <IApplicationSelection>(); var pluginsHost = mocks.Stub <IPluginsHost>(); mocks.ReplayAll(); var commandHandler = new ViewCommandHandler(viewController, applicationSelection, pluginsHost); // Call bool hasViewDefinitionsForData = commandHandler.CanOpenViewFor(viewObject); // Assert Assert.IsFalse(hasViewDefinitionsForData); mocks.VerifyAll(); }
public void OpenViewForSelection_OpenViewDialogForSelection() { // Setup var selectedObject = new object(); var mocks = new MockRepository(); var documentViewController = mocks.Stub <IDocumentViewController>(); documentViewController.Expect(r => r.OpenViewForData(selectedObject)).Return(true); var viewController = mocks.Stub <IViewController>(); viewController.Stub(c => c.DocumentViewController).Return(documentViewController); var applicationSelection = mocks.Stub <IApplicationSelection>(); applicationSelection.Selection = selectedObject; var pluginsHost = mocks.Stub <IPluginsHost>(); mocks.ReplayAll(); var commandHandler = new ViewCommandHandler(viewController, applicationSelection, pluginsHost); // Call commandHandler.OpenViewForSelection(); // Assert mocks.VerifyAll(); // Expect open view method is called }
/// <summary> /// Initializes a new instance of the <see cref="GuiCore"/> class. /// </summary> /// <param name="mainWindow">The main window.</param> /// <param name="projectStore">The project store.</param> /// <param name="projectMigrator">The project migrator.</param> /// <param name="projectFactory">The project factory.</param> /// <param name="fixedSettings">The fixed settings.</param> /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception> public GuiCore(IMainWindow mainWindow, IStoreProject projectStore, IMigrateProject projectMigrator, IProjectFactory projectFactory, GuiCoreSettings fixedSettings) { if (mainWindow == null) { throw new ArgumentNullException(nameof(mainWindow)); } if (projectStore == null) { throw new ArgumentNullException(nameof(projectStore)); } if (projectMigrator == null) { throw new ArgumentNullException(nameof(projectMigrator)); } if (projectFactory == null) { throw new ArgumentNullException(nameof(projectFactory)); } if (fixedSettings == null) { throw new ArgumentNullException(nameof(fixedSettings)); } ProjectStore = projectStore; FixedSettings = fixedSettings; MainWindow = mainWindow; Plugins = new List <PluginBase>(); viewCommandHandler = new ViewCommandHandler(this, this, this); StorageCommands = new StorageCommandHandler(projectStore, projectMigrator, projectFactory, this, dialogBasedInquiryHelper, this); importCommandHandler = new GuiImportHandler(MainWindow, Plugins.SelectMany(p => p.GetImportInfos()) .Concat(MapImportInfoFactory.Create()), dialogBasedInquiryHelper); exportCommandHandler = new GuiExportHandler(MainWindow, Plugins.SelectMany(p => p.GetExportInfos())); updateCommandHandler = new GuiUpdateHandler(MainWindow, Plugins.SelectMany(p => p.GetUpdateInfos()), dialogBasedInquiryHelper); WindowsApplication.EnableVisualStyles(); ViewPropertyEditor.ViewCommands = ViewCommands; ProjectOpened += ApplicationProjectOpened; BeforeProjectOpened += ApplicationBeforeProjectOpened; projectObserver = new Observer(UpdateProjectData); applicationTitle = string.Format(CultureInfo.CurrentCulture, "{0} {1}", FixedSettings.ApplicationName, SettingsHelper.Instance.ApplicationVersion); SetTitle(); }
public void RemoveAllViewsForItem_GuiHasDocumentViews_CloseViewForDataAndChildren() { // Setup var data = new object(); var childData = new object(); var mocks = new MockRepository(); var documentViewsResolver = mocks.StrictMock <IDocumentViewController>(); documentViewsResolver.Expect(vr => vr.CloseAllViewsFor(data)); documentViewsResolver.Expect(vr => vr.CloseAllViewsFor(childData)); var dataView = mocks.Stub <IView>(); dataView.Data = data; var childDataView = mocks.Stub <IView>(); childDataView.Data = childData; var viewsArray = new List <IView> { dataView, childDataView }; var viewHost = mocks.StrictMock <IViewHost>(); viewHost.Stub(ws => ws.DocumentViews).Return(viewsArray); var applicationSelection = mocks.Stub <IApplicationSelection>(); var pluginsHost = mocks.Stub <IPluginsHost>(); pluginsHost.Expect(g => g.GetAllDataWithViewDefinitionsRecursively(data)).Return(new[] { childData }); var viewController = mocks.Stub <IViewController>(); viewController.Stub(g => g.ViewHost).Return(viewHost); viewController.Stub(g => g.DocumentViewController).Return(documentViewsResolver); mocks.ReplayAll(); var viewCommandHandler = new ViewCommandHandler(viewController, applicationSelection, pluginsHost); // Call viewCommandHandler.RemoveAllViewsForItem(data); // Assert mocks.VerifyAll(); }
public NamespaceRenamingDialogViewModel( NamespaceChangesCalculator namespaceRenamingChangesCalculator, SolutionTreeBuilder solutionTreeBuilder, NamespaceChangesProcessor namespaceChangesProcessor) { Debug.Assert(namespaceRenamingChangesCalculator != null, $"{nameof(namespaceRenamingChangesCalculator)} should not be null"); Debug.Assert(solutionTreeBuilder != null, $"{nameof(solutionTreeBuilder)} should not be null"); Debug.Assert(namespaceChangesProcessor != null, $"{nameof(namespaceChangesProcessor)} should not be null"); _namespaceRenamingChangesCalculator = namespaceRenamingChangesCalculator; _solutionTreeBuilder = solutionTreeBuilder; _namespaceChangesProcessor = namespaceChangesProcessor; cancellationTokenSource = new CancellationTokenSource(); CancelCommand = new ViewCommandHandler(Cancel); }
public void RemoveAllViewsForItem_DataObjectNull_DoNothing() { // Setup var mocks = new MockRepository(); var viewController = mocks.StrictMock <IViewController>(); var applicationSelection = mocks.StrictMock <IApplicationSelection>(); var pluginsHost = mocks.StrictMock <IPluginsHost>(); mocks.ReplayAll(); var commandHandler = new ViewCommandHandler(viewController, applicationSelection, pluginsHost); // Call commandHandler.RemoveAllViewsForItem(null); // Assert mocks.VerifyAll(); // Expect no calls on mocks }
public void HandleCommand_OneTask_OutputsOneTaskToWriter() { // Arrange const string title1 = "fwef"; const string title2 = "fwefewf"; var taskRepository = new InMemoryTaskRepository(); taskRepository.Add(new Task(123, title1)); taskRepository.Add(new Task(456, title2)); var stringWriter = new StringWriter(); var viewCommandHandler = new ViewCommandHandler(taskRepository, stringWriter); // Act viewCommandHandler.HandleCommand(new ViewCommand()); // Assert var textOutput = stringWriter.GetStringBuilder().ToString(); Assert.That(textOutput, Is.StringContaining("123")); Assert.That(textOutput, Is.StringContaining("456")); Assert.That(textOutput, Is.StringContaining(title1)); Assert.That(textOutput, Is.StringContaining(title2)); }