public void UpdateOn_NoSupportedUpdateInfoAvailable_GivesMessageBox() { // Setup var mockRepository = new MockRepository(); var mainWindow = mockRepository.Stub <IMainWindow>(); var inquiryHelper = mockRepository.Stub <IInquiryHelper>(); mockRepository.ReplayAll(); string messageBoxTitle = null, messageBoxText = null; DialogBoxHandler = (name, wnd) => { var messageBox = new MessageBoxTester(wnd); messageBoxText = messageBox.Text; messageBoxTitle = messageBox.Title; messageBox.ClickOk(); }; var updateHandler = new GuiUpdateHandler(mainWindow, new UpdateInfo[] { new UpdateInfo <double>() }, inquiryHelper); // Call updateHandler.UpdateOn(string.Empty); // Assert Assert.AreEqual("Fout", messageBoxTitle); Assert.AreEqual("Geen enkele 'Updater' is beschikbaar voor dit element.", messageBoxText); mockRepository.VerifyAll(); }
public void CanUpdateOn_HasMultipleUpdateInfosForTargetThatCannotBeUsedForUpdating_ReturnFalse() { // Setup var target = new object(); var mocks = new MockRepository(); var dialogParent = mocks.Stub <IViewParent>(); var inquiryHelper = mocks.Stub <IInquiryHelper>(); mocks.ReplayAll(); var commandHandler = new GuiUpdateHandler(dialogParent, new UpdateInfo[] { new UpdateInfo <object> { IsEnabled = data => false }, new UpdateInfo <object> { IsEnabled = data => false } }, inquiryHelper); // Call bool isUpdatePossible = commandHandler.CanUpdateOn(target); // Assert Assert.IsFalse(isUpdatePossible); mocks.VerifyAll(); }
/// <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 frmStopLight() { InitializeComponent(); // detector = new ConnectivityDetector(); // detector.Connectivity += new ConnectivityDetector.ConnectivityEventHandler(ConnectivityEvent); startTime = DateTime.Now; updateGui = new GuiUpdateHandler(UpdateGui); }
public frmStopLight() { InitializeComponent(); detector = new ConnectivityDetector(); detector.Connectivity += new ConnectivityDetector.ConnectivityEventHandler(ConnectivityEvent); startTime = DateTime.Now; updateGui = new GuiUpdateHandler(UpdateGui); }
public void UpdateOn_MultipleSupportedUpdateInfoAvailable_ShowsDialogWithOptions() { // Setup const string updateInfoAName = "nameA"; var updateInfoA = new UpdateInfo <object> { Name = updateInfoAName }; const string updateInfoBName = "nameB"; var updateInfoB = new UpdateInfo <object> { Name = updateInfoBName }; var mockRepository = new MockRepository(); var dialogParent = mockRepository.Stub <IViewParent>(); var inquiryHelper = mockRepository.Stub <IInquiryHelper>(); mockRepository.ReplayAll(); var listViewItems = new ListViewItem[0]; DialogBoxHandler = (name, wnd) => { using (new FormTester(name)) { var listView = (ListView) new ControlTester("listViewItemTypes").TheObject; listViewItems = listView.Items.OfType <ListViewItem>().ToArray(); } }; var updateHandler = new GuiUpdateHandler(dialogParent, new UpdateInfo[] { updateInfoA, updateInfoB }, inquiryHelper); // Call updateHandler.UpdateOn(new object()); // Assert Assert.AreEqual(2, listViewItems.Length); Assert.AreEqual(updateInfoAName, listViewItems[0].Name); Assert.AreEqual(updateInfoBName, listViewItems[1].Name); mockRepository.VerifyAll(); }
public void CanUpdateOn_HasNoFileUpdatersForTarget_ReturnFalse() { // Setup var mocks = new MockRepository(); var dialogParent = mocks.Stub <IViewParent>(); var inquiryHelper = mocks.Stub <IInquiryHelper>(); mocks.ReplayAll(); var commandHandler = new GuiUpdateHandler(dialogParent, Enumerable.Empty <UpdateInfo>(), inquiryHelper); // Call bool isUpdatePossible = commandHandler.CanUpdateOn(new object()); // Assert Assert.IsFalse(isUpdatePossible); mocks.VerifyAll(); }
public void UpdateOn_SupportedUpdateInfoAvailableVerifyUpdatesUnsuccessful_ActivityNotCreated() { // Setup var generator = new FileFilterGenerator(); var targetObject = new object(); var mockRepository = new MockRepository(); var dialogParent = mockRepository.Stub <IViewParent>(); var inquiryHelper = mockRepository.Stub <IInquiryHelper>(); inquiryHelper.Stub(ih => ih.GetSourceFileLocation(generator.Filter)).Return("/some/path"); var fileImporter = mockRepository.Stub <IFileImporter>(); mockRepository.ReplayAll(); var isVerifyUpdatedCalled = false; var updateHandler = new GuiUpdateHandler(dialogParent, new UpdateInfo[] { new UpdateInfo <object> { CreateFileImporter = (o, s) => { Assert.Fail("CreateFileImporter is not expected to be called when VerifyUpdates function returns false."); return(fileImporter); }, FileFilterGenerator = generator, VerifyUpdates = o => { Assert.AreSame(o, targetObject); isVerifyUpdatedCalled = true; return(false); } } }, inquiryHelper); // Call updateHandler.UpdateOn(targetObject); // Assert Assert.IsTrue(isVerifyUpdatedCalled); mockRepository.VerifyAll(); }
public void UpdateOn_InquiryHelperReturnsNoPathAndCurrentPathSet_UpdateCancelledWithLogMessage() { // Setup var generator = new FileFilterGenerator(); var targetObject = new object(); var mockRepository = new MockRepository(); var dialogParent = mockRepository.Stub <IViewParent>(); var inquiryHelper = mockRepository.Stub <IInquiryHelper>(); inquiryHelper.Stub(ih => ih.GetSourceFileLocation(generator.Filter)).Return(null); var fileImporter = mockRepository.Stub <IFileImporter>(); mockRepository.ReplayAll(); const string currentPath = "FilePath/to/Update"; var updateHandler = new GuiUpdateHandler(dialogParent, new UpdateInfo[] { new UpdateInfo <object> { CreateFileImporter = (o, s) => { Assert.Fail("CreateFileImporter is not expected to be called when no file path is chosen."); return(fileImporter); }, FileFilterGenerator = generator, VerifyUpdates = o => true, CurrentPath = o => currentPath } }, inquiryHelper); // Call Action call = () => updateHandler.UpdateOn(targetObject); // Assert string expectedLogMessage = $"Bijwerken van gegevens in '{currentPath}' is geannuleerd."; Tuple <string, LogLevelConstant> expectedLogMessageAndLevel = Tuple.Create(expectedLogMessage, LogLevelConstant.Info); TestHelper.AssertLogMessageWithLevelIsGenerated(call, expectedLogMessageAndLevel); mockRepository.VerifyAll(); }
public void CanUpdateOn_HasOneUpdateInfoForTarget_ReturnTrue() { // Setup var target = new object(); var mocks = new MockRepository(); var dialogParent = mocks.Stub <IViewParent>(); var inquiryHelper = mocks.Stub <IInquiryHelper>(); mocks.ReplayAll(); var commandHandler = new GuiUpdateHandler(dialogParent, new UpdateInfo[] { new UpdateInfo <object>() }, inquiryHelper); // Call bool isUpdatePossible = commandHandler.CanUpdateOn(target); // Assert Assert.IsTrue(isUpdatePossible); mocks.VerifyAll(); }
public void UpdateOn_SupportedUpdateInfoAvailableVerifyUpdatesSuccessful_ExpectedUpdateInfoFunctionsCalledActivityCreated() { // Setup const string filePath = "/some/path"; var generator = new FileFilterGenerator(); var targetObject = new object(); var mockRepository = new MockRepository(); var inquiryHelper = mockRepository.Stub <IInquiryHelper>(); inquiryHelper.Stub(ih => ih.GetSourceFileLocation(generator.Filter)).Return(filePath); var fileImporter = mockRepository.Stub <IFileImporter>(); mockRepository.ReplayAll(); const string dataDescription = "Random data"; var isCreateFileImporterCalled = false; var isVerifyUpdatedCalled = false; DialogBoxHandler = (name, wnd) => { // Activity closes itself }; using (var form = new TestViewParentForm()) { var updateHandler = new GuiUpdateHandler(form, new UpdateInfo[] { new UpdateInfo <object> { Name = dataDescription, CreateFileImporter = (o, s) => { Assert.AreSame(o, targetObject); Assert.AreEqual(filePath, s); isCreateFileImporterCalled = true; return(fileImporter); }, FileFilterGenerator = generator, VerifyUpdates = o => { Assert.AreSame(o, targetObject); isVerifyUpdatedCalled = true; return(true); } } }, inquiryHelper); // Call Action call = () => updateHandler.UpdateOn(targetObject); // Assert TestHelper.AssertLogMessagesAreGenerated(call, new[] { $"Bijwerken van '{dataDescription}' is gestart.", $"Bijwerken van '{dataDescription}' is mislukt." }); } // Assert Assert.IsTrue(isCreateFileImporterCalled); Assert.IsTrue(isVerifyUpdatedCalled); mockRepository.VerifyAll(); }