public void ContextMenuStrip_Always_AddCustomItems() { // Setup using (var treeView = new TreeViewControl()) { var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); var assessmentSectionContext = new AssessmentSectionStateRootContext(assessmentSection); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var mocks = new MockRepository(); IGui gui = StubFactory.CreateGuiStub(mocks); gui.Stub(cmp => cmp.Get(assessmentSectionContext, treeView)).Return(menuBuilder); mocks.ReplayAll(); using (var plugin = new RiskeerPlugin()) { plugin.Gui = gui; // Call using (ContextMenuStrip menu = GetInfo(plugin).ContextMenuStrip(assessmentSectionContext, null, treeView)) { // Assert Assert.AreEqual(10, menu.Items.Count); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuImportAssessmentSectionIndex, "&Importeren...", "Importeer de gegevens vanuit een bestand.", CoreGuiResources.ImportIcon); } } } }
public void OnNodeRenamed_WithData_SetProjectNameWithNotification() { // Setup var mocks = new MockRepository(); var observer = mocks.Stub <IObserver>(); observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); var assessmentSectionContext = new AssessmentSectionStateRootContext(assessmentSection); assessmentSectionContext.Attach(observer); using (var plugin = new RiskeerPlugin()) { TreeNodeInfo info = GetInfo(plugin); // Call const string newName = "New Name"; info.OnNodeRenamed(assessmentSectionContext, newName); // Assert Assert.AreEqual(newName, assessmentSection.Name); } mocks.VerifyAll(); }
public void ContextMenuStrip_Always_ContextMenuItemSelectMapLayerEnabled() { // Setup var backgroundData = new BackgroundData(new TestBackgroundDataConfiguration()); var mockRepository = new MockRepository(); var assessmentSectionStateRootContext = new AssessmentSectionStateRootContext(new AssessmentSection(AssessmentSectionComposition.Dike)); using (var treeViewControl = new TreeViewControl()) { IGui gui = StubFactory.CreateGuiStub(mockRepository); gui.Stub(g => g.Get(backgroundData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); mockRepository.ReplayAll(); using (var plugin = new RiskeerPlugin()) { TreeNodeInfo info = GetInfo(plugin); plugin.Gui = gui; // Call using (ContextMenuStrip contextMenu = info.ContextMenuStrip(backgroundData, assessmentSectionStateRootContext, treeViewControl)) { const string expectedItemText = "&Selecteren..."; const string expectedItemTooltip = "Selecteer een achtergrondkaart."; TestHelper.AssertContextMenuStripContainsItem(contextMenu, selectContextMenuIndex, expectedItemText, expectedItemTooltip, RiskeerCommonFormsResources.MapsIcon); } } } // Assert mockRepository.VerifyAll(); }
public void ChildNodeObjects_WithContext_ReturnsChildrenOfData() { // Setup var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); var assessmentSectionContext = new AssessmentSectionStateRootContext(assessmentSection); using (var plugin = new RiskeerPlugin()) { TreeNodeInfo info = GetInfo(plugin); // Call object[] objects = info.ChildNodeObjects(assessmentSectionContext).ToArray(); // Assert Assert.AreEqual(4, objects.Length); var referenceLineContext = (ReferenceLineContext)objects[0]; Assert.AreSame(assessmentSection.ReferenceLine, referenceLineContext.WrappedData); Assert.AreSame(assessmentSection, referenceLineContext.AssessmentSection); var normContext = (NormContext)objects[1]; Assert.AreSame(assessmentSection.FailureMechanismContribution, normContext.WrappedData); Assert.AreSame(assessmentSection, normContext.AssessmentSection); var backgroundData = (BackgroundData)objects[2]; Assert.AreSame(assessmentSection.BackgroundData, backgroundData); var comment = (Comment)objects[3]; Assert.AreSame(assessmentSection.Comments, comment); } }
public void GivenMapDataSet_WhenSelectingMapDataFromContextMenuCancelled_ThenNoObserversNotified() { // Given var mockRepository = new MockRepository(); var assessmentSectionObserver = mockRepository.StrictMock <IObserver>(); var backgroundDataObserver = mockRepository.StrictMock <IObserver>(); WmtsMapData mapData = WmtsMapDataTestHelper.CreateUnconnectedMapData(); BackgroundData backgroundData = BackgroundDataConverter.ConvertTo(mapData); WmtsMapData newMapData = WmtsMapDataTestHelper.CreateDefaultPdokMapData(); BackgroundData newBackgroundData = BackgroundDataConverter.ConvertTo(newMapData); using (new UseCustomSettingsHelper(new TestSettingsHelper { ApplicationLocalUserSettingsDirectory = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO, "noConfig") })) using (new UseCustomTileSourceFactoryConfig(newMapData)) using (var treeViewControl = new TreeViewControl()) using (var plugin = new RiskeerPlugin()) { var viewCommands = mockRepository.Stub <IViewCommands>(); var mainWindow = mockRepository.Stub <IMainWindow>(); IGui gui = StubFactory.CreateGuiStub(mockRepository); gui.Stub(g => g.MainWindow).Return(mainWindow); gui.Stub(g => g.ViewCommands).Return(viewCommands); gui.Stub(cmp => cmp.Get(newBackgroundData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); mockRepository.ReplayAll(); var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); var assessmentSectionStateRootContext = new AssessmentSectionStateRootContext(assessmentSection); assessmentSection.Attach(assessmentSectionObserver); assessmentSection.BackgroundData.Attach(backgroundDataObserver); SetBackgroundData(assessmentSection, mapData); DialogBoxHandler = (name, wnd) => { var tester = (BackgroundMapDataSelectionDialog) new FormTester(name).TheObject; tester.DialogResult = DialogResult.Cancel; tester.Close(); }; TreeNodeInfo info = GetInfo(plugin); plugin.Gui = gui; using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(newBackgroundData, assessmentSectionStateRootContext, treeViewControl)) { // When contextMenuStrip.Items[selectContextMenuIndex].PerformClick(); // Then BackgroundDataTestHelper.AssertBackgroundData(backgroundData, assessmentSection.BackgroundData); } } mockRepository.VerifyAll(); }
public void CreateInstance_WithContext_ReturnsAssessmentSectionReferenceLineView() { // Setup var context = new AssessmentSectionStateRootContext(new AssessmentSection(AssessmentSectionComposition.Dike)); // Call IView view = info.CreateInstance(context); // Assert Assert.IsInstanceOf <AssessmentSectionReferenceLineView>(view); }
public void Constructor_ExpectedValues() { // Setup var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); // Call var context = new AssessmentSectionStateRootContext(assessmentSection); // Assert Assert.IsInstanceOf <StateRootContext>(context); Assert.AreSame(assessmentSection, context.WrappedData); }
public void Text_WithContext_ReturnsName() { // Setup const string testName = "ttt"; var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) { Name = testName }; var assessmentSectionContext = new AssessmentSectionStateRootContext(assessmentSection); using (var plugin = new RiskeerPlugin()) { TreeNodeInfo info = GetInfo(plugin); // Call string text = info.Text(assessmentSectionContext); // Assert Assert.AreEqual(testName, text); } }
public void GivenMapDataSet_WhenSelectingValidWellKnownMapDataFromContextMenu_ThenBackgroundDataSetAndNotifiesObserver() { // Given var mockRepository = new MockRepository(); var backgroundDataObserver = mockRepository.StrictMock <IObserver>(); backgroundDataObserver.Expect(o => o.UpdateObserver()); WmtsMapData mapData = WmtsMapDataTestHelper.CreateUnconnectedMapData(); var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); var assessmentSectionStateRootContext = new AssessmentSectionStateRootContext(assessmentSection); const WellKnownTileSource wellKnownTileSource = WellKnownTileSource.BingAerial; var newMapData = new WellKnownTileSourceMapData(wellKnownTileSource); BackgroundData newBackgroundData = BackgroundDataConverter.ConvertTo(newMapData); using (new UseCustomSettingsHelper(new TestSettingsHelper { ApplicationLocalUserSettingsDirectory = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Integration.Forms, "EmptyWmtsConnectionInfo") })) using (var treeViewControl = new TreeViewControl()) using (var plugin = new RiskeerPlugin()) { var viewCommands = mockRepository.Stub <IViewCommands>(); var mainWindow = mockRepository.Stub <IMainWindow>(); IGui gui = StubFactory.CreateGuiStub(mockRepository); gui.Stub(g => g.MainWindow).Return(mainWindow); gui.Stub(g => g.ViewCommands).Return(viewCommands); gui.Stub(cmp => cmp.Get(newBackgroundData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); mockRepository.ReplayAll(); assessmentSection.BackgroundData.Attach(backgroundDataObserver); SetBackgroundData(assessmentSection, mapData); DialogBoxHandler = (name, wnd) => { var dialog = (BackgroundMapDataSelectionDialog) new FormTester(name).TheObject; var comboBox = (ComboBox) new ComboBoxTester("mapLayerComboBox", dialog).TheObject; comboBox.SelectedItem = ((BackgroundMapDataSelectionControl[])comboBox.DataSource).OfType <WellKnownMapDataControl>().First(); var dataGridViewControl = (DataGridViewControl) new ControlTester("dataGridViewControl", dialog).TheObject; dataGridViewControl.SetCurrentCell(dataGridViewControl.GetCell(0, 0)); var button = new ButtonTester("selectButton", dialog); button.Click(); dialog.Close(); }; TreeNodeInfo info = GetInfo(plugin); plugin.Gui = gui; using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(newBackgroundData, assessmentSectionStateRootContext, treeViewControl)) { // When contextMenuStrip.Items[selectContextMenuIndex].PerformClick(); // Then AssertBackgroundData(newMapData, assessmentSection.BackgroundData); } } mockRepository.VerifyAll(); }
public void GivenNoMapDataSet_WhenSelectingValidWmtsMapDataFromContextMenu_ThenBackgroundDataSetAndNotifiesObserver() { // Given var mockRepository = new MockRepository(); var tileFactory = mockRepository.StrictMock <ITileSourceFactory>(); var newMapData = new WmtsMapData("Actueel Hoogtebestand Nederland (AHN1)", "https://geodata.nationaalgeoregister.nl/tiles/service/wmts/ahn1?request=GetCapabilities", "()", "image/png"); tileFactory.Expect(tf => tf.GetWmtsTileSources(null)) .IgnoreArguments() .Return(new[] { new TestWmtsTileSource(newMapData) }); var backgroundDataObserver = mockRepository.StrictMock <IObserver>(); backgroundDataObserver.Expect(o => o.UpdateObserver()); WmtsMapData mapData = WmtsMapDataTestHelper.CreateUnconnectedMapData(); BackgroundData backgroundData = BackgroundDataConverter.ConvertTo(mapData); using (new UseCustomSettingsHelper(new TestSettingsHelper { ApplicationLocalUserSettingsDirectory = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO, "twoValidWmtsConnectionInfos") })) using (new UseCustomTileSourceFactoryConfig(tileFactory)) using (var treeViewControl = new TreeViewControl()) using (var plugin = new RiskeerPlugin()) { var viewCommands = mockRepository.Stub <IViewCommands>(); var mainWindow = mockRepository.Stub <IMainWindow>(); IGui gui = StubFactory.CreateGuiStub(mockRepository); gui.Stub(g => g.MainWindow).Return(mainWindow); gui.Stub(g => g.ViewCommands).Return(viewCommands); gui.Stub(cmp => cmp.Get(backgroundData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); mockRepository.ReplayAll(); var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); var assessmentSectionStateRootContext = new AssessmentSectionStateRootContext(assessmentSection); assessmentSection.BackgroundData.Attach(backgroundDataObserver); DialogBoxHandler = (name, wnd) => { var dialog = (BackgroundMapDataSelectionDialog) new FormTester(name).TheObject; var connectButton = new ButtonTester("connectToButton", dialog); connectButton.Click(); var layersControl = (DataGridViewControl) new ControlTester("dataGridViewControl", dialog).TheObject; layersControl.SetCurrentCell(layersControl.GetCell(0, 0)); var button = new ButtonTester("selectButton", dialog); button.Click(); dialog.Close(); }; TreeNodeInfo info = GetInfo(plugin); plugin.Gui = gui; using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(backgroundData, assessmentSectionStateRootContext, treeViewControl)) { // When contextMenuStrip.Items[selectContextMenuIndex].PerformClick(); // Then AssertBackgroundData(newMapData, assessmentSection.BackgroundData); } } mockRepository.VerifyAll(); }