public void SetDuneLocations_Always_PreviousLocationsAndCalculationsCleared() { // Setup var calculationsForTargetProbability1 = new DuneLocationCalculationsForTargetProbability(0.1); var calculationsForTargetProbability2 = new DuneLocationCalculationsForTargetProbability(0.01); var failureMechanism = new DuneErosionFailureMechanism { DuneLocationCalculationsForUserDefinedTargetProbabilities = { calculationsForTargetProbability1, calculationsForTargetProbability2 } }; failureMechanism.SetDuneLocations(new DuneLocation[] { new TestDuneLocation() }); // Precondition CollectionAssert.IsNotEmpty(failureMechanism.DuneLocations); CollectionAssert.IsNotEmpty(calculationsForTargetProbability1.DuneLocationCalculations); CollectionAssert.IsNotEmpty(calculationsForTargetProbability2.DuneLocationCalculations); // Call failureMechanism.SetDuneLocations(Enumerable.Empty <DuneLocation>()); // Assert CollectionAssert.IsEmpty(failureMechanism.DuneLocations); CollectionAssert.IsEmpty(calculationsForTargetProbability1.DuneLocationCalculations); CollectionAssert.IsEmpty(calculationsForTargetProbability2.DuneLocationCalculations); }
/// <summary> /// Sets <see cref="DuneErosionFailureMechanism.DuneLocations"/> based upon /// the <paramref name="hydraulicBoundaryLocations"/>. /// </summary> /// <param name="failureMechanism">The <see cref="DuneErosionFailureMechanism"/> to update.</param> /// <param name="hydraulicBoundaryLocations">The hydraulic boundary locations to use.</param> /// <param name="duneLocations">The dune locations to use.</param> /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception> public static void SetDuneLocations(DuneErosionFailureMechanism failureMechanism, IEnumerable <HydraulicBoundaryLocation> hydraulicBoundaryLocations, IEnumerable <ReadDuneLocation> duneLocations) { if (failureMechanism == null) { throw new ArgumentNullException(nameof(failureMechanism)); } if (hydraulicBoundaryLocations == null) { throw new ArgumentNullException(nameof(hydraulicBoundaryLocations)); } if (duneLocations == null) { throw new ArgumentNullException(nameof(duneLocations)); } if (!hydraulicBoundaryLocations.Any() || !duneLocations.Any()) { failureMechanism.SetDuneLocations(Enumerable.Empty <DuneLocation>()); return; } var correspondingDuneLocations = new List <DuneLocation>(); foreach (ReadDuneLocation readDuneLocation in duneLocations) { HydraulicBoundaryLocation correspondingHydraulicBoundaryLocation = hydraulicBoundaryLocations .FirstOrDefault(hbl => DoesHydraulicBoundaryLocationMatchWithDuneLocation(hbl, readDuneLocation)); if (correspondingHydraulicBoundaryLocation != null) { var duneLocation = new DuneLocation(correspondingHydraulicBoundaryLocation.Id, readDuneLocation.Name, readDuneLocation.Location, new DuneLocation.ConstructionProperties { CoastalAreaId = readDuneLocation.CoastalAreaId, Offset = readDuneLocation.Offset, Orientation = readDuneLocation.Orientation, D50 = readDuneLocation.D50 }); correspondingDuneLocations.Add(duneLocation); } } failureMechanism.SetDuneLocations(correspondingDuneLocations); }
public void SetDuneLocations_Always_PreviousDuneLocationsCleared() { // Setup var duneLocation = new TestDuneLocation(); var failureMechanism = new DuneErosionFailureMechanism(); failureMechanism.SetDuneLocations(new[] { duneLocation }); // Precondition CollectionAssert.AreEqual( new[] { duneLocation }, failureMechanism.DuneLocations); // Call DuneErosionDataSynchronizationService.SetDuneLocations(failureMechanism, new HydraulicBoundaryLocation[0], new ReadDuneLocation[0]); // Assert CollectionAssert.IsEmpty(failureMechanism.DuneLocations); }
public void DoPostReplacementUpdates_DuneLocationsAdded_DoNothing() { // Setup var mocks = new MockRepository(); var viewCommands = mocks.StrictMock <IViewCommands>(); mocks.ReplayAll(); var failureMechanism = new DuneErosionFailureMechanism(); failureMechanism.SetDuneLocations(new[] { new TestDuneLocation(), new TestDuneLocation() }); var handler = new DuneLocationsReplacementHandler(viewCommands, failureMechanism); handler.Replace(new[] { new HydraulicBoundaryLocation(1, "Locatie_1_100", 205354, 609735) }); // Precondition Assert.AreEqual(1, failureMechanism.DuneLocations.Count()); // Call handler.DoPostReplacementUpdates(); // Assert mocks.VerifyAll(); // Expect no calls in 'viewCommands' }
public void IsEnabled_CalculationsWithoutOutput_ReturnFalse() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); var failureMechanism = new DuneErosionFailureMechanism(); failureMechanism.SetDuneLocations(new[] { new TestDuneLocation() }); var context = new DuneLocationCalculationsForUserDefinedTargetProbabilitiesGroupContext(new ObservableList <DuneLocationCalculationsForTargetProbability>(), failureMechanism, assessmentSection); using (var plugin = new DuneErosionPlugin()) { ExportInfo info = GetExportInfo(plugin); // Call bool isEnabled = info.IsEnabled(context); // Assert Assert.IsFalse(isEnabled); } mocks.VerifyAll(); }
public void ForeColor_DuneLocationsPresent_ReturnControlText() { // Setup var failureMechanism = new DuneErosionFailureMechanism(); failureMechanism.SetDuneLocations(new[] { new TestDuneLocation() }); var calculationsGroupContext = new DuneLocationCalculationsForUserDefinedTargetProbabilitiesGroupContext( new ObservableList <DuneLocationCalculationsForTargetProbability>(), failureMechanism, new AssessmentSectionStub()); using (var plugin = new DuneErosionPlugin()) { TreeNodeInfo info = GetInfo(plugin); // Call Color textColor = info.ForeColor(calculationsGroupContext); // Assert Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), textColor); } }
public void Create_WithDuneLocations_ReturnsEntityWithDuneLocations() { // Setup var duneLocation = new TestDuneLocation(); var failureMechanism = new DuneErosionFailureMechanism { DuneLocationCalculationsForUserDefinedTargetProbabilities = { new DuneLocationCalculationsForTargetProbability(0.1), new DuneLocationCalculationsForTargetProbability(0.01) } }; failureMechanism.SetDuneLocations(new[] { duneLocation }); var duneLocationEntity = new DuneLocationEntity(); var registry = new PersistenceRegistry(); registry.Register(duneLocationEntity, duneLocation); // Call FailureMechanismEntity entity = failureMechanism.Create(registry); // Assert DuneLocationEntity actualDuneLocationEntity = entity.DuneLocationEntities.Single(); Assert.AreSame(duneLocationEntity, actualDuneLocationEntity); DuneErosionFailureMechanismMetaEntity metaEntity = entity.DuneErosionFailureMechanismMetaEntities.Single(); AssertDuneLocationCalculationCollectionEntities(failureMechanism, metaEntity); }
public void ContextMenuStrip_HydraulicBoundaryDatabaseNotLinked_ContextMenuItemCalculateAllDisabledAndTooltipSet() { // Setup var duneLocation = new TestDuneLocation("Test"); var failureMechanism = new DuneErosionFailureMechanism(); var assessmentSection = new AssessmentSectionStub(); failureMechanism.SetDuneLocations(new[] { duneLocation }); var context = new DuneErosionFailureMechanismContext(failureMechanism, assessmentSection); using (var treeViewControl = new TreeViewControl()) { var gui = mocksRepository.Stub <IGui>(); gui.Stub(cmp => cmp.Get(context, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); gui.Stub(g => g.ViewHost).Return(mocksRepository.Stub <IViewHost>()); mocksRepository.ReplayAll(); plugin.Gui = gui; // Call using (ContextMenuStrip contextMenu = info.ContextMenuStrip(context, null, treeViewControl)) { // Assert TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuCalculateAllIndex, "Alles be&rekenen", "Er is geen hydraulische belastingendatabase geïmporteerd.", RiskeerCommonFormsResources.CalculateAllIcon, false); } } }
public void CreateDuneLocationFeatures_WithLocations_ReturnsLocationFeaturesCollection(bool withOutput) { // Setup DuneLocation[] duneLocations = { CreateDuneLocation(1), CreateDuneLocation(2) }; var failureMechanism = new DuneErosionFailureMechanism(); failureMechanism.DuneLocationCalculationsForUserDefinedTargetProbabilities.AddRange(new[] { new DuneLocationCalculationsForTargetProbability(0.1), new DuneLocationCalculationsForTargetProbability(0.001) }); failureMechanism.SetDuneLocations(duneLocations); if (withOutput) { DuneLocationsTestHelper.SetDuneLocationCalculationOutput(failureMechanism); } IEnumerable <AggregatedDuneLocation> aggregatedLocations = AggregatedDuneLocationFactory.CreateAggregatedDuneLocations( failureMechanism.DuneLocations, failureMechanism.DuneLocationCalculationsForUserDefinedTargetProbabilities); // Call IEnumerable <MapFeature> features = DuneErosionMapDataFeaturesFactory.CreateDuneLocationFeatures(aggregatedLocations); // Assert DuneErosionMapFeaturesTestHelper.AssertDuneLocationFeaturesData(failureMechanism, features); }
public void DoPostReplacementUpdates_NoDuneLocationsAdded_CloseAllViewsForFailureMechanism() { // Setup var failureMechanism = new DuneErosionFailureMechanism(); failureMechanism.SetDuneLocations(new[] { new TestDuneLocation(), new TestDuneLocation() }); var mocks = new MockRepository(); var viewCommands = mocks.StrictMock <IViewCommands>(); viewCommands.Expect(vc => vc.RemoveAllViewsForItem(failureMechanism)); mocks.ReplayAll(); var handler = new DuneLocationsReplacementHandler(viewCommands, failureMechanism); handler.Replace(new HydraulicBoundaryLocation[] { new TestHydraulicBoundaryLocation() }); // Precondition CollectionAssert.IsEmpty(failureMechanism.DuneLocations); // Call handler.DoPostReplacementUpdates(); // Assert mocks.VerifyAll(); }
public void CreateCalculationActivitiesForFailureMechanism_WithValidDataAndUsePreprocessorStates_ReturnsExpectedActivities(bool usePreprocessor) { // Setup AssessmentSectionStub assessmentSection = CreateAssessmentSection(usePreprocessor); var duneLocationCalculationsForTargetProbability1 = new DuneLocationCalculationsForTargetProbability(0.1); var duneLocationCalculationsForTargetProbability2 = new DuneLocationCalculationsForTargetProbability(0.01); var failureMechanism = new DuneErosionFailureMechanism { DuneLocationCalculationsForUserDefinedTargetProbabilities = { duneLocationCalculationsForTargetProbability1, duneLocationCalculationsForTargetProbability2 } }; var duneLocation1 = new DuneLocation(1, "locationName1", new Point2D(1, 1), new DuneLocation.ConstructionProperties()); var duneLocation2 = new DuneLocation(2, "locationName2", new Point2D(2, 2), new DuneLocation.ConstructionProperties()); failureMechanism.SetDuneLocations(new[] { duneLocation1, duneLocation2 }); // Call CalculatableActivity[] activities = DuneLocationCalculationActivityFactory.CreateCalculationActivities(failureMechanism, assessmentSection).ToArray(); // Assert Assert.AreEqual(4, activities.Length); HydraulicBoundaryDatabase hydraulicBoundaryDatabase = assessmentSection.HydraulicBoundaryDatabase; AssertDuneLocationCalculationActivity(activities[0], "1/10", duneLocation1.Name, duneLocation1.Id, duneLocationCalculationsForTargetProbability1.TargetProbability, hydraulicBoundaryDatabase); AssertDuneLocationCalculationActivity(activities[1], "1/10", duneLocation2.Name, duneLocation2.Id, duneLocationCalculationsForTargetProbability1.TargetProbability, hydraulicBoundaryDatabase); AssertDuneLocationCalculationActivity(activities[2], "1/100", duneLocation1.Name, duneLocation1.Id, duneLocationCalculationsForTargetProbability2.TargetProbability, hydraulicBoundaryDatabase); AssertDuneLocationCalculationActivity(activities[3], "1/100", duneLocation2.Name, duneLocation2.Id, duneLocationCalculationsForTargetProbability2.TargetProbability, hydraulicBoundaryDatabase); }
public void GivenMapLayerWithDuneLocations_WhenSelectedTargetProbabilityIndexUpdatedAndCollectionNotified_ThenMapDataAndSelectedMetaDataAttributeUpdated( Action <ObservableList <DuneLocationCalculationsForTargetProbability> > shiftItemAction, string selectedMetaDataAttributeFormat, string expectedSelectedMetadataAttributeFormat) { // Given var mocks = new MockRepository(); var observer = mocks.StrictMock <IObserver>(); observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); const double targetProbability = 0.1; var failureMechanism = new DuneErosionFailureMechanism { DuneLocationCalculationsForUserDefinedTargetProbabilities = { new DuneLocationCalculationsForTargetProbability(targetProbability), new DuneLocationCalculationsForTargetProbability(targetProbability), new DuneLocationCalculationsForTargetProbability(targetProbability) } }; failureMechanism.SetDuneLocations(new[] { new TestDuneLocation("test1") }); using (var mapLayer = new DuneErosionLocationsMapLayer(failureMechanism)) { string targetProbabilityString = ProbabilityFormattingHelper.Format(targetProbability); string selectedProbabilityAttribute = string.Format(selectedMetaDataAttributeFormat, targetProbabilityString); mapLayer.MapData.SelectedMetaDataAttribute = selectedProbabilityAttribute; mapLayer.MapData.NotifyObservers(); mapLayer.MapData.Attach(observer); // Precondition AssertDuneLocationsMapData(failureMechanism, mapLayer.MapData); // When ObservableList <DuneLocationCalculationsForTargetProbability> duneLocationCalculationsForUserDefinedTargetProbabilities = failureMechanism.DuneLocationCalculationsForUserDefinedTargetProbabilities; shiftItemAction(duneLocationCalculationsForUserDefinedTargetProbabilities); duneLocationCalculationsForUserDefinedTargetProbabilities.NotifyObservers(); // Then AssertDuneLocationsMapData(failureMechanism, mapLayer.MapData); Assert.AreEqual(string.Format(expectedSelectedMetadataAttributeFormat, targetProbabilityString), mapLayer.MapData.SelectedMetaDataAttribute); } mocks.VerifyAll(); }
public void ContextMenuStrip_ClickOnAddTargetProbabilityItem_CalculationsForTargetProbabilityAddedAndObserversNotified() { // Given var failureMechanism = new DuneErosionFailureMechanism(); failureMechanism.SetDuneLocations(new[] { new TestDuneLocation("Location 1"), new TestDuneLocation("Location 2") }); var calculations = new ObservableList <DuneLocationCalculationsForTargetProbability>(); var context = new DuneLocationCalculationsForUserDefinedTargetProbabilitiesGroupContext(calculations, failureMechanism, new AssessmentSectionStub()); var mockRepository = new MockRepository(); var calculationsObserver = mockRepository.StrictMock <IObserver>(); calculationsObserver.Expect(o => o.UpdateObserver()); calculations.Attach(calculationsObserver); using (var treeViewControl = new TreeViewControl()) { IMainWindow mainWindow = MainWindowTestHelper.CreateMainWindowStub(mockRepository); IGui gui = StubFactory.CreateGuiStub(mockRepository); gui.Stub(g => g.MainWindow).Return(mainWindow); gui.Stub(cmp => cmp.Get(context, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); mockRepository.ReplayAll(); using (var plugin = new DuneErosionPlugin()) { TreeNodeInfo info = GetInfo(plugin); plugin.Gui = gui; plugin.Activate(); using (ContextMenuStrip contextMenuAdapter = info.ContextMenuStrip(context, null, treeViewControl)) { // When contextMenuAdapter.Items[contextMenuAddTargetProbabilityIndex].PerformClick(); // Then Assert.AreEqual(1, calculations.Count); Assert.AreEqual(0.01, calculations[0].TargetProbability); Assert.AreEqual(2, calculations[0].DuneLocationCalculations.Count); } } } mockRepository.VerifyAll(); }
public void Constructor_WithAllData_DataUpdatedToCollectionOfFilledMapData() { // Setup var assessmentSection = new AssessmentSectionStub { ReferenceLine = new ReferenceLine() }; assessmentSection.ReferenceLine.SetGeometry(new[] { new Point2D(1.0, 2.0), new Point2D(2.0, 1.0) }); var geometryPoints = new[] { new Point2D(0.0, 0.0), new Point2D(2.0, 0.0), new Point2D(4.0, 4.0), new Point2D(6.0, 4.0) }; var failureMechanism = new DuneErosionFailureMechanism(); failureMechanism.SetDuneLocations(new[] { new TestDuneLocation() }); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { new FailureMechanismSection("A", geometryPoints.Take(2)), new FailureMechanismSection("B", geometryPoints.Skip(1).Take(2)), new FailureMechanismSection("C", geometryPoints.Skip(2).Take(2)) }); // Call DuneErosionFailureMechanismView view = CreateView(failureMechanism, assessmentSection); IMapControl map = ((RiskeerMapControl)view.Controls[0]).MapControl; // Assert MapDataCollection mapData = map.Data; Assert.IsInstanceOf <MapDataCollection>(mapData); List <MapData> mapDataList = mapData.Collection.ToList(); Assert.AreEqual(2, mapDataList.Count); MapDataTestHelper.AssertReferenceLineMapData(assessmentSection.ReferenceLine, mapDataList[referenceLineIndex]); AssertDuneLocationsMapData(failureMechanism, mapDataList[duneLocationsIndex]); }
public void Replace_NewLocationsIsDune_LocationAndCalculationsAdded() { // Setup var mocks = new MockRepository(); var viewCommands = mocks.Stub <IViewCommands>(); mocks.ReplayAll(); var random = new Random(21); var failureMechanism = new DuneErosionFailureMechanism { DuneLocationCalculationsForUserDefinedTargetProbabilities = { new DuneLocationCalculationsForTargetProbability(random.NextDouble(0, 0.01)), new DuneLocationCalculationsForTargetProbability(random.NextDouble(0, 0.01)) } }; failureMechanism.SetDuneLocations(new[] { new TestDuneLocation(), new TestDuneLocation() }); var handler = new DuneLocationsReplacementHandler(viewCommands, failureMechanism); // Precondition Assert.AreEqual(2, failureMechanism.DuneLocations.Count()); ObservableList <DuneLocationCalculationsForTargetProbability> calculationsForTargetProbabilities = failureMechanism.DuneLocationCalculationsForUserDefinedTargetProbabilities; Assert.AreEqual(2, calculationsForTargetProbabilities[0].DuneLocationCalculations.Count); Assert.AreEqual(2, calculationsForTargetProbabilities[1].DuneLocationCalculations.Count); // Call handler.Replace(new[] { new HydraulicBoundaryLocation(1, "test_1_100", 205354, 609735) }); // Assert Assert.AreEqual(1, failureMechanism.DuneLocations.Count()); DuneLocation duneLocation = failureMechanism.DuneLocations.First(); Assert.AreEqual(1, duneLocation.Id); Assert.AreEqual(new Point2D(205354, 609735), duneLocation.Location); AssertDuneLocationCalculations(duneLocation, failureMechanism); mocks.VerifyAll(); }
public void SetDuneLocations_DuneLocationsNull_ThrowsArgumentNullException() { // Setup var failureMechanism = new DuneErosionFailureMechanism(); // Call void Call() => failureMechanism.SetDuneLocations(null); // Assert string paramName = Assert.Throws <ArgumentNullException>(Call).ParamName; Assert.AreEqual("duneLocations", paramName); }
public void Replace_FailureMechanismHasDuneLocations_LocationsAndCalculationsCleared() { // Setup var mocks = new MockRepository(); var viewCommands = mocks.Stub <IViewCommands>(); mocks.ReplayAll(); var random = new Random(21); var failureMechanism = new DuneErosionFailureMechanism { DuneLocationCalculationsForUserDefinedTargetProbabilities = { new DuneLocationCalculationsForTargetProbability(random.NextDouble(0, 0.01)), new DuneLocationCalculationsForTargetProbability(random.NextDouble(0, 0.01)) } }; var duneLocations = new[] { new TestDuneLocation(), new TestDuneLocation() }; failureMechanism.SetDuneLocations(duneLocations); var handler = new DuneLocationsReplacementHandler(viewCommands, failureMechanism); // Precondition Assert.AreEqual(2, failureMechanism.DuneLocations.Count()); ObservableList <DuneLocationCalculationsForTargetProbability> calculationsForTargetProbabilities = failureMechanism.DuneLocationCalculationsForUserDefinedTargetProbabilities; Assert.AreEqual(2, calculationsForTargetProbabilities[0].DuneLocationCalculations.Count); Assert.AreEqual(2, calculationsForTargetProbabilities[1].DuneLocationCalculations.Count); // Call handler.Replace(new HydraulicBoundaryLocation[] { new TestHydraulicBoundaryLocation() }); // Assert CollectionAssert.IsEmpty(failureMechanism.DuneLocations); CollectionAssert.IsEmpty(calculationsForTargetProbabilities[0].DuneLocationCalculations); CollectionAssert.IsEmpty(calculationsForTargetProbabilities[1].DuneLocationCalculations); mocks.VerifyAll(); }
public void GivenMapLayerWithDuneLocations_WhenChangingDuneLocationsDataAndObserversNotified_ThenMapDataUpdated() { // Given var mocks = new MockRepository(); var observer = mocks.StrictMock <IObserver>(); observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); var failureMechanism = new DuneErosionFailureMechanism(); failureMechanism.SetDuneLocations(new[] { new TestDuneLocation("test1") }); using (var mapLayer = new DuneErosionLocationsMapLayer(failureMechanism)) { mapLayer.MapData.Attach(observer); // Precondition AssertDuneLocationsMapData(failureMechanism, mapLayer.MapData); // When failureMechanism.SetDuneLocations(new[] { new TestDuneLocation("test2") }); failureMechanism.DuneLocations.NotifyObservers(); // Then AssertDuneLocationsMapData(failureMechanism, mapLayer.MapData); } mocks.VerifyAll(); }
public void Constructor_ExpectedValues() { var failureMechanism = new DuneErosionFailureMechanism(); failureMechanism.SetDuneLocations(new[] { new TestDuneLocation("test") }); // Call using (var mapLayer = new DuneErosionLocationsMapLayer(failureMechanism)) { // Assert Assert.IsInstanceOf <IDisposable>(mapLayer); AssertDuneLocationsMapData(failureMechanism, mapLayer.MapData); } }
public void ChildNodeObjects_DuneLocationsPresent_ReturnsExpectedChildData() { // Setup var assessmentSection = new AssessmentSectionStub(); var failureMechanism = new DuneErosionFailureMechanism(); failureMechanism.SetDuneLocations(new[] { new TestDuneLocation() }); var duneLocationCalculationsForTargetProbability1 = new DuneLocationCalculationsForTargetProbability(0.1); var duneLocationCalculationsForTargetProbability2 = new DuneLocationCalculationsForTargetProbability(0.01); var calculationsForTargetProbabilities = new ObservableList <DuneLocationCalculationsForTargetProbability> { duneLocationCalculationsForTargetProbability1, duneLocationCalculationsForTargetProbability2 }; var calculationsGroupContext = new DuneLocationCalculationsForUserDefinedTargetProbabilitiesGroupContext( calculationsForTargetProbabilities, failureMechanism, assessmentSection); using (var plugin = new DuneErosionPlugin()) { TreeNodeInfo info = GetInfo(plugin); // Call object[] childNodeObjects = info.ChildNodeObjects(calculationsGroupContext); // Assert Assert.AreEqual(2, childNodeObjects.Length); DuneLocationCalculationsForUserDefinedTargetProbabilityContext[] calculationsContexts = childNodeObjects.OfType <DuneLocationCalculationsForUserDefinedTargetProbabilityContext>().ToArray(); Assert.AreEqual(2, calculationsContexts.Length); Assert.AreSame(duneLocationCalculationsForTargetProbability1, calculationsContexts[0].WrappedData); Assert.AreSame(failureMechanism, calculationsContexts[0].FailureMechanism); Assert.AreSame(assessmentSection, calculationsContexts[0].AssessmentSection); Assert.AreSame(duneLocationCalculationsForTargetProbability2, calculationsContexts[1].WrappedData); Assert.AreSame(failureMechanism, calculationsContexts[1].FailureMechanism); Assert.AreSame(assessmentSection, calculationsContexts[1].AssessmentSection); } }
public void ContextMenuStrip_HydraulicBoundaryDatabaseNotLinked_ContextMenuItemCalculateAllDisabledAndTooltipSet() { // Setup var duneLocation = new TestDuneLocation("Test"); var failureMechanism = new DuneErosionFailureMechanism(); var assessmentSection = new AssessmentSectionStub(); failureMechanism.SetDuneLocations(new[] { duneLocation }); var groupContext = new DuneLocationCalculationsForUserDefinedTargetProbabilitiesGroupContext(new ObservableList <DuneLocationCalculationsForTargetProbability>(), failureMechanism, assessmentSection); var mocks = new MockRepository(); using (var treeViewControl = new TreeViewControl()) { var gui = mocks.Stub <IGui>(); gui.Stub(cmp => cmp.Get(groupContext, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); gui.Stub(g => g.ViewHost).Return(mocks.Stub <IViewHost>()); mocks.ReplayAll(); using (var plugin = new DuneErosionPlugin()) { TreeNodeInfo info = GetInfo(plugin); plugin.Gui = gui; // Call using (ContextMenuStrip contextMenu = info.ContextMenuStrip(groupContext, null, treeViewControl)) { // Assert ToolStripItem contextMenuItem = contextMenu.Items[contextMenuCalculateAllIndex]; StringAssert.Contains("Er is geen hydraulische belastingendatabase geïmporteerd.", contextMenuItem.ToolTipText); Assert.IsFalse(contextMenuItem.Enabled); } } } mocks.VerifyAll(); }
public void GivenMapLayerWithDuneLocations_WhenNotSelectedTargetProbabilityRemovedAndNotified_ThenMapDataUpdated(string displayName) { // Given var mocks = new MockRepository(); var observer = mocks.StrictMock <IObserver>(); observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); var failureMechanism = new DuneErosionFailureMechanism(); failureMechanism.DuneLocationCalculationsForUserDefinedTargetProbabilities.Add( new DuneLocationCalculationsForTargetProbability(0.1)); failureMechanism.DuneLocationCalculationsForUserDefinedTargetProbabilities.Add( new DuneLocationCalculationsForTargetProbability(0.001)); failureMechanism.SetDuneLocations(new[] { new TestDuneLocation("test1") }); using (var mapLayer = new DuneErosionLocationsMapLayer(failureMechanism)) { DuneLocationCalculationsForTargetProbability calculationsForTargetProbabilityToRemove = failureMechanism.DuneLocationCalculationsForUserDefinedTargetProbabilities.First(); DuneLocationCalculationsForTargetProbability calculationsForTargetProbability = failureMechanism.DuneLocationCalculationsForUserDefinedTargetProbabilities.Last(); mapLayer.MapData.SelectedMetaDataAttribute = string.Format(displayName, ProbabilityFormattingHelper.Format(calculationsForTargetProbability.TargetProbability)); mapLayer.MapData.NotifyObservers(); mapLayer.MapData.Attach(observer); // Precondition AssertDuneLocationsMapData(failureMechanism, mapLayer.MapData); // When failureMechanism.DuneLocationCalculationsForUserDefinedTargetProbabilities.Remove(calculationsForTargetProbabilityToRemove); failureMechanism.DuneLocationCalculationsForUserDefinedTargetProbabilities.NotifyObservers(); // Then AssertDuneLocationsMapData(failureMechanism, mapLayer.MapData); Assert.AreEqual(string.Format(displayName, ProbabilityFormattingHelper.Format(calculationsForTargetProbability.TargetProbability)), mapLayer.MapData.SelectedMetaDataAttribute); } mocks.VerifyAll(); }
public void GivenMapLayerWithDuneLocations_WhenCalculationsForAddedUserDefinedTargetProbabilityUpdatedAndNotified_ThenMapDataUpdated() { // Given var mocks = new MockRepository(); var observer = mocks.StrictMock <IObserver>(); observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); var failureMechanism = new DuneErosionFailureMechanism(); failureMechanism.SetDuneLocations(new[] { new TestDuneLocation("test1") }); using (var mapLayer = new DuneErosionLocationsMapLayer(failureMechanism)) { var targetProbability = new DuneLocationCalculationsForTargetProbability(0.1); targetProbability.DuneLocationCalculations.AddRange(failureMechanism.DuneLocations.Select(l => new DuneLocationCalculation(l))); failureMechanism.DuneLocationCalculationsForUserDefinedTargetProbabilities.Add(targetProbability); failureMechanism.DuneLocationCalculationsForUserDefinedTargetProbabilities.NotifyObservers(); mapLayer.MapData.Attach(observer); // Precondition AssertDuneLocationsMapData(failureMechanism, mapLayer.MapData); // When DuneLocationCalculation duneLocationCalculation = targetProbability.DuneLocationCalculations.First(); duneLocationCalculation.Output = new TestDuneLocationCalculationOutput(); duneLocationCalculation.NotifyObservers(); // Then AssertDuneLocationsMapData(failureMechanism, mapLayer.MapData); } mocks.VerifyAll(); }
public void SetDuneLocations_MultipleDuneLocations_SetsExpectedLocationsAndCalculations() { // Setup var calculationsForTargetProbability1 = new DuneLocationCalculationsForTargetProbability(0.1); var calculationsForTargetProbability2 = new DuneLocationCalculationsForTargetProbability(0.01); var failureMechanism = new DuneErosionFailureMechanism { DuneLocationCalculationsForUserDefinedTargetProbabilities = { calculationsForTargetProbability1, calculationsForTargetProbability2 } }; var duneLocation1 = new TestDuneLocation(); var duneLocation2 = new TestDuneLocation(); TestDuneLocation[] duneLocations = { duneLocation1, duneLocation2 }; // Call failureMechanism.SetDuneLocations(duneLocations); // Assert CollectionAssert.AreEqual(duneLocations, failureMechanism.DuneLocations); Assert.AreEqual(2, calculationsForTargetProbability1.DuneLocationCalculations.Count); Assert.AreSame(duneLocation1, calculationsForTargetProbability1.DuneLocationCalculations[0].DuneLocation); Assert.AreSame(duneLocation2, calculationsForTargetProbability1.DuneLocationCalculations[1].DuneLocation); Assert.AreEqual(2, calculationsForTargetProbability2.DuneLocationCalculations.Count); Assert.AreSame(duneLocation1, calculationsForTargetProbability2.DuneLocationCalculations[0].DuneLocation); Assert.AreSame(duneLocation2, calculationsForTargetProbability2.DuneLocationCalculations[1].DuneLocation); }
public void ClearDuneLocationCalculationOutput_CalculationsWithOutput_OutputClearedAndAffectedItemsReturned() { // Setup var duneLocations = new[] { new TestDuneLocation(), new TestDuneLocation() }; var duneLocationCalculationsForTargetProbability1 = new DuneLocationCalculationsForTargetProbability(0.1); var duneLocationCalculationsForTargetProbability2 = new DuneLocationCalculationsForTargetProbability(0.01); var failureMechanism = new DuneErosionFailureMechanism { DuneLocationCalculationsForUserDefinedTargetProbabilities = { duneLocationCalculationsForTargetProbability1, duneLocationCalculationsForTargetProbability2 } }; failureMechanism.SetDuneLocations(duneLocations); duneLocationCalculationsForTargetProbability1.DuneLocationCalculations.First().Output = new TestDuneLocationCalculationOutput(); duneLocationCalculationsForTargetProbability2.DuneLocationCalculations.First().Output = new TestDuneLocationCalculationOutput(); IEnumerable <IObservable> expectedAffectedCalculations = DuneLocationsTestHelper.GetAllDuneLocationCalculationsWithOutput(failureMechanism); // Call IEnumerable <IObservable> affected = DuneErosionDataSynchronizationService.ClearDuneLocationCalculationsOutput(failureMechanism); // Assert CollectionAssert.AreEquivalent(expectedAffectedCalculations, affected); DuneLocationsTestHelper.AssertDuneLocationCalculationsHaveNoOutputs(failureMechanism); }
public void GivenValidCalculations_WhenCalculatingAllFromContextMenu_ThenAllCalculationsScheduled() { // Given var assessmentSection = new AssessmentSectionStub { HydraulicBoundaryDatabase = { FilePath = validFilePath } }; HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(assessmentSection.HydraulicBoundaryDatabase); var failureMechanism = new DuneErosionFailureMechanism { DuneLocationCalculationsForUserDefinedTargetProbabilities = { new DuneLocationCalculationsForTargetProbability(0.1), new DuneLocationCalculationsForTargetProbability(0.01) } }; var duneLocation = new TestDuneLocation("Test"); failureMechanism.SetDuneLocations(new[] { duneLocation }); var groupContext = new DuneLocationCalculationsForUserDefinedTargetProbabilitiesGroupContext(failureMechanism.DuneLocationCalculationsForUserDefinedTargetProbabilities, failureMechanism, assessmentSection); var mocks = new MockRepository(); using (var treeViewControl = new TreeViewControl()) { IMainWindow mainWindow = MainWindowTestHelper.CreateMainWindowStub(mocks); var gui = mocks.Stub <IGui>(); gui.Stub(g => g.MainWindow).Return(mainWindow); gui.Stub(cmp => cmp.Get(groupContext, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); gui.Stub(g => g.DocumentViewController).Return(mocks.Stub <IDocumentViewController>()); gui.Stub(g => g.ViewHost).Return(mocks.Stub <IViewHost>()); var calculatorFactory = mocks.Stub <IHydraRingCalculatorFactory>(); var dunesBoundaryConditionsCalculator = new TestDunesBoundaryConditionsCalculator { Converged = false }; calculatorFactory.Expect(cf => cf.CreateDunesBoundaryConditionsCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull)) .WhenCalled(invocation => { HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings( HydraulicBoundaryCalculationSettingsFactory.CreateSettings(assessmentSection.HydraulicBoundaryDatabase), (HydraRingCalculationSettings)invocation.Arguments[0]); }) .Return(dunesBoundaryConditionsCalculator).Repeat.Times(2); mocks.ReplayAll(); using (var plugin = new DuneErosionPlugin()) { TreeNodeInfo info = GetInfo(plugin); plugin.Gui = gui; plugin.Activate(); using (ContextMenuStrip contextMenuAdapter = info.ContextMenuStrip(groupContext, null, treeViewControl)) using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // When void Call() => contextMenuAdapter.Items[contextMenuCalculateAllIndex].PerformClick(); // Then TestHelper.AssertLogMessages(Call, messages => { string[] msgs = messages.ToArray(); Assert.AreEqual(16, msgs.Length); const string calculationTypeDisplayName = "Hydraulische belastingen"; const string calculationDisplayName = "Hydraulische belastingenberekening"; HydraulicBoundaryLocationCalculationActivityLogTestHelper.AssertHydraulicBoundaryLocationCalculationMessages( duneLocation.Name, calculationTypeDisplayName, calculationDisplayName, "1/10", msgs, 0); HydraulicBoundaryLocationCalculationActivityLogTestHelper.AssertHydraulicBoundaryLocationCalculationMessages( duneLocation.Name, calculationTypeDisplayName, calculationDisplayName, "1/100", msgs, 8); }); } } } mocks.VerifyAll(); }
public void Constructor_WithAllData_DataUpdatedToCollectionOfFilledMapData() { // Setup var assessmentSection = new AssessmentSectionStub { ReferenceLine = new ReferenceLine() }; assessmentSection.ReferenceLine.SetGeometry(new[] { new Point2D(1.0, 2.0), new Point2D(2.0, 1.0) }); var geometryPoints = new[] { new Point2D(0.0, 0.0), new Point2D(2.0, 0.0), new Point2D(4.0, 4.0), new Point2D(6.0, 4.0) }; var failureMechanism = new DuneErosionFailureMechanism(); failureMechanism.SetDuneLocations(new[] { new TestDuneLocation() }); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { new FailureMechanismSection("A", geometryPoints.Take(2)), new FailureMechanismSection("B", geometryPoints.Skip(1).Take(2)), new FailureMechanismSection("C", geometryPoints.Skip(2).Take(2)) }); using (new AssemblyToolCalculatorFactoryConfig()) { // Call DuneErosionFailureMechanismView view = CreateView(failureMechanism, assessmentSection); IMapControl map = ((RiskeerMapControl)view.Controls[0]).MapControl; // Assert MapDataCollection mapData = map.Data; Assert.IsInstanceOf <MapDataCollection>(mapData); List <MapData> mapDataList = mapData.Collection.ToList(); Assert.AreEqual(4, mapDataList.Count); MapDataTestHelper.AssertReferenceLineMapData(assessmentSection.ReferenceLine, mapDataList[referenceLineIndex]); IEnumerable <MapData> sectionsCollection = ((MapDataCollection)mapDataList[sectionsCollectionIndex]).Collection; MapDataTestHelper.AssertFailureMechanismSectionsMapData(failureMechanism.Sections, sectionsCollection.ElementAt(sectionsIndex)); MapDataTestHelper.AssertFailureMechanismSectionsStartPointMapData(failureMechanism.Sections, sectionsCollection.ElementAt(sectionsStartPointIndex)); MapDataTestHelper.AssertFailureMechanismSectionsEndPointMapData(failureMechanism.Sections, sectionsCollection.ElementAt(sectionsEndPointIndex)); AssertDuneLocationsMapData(failureMechanism, mapDataList[duneLocationsIndex]); var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance; FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; MapDataTestHelper.AssertAssemblyMapData(failureMechanism, calculator.FailureMechanismSectionAssemblyResultOutput.AssemblyResult, mapDataList[assemblyResultsIndex]); } }