public void Constructor_WithReferenceLine_DataUpdatedToCollectionOfFilledMapData()
        {
            // Setup
            var referenceLine = new ReferenceLine();

            referenceLine.SetGeometry(new[]
            {
                new Point2D(1.0, 2.0),
                new Point2D(2.0, 1.0)
            });

            var assessmentSection = new AssessmentSectionStub
            {
                ReferenceLine = referenceLine
            };

            // Call
            AssessmentSectionReferenceLineView view = ShowCalculationsView(assessmentSection);

            // Assert
            Assert.IsInstanceOf <MapDataCollection>(view.Map.Data);
            MapDataCollection mapData = view.Map.Data;

            Assert.IsNotNull(mapData);

            MapData referenceLineMapData = mapData.Collection.ElementAt(referenceLineIndex);

            MapDataTestHelper.AssertReferenceLineMapData(referenceLine, referenceLineMapData);
            Assert.IsTrue(referenceLineMapData.IsVisible);
        }
Beispiel #2
0
        public void GivenMapLayerWithHydraulicBoundaryLocationsData_WhenSelectedWaveHeightTargetProbabilityIndexUpdatedAndCollectionNotified_ThenMapDataAndSelectedMetaDataAttributeUpdated(
            Action <ObservableList <HydraulicBoundaryLocationCalculationsForTargetProbability> > shiftItemAction,
            string selectedTargetProbabilityFormat, string expectedSelectedTargetProbabilityFormat)
        {
            // Given
            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

            observer.Expect(o => o.UpdateObserver());
            mocks.ReplayAll();

            const double targetProbability = 0.001;
            var          assessmentSection = new AssessmentSectionStub();

            assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities.Clear();
            assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities.AddRange(new[]
            {
                new HydraulicBoundaryLocationCalculationsForTargetProbability(targetProbability),
                new HydraulicBoundaryLocationCalculationsForTargetProbability(targetProbability),
                new HydraulicBoundaryLocationCalculationsForTargetProbability(targetProbability)
            });

            var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "test1", 1.0, 2.0);

            assessmentSection.SetHydraulicBoundaryLocationCalculations(new[]
            {
                hydraulicBoundaryLocation
            });

            using (var mapLayer = new HydraulicBoundaryLocationsMapLayer(assessmentSection))
            {
                string targetProbabilityString   = ProbabilityFormattingHelper.Format(targetProbability);
                string selectedProbabilityString = string.Format(selectedTargetProbabilityFormat, targetProbabilityString);
                mapLayer.MapData.SelectedMetaDataAttribute = string.Format(waveHeightDisplayNameFormat, selectedProbabilityString);
                mapLayer.MapData.NotifyObservers();

                mapLayer.MapData.Attach(observer);

                // Precondition
                MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, mapLayer.MapData);

                // When
                ObservableList <HydraulicBoundaryLocationCalculationsForTargetProbability> waveHeightCalculationsForUserDefinedTargetProbabilities =
                    assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities;
                shiftItemAction(waveHeightCalculationsForUserDefinedTargetProbabilities);
                waveHeightCalculationsForUserDefinedTargetProbabilities.NotifyObservers();

                // Then
                MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, mapLayer.MapData);

                string expectedSelectedProbabilityString = string.Format(expectedSelectedTargetProbabilityFormat, targetProbabilityString);
                Assert.AreEqual(string.Format(waveHeightDisplayNameFormat, expectedSelectedProbabilityString),
                                mapLayer.MapData.SelectedMetaDataAttribute);
            }

            mocks.VerifyAll();
        }
Beispiel #3
0
        public void Constructor_AssessmentSectionWithBackgroundData_BackgroundDataSet()
        {
            // Setup
            IAssessmentSection assessmentSection = new AssessmentSectionStub();

            // Call
            DuneErosionFailureMechanismView view = CreateView(new DuneErosionFailureMechanism(), assessmentSection);

            // Assert
            MapDataTestHelper.AssertImageBasedMapData(assessmentSection.BackgroundData, view.Map.BackgroundMapData);
        }
        public void Constructor_AssessmentSectionWithBackgroundData_BackgroundDataSet()
        {
            // Setup
            var assessmentSection = new AssessmentSectionStub();

            // Call
            AssessmentSectionReferenceLineView view = ShowCalculationsView(assessmentSection);

            // Assert
            MapDataTestHelper.AssertImageBasedMapData(assessmentSection.BackgroundData, view.Map.BackgroundMapData);
        }
        public void Constructor_AssessmentSectionWithBackgroundData_BackgroundDataSet()
        {
            // Setup
            var assessmentSection = new AssessmentSectionStub();

            // Call
            MacroStabilityInwardsFailureMechanismView view = CreateView(new MacroStabilityInwardsFailureMechanism(), assessmentSection);

            // Assert
            MapDataTestHelper.AssertImageBasedMapData(assessmentSection.BackgroundData, view.Map.BackgroundMapData);
        }
        public void ConvertFrom_BackgroundData_ReturnWmtsMapData(WmtsMapData mapData)
        {
            // Setup
            BackgroundData backgroundData = BackgroundDataConverter.ConvertTo(mapData);

            // Call
            ImageBasedMapData convertedMapData = BackgroundDataConverter.ConvertFrom(backgroundData);

            // Assert
            MapDataTestHelper.AssertImageBasedMapData(backgroundData, convertedMapData);
        }
Beispiel #7
0
        public void GivenMapLayerWithFailureMechanismSectionAssemblyResults_WhenChangingNestedCalculationScenarioInputDataAndObserversNotified_ThenMapDataUpdated()
        {
            // Given
            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

            observer.Expect(o => o.UpdateObserver());
            mocks.ReplayAll();

            var random = new Random(21);
            var calculationScenario = new TestCalculationScenario();
            var failureMechanism    = new TestCalculatableFailureMechanism(new[]
            {
                calculationScenario
            });

            failureMechanism.SetSections(new[]
            {
                FailureMechanismSectionTestFactory.CreateFailureMechanismSection()
            }, string.Empty);

            var nestedCalculationScenario = new TestCalculationScenario();
            var nestedCalculationGroup    = new CalculationGroup();

            nestedCalculationGroup.Children.Add(nestedCalculationScenario);
            failureMechanism.CalculationsGroup.Children.Add(nestedCalculationGroup);

            var assemblyResult = new FailureMechanismSectionAssemblyResult(
                random.NextDouble(), random.NextDouble(), random.NextDouble(),
                random.NextEnumValue <FailureMechanismSectionAssemblyGroup>());

            using (var mapLayer = new CalculatableFailureMechanismSectionResultsMapLayer <TestCalculatableFailureMechanism, TestFailureMechanismSectionResult, TestCalculationInput>(
                       failureMechanism, result => assemblyResult))
            {
                mapLayer.MapData.Attach(observer);

                // Precondition
                MapDataTestHelper.AssertAssemblyMapData(failureMechanism, assemblyResult, mapLayer.MapData);

                // When
                assemblyResult = new FailureMechanismSectionAssemblyResult(
                    random.NextDouble(), random.NextDouble(), random.NextDouble(),
                    random.NextEnumValue <FailureMechanismSectionAssemblyGroup>());

                nestedCalculationScenario.InputParameters.HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation();
                nestedCalculationScenario.InputParameters.NotifyObservers();

                // Then
                MapDataTestHelper.AssertAssemblyMapData(failureMechanism, assemblyResult, mapLayer.MapData);
            }

            mocks.VerifyAll();
        }
        public void Constructor_AssessmentSectionWithBackgroundData_BackgroundDataSet()
        {
            // Setup
            AssessmentSection assessmentSection = CreateAssessmentSection();

            // Call
            using (var view = new AssemblyResultPerSectionMapView(assessmentSection))
            {
                // Assert
                MapDataTestHelper.AssertImageBasedMapData(assessmentSection.BackgroundData, view.Map.BackgroundMapData);
            }
        }
Beispiel #9
0
        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]);
        }
Beispiel #10
0
        public void Constructor_AssessmentSectionWithBackgroundData_BackgroundDataSet()
        {
            // Setup
            IAssessmentSection assessmentSection = new AssessmentSectionStub();

            // Call
            using (StandAloneFailureMechanismView <IFailureMechanism <FailureMechanismSectionResult>, FailureMechanismSectionResult> view =
                       CreateView(new TestFailureMechanism(), assessmentSection))
            {
                // Assert
                MapDataTestHelper.AssertImageBasedMapData(assessmentSection.BackgroundData, view.Map.BackgroundMapData);
            }
        }
        public void ConvertFrom_BackgroundData_ReturnWellKnownMapData()
        {
            // Setup
            var            random = new Random(21);
            var            wellKnownTileSource = random.NextEnumValue <WellKnownTileSource>();
            BackgroundData backgroundData      = BackgroundDataConverter.ConvertTo(new WellKnownTileSourceMapData(wellKnownTileSource));

            // Call
            ImageBasedMapData convertedMapData = BackgroundDataConverter.ConvertFrom(backgroundData);

            // Assert
            MapDataTestHelper.AssertImageBasedMapData(backgroundData, convertedMapData);
        }
        public void GivenMapLayerWithFailureMechanismSectionAssemblyResults_WhenChangingFailureMechanismDataAndObserversNotified_ThenMapDataUpdated()
        {
            // Given
            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

            observer.Expect(o => o.UpdateObserver());
            mocks.ReplayAll();

            var random           = new Random(21);
            var failureMechanism = new TestFailureMechanism();

            failureMechanism.SetSections(new[]
            {
                FailureMechanismSectionTestFactory.CreateFailureMechanismSection()
            }, string.Empty);

            var assemblyResult = new FailureMechanismSectionAssemblyResult(
                random.NextDouble(), random.NextDouble(), random.NextDouble(),
                random.NextEnumValue <FailureMechanismSectionAssemblyGroup>());

            using (var mapLayer = new NonCalculatableFailureMechanismSectionResultsMapLayer <TestFailureMechanismSectionResult>(
                       failureMechanism, result => assemblyResult))
            {
                mapLayer.MapData.Attach(observer);

                // Precondition
                MapDataTestHelper.AssertAssemblyMapData(failureMechanism, assemblyResult, mapLayer.MapData);

                // When
                failureMechanism.SetSections(new[]
                {
                    FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[]
                    {
                        new Point2D(0, 0),
                        new Point2D(1, 1)
                    }),
                    FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[]
                    {
                        new Point2D(1, 1),
                        new Point2D(2, 2)
                    })
                }, string.Empty);
                failureMechanism.NotifyObservers();

                // Then
                MapDataTestHelper.AssertAssemblyMapData(failureMechanism, assemblyResult, mapLayer.MapData);
            }

            mocks.VerifyAll();
        }
        public void Constructor_WithAllData_DataUpdatedToCollectionOfFilledMapData()
        {
            // Setup
            AssessmentSection assessmentSection = CreateAssessmentSectionWithReferenceLine();

            assessmentSection.SetHydraulicBoundaryLocationCalculations(new[]
            {
                new HydraulicBoundaryLocation(1, "test", 1.0, 2.0)
            });

            // Call
            using (new AssemblyToolCalculatorFactoryConfig())
            {
                var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                AssessmentSectionAssemblyCalculatorStub   calculator = calculatorFactory.LastCreatedAssessmentSectionAssemblyCalculator;
                CombinedFailureMechanismSectionAssembly[] failureMechanismSectionAssembly =
                {
                    CombinedFailureMechanismSectionAssemblyTestFactory.Create(assessmentSection, 21)
                };
                calculator.CombinedFailureMechanismSectionAssemblyOutput = new CombinedFailureMechanismSectionAssemblyResultWrapper(
                    failureMechanismSectionAssembly, AssemblyMethod.BOI3A1, AssemblyMethod.BOI3B1, AssemblyMethod.BOI3C1);

                using (var view = new AssemblyResultPerSectionMapView(assessmentSection))
                {
                    // Assert
                    Assert.IsInstanceOf <MapDataCollection>(view.Map.Data);
                    MapDataCollection mapData = view.Map.Data;
                    Assert.IsNotNull(mapData);

                    Assert.AreEqual(3, mapData.Collection.Count());

                    IEnumerable <CombinedFailureMechanismSectionAssemblyResult> expectedResults =
                        AssessmentSectionAssemblyFactory.AssembleCombinedPerFailureMechanismSection(assessmentSection);

                    AssertCombinedFailureMechanismSectionAssemblyResultMapData(expectedResults,
                                                                               assessmentSection.ReferenceLine,
                                                                               mapData.Collection.ElementAt(assemblyResultsIndex));

                    MapData hydraulicBoundaryLocationsMapData = mapData.Collection.ElementAt(hydraulicBoundaryLocationsIndex);
                    MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, hydraulicBoundaryLocationsMapData);

                    MapData referenceLineMapData = mapData.Collection.ElementAt(referenceLineIndex);
                    AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData);
                }
            }
        }
        public void GivenViewWithForeshoreProfileData_WhenForeshoreProfileUpdatedAndNotified_ThenMapDataUpdated()
        {
            // Given
            var         failureMechanism = new GrassCoverErosionInwardsFailureMechanism();
            DikeProfile dikeProfile      = DikeProfileTestFactory.CreateDikeProfile(new[]
            {
                new Point2D(0, 0),
                new Point2D(1, 1)
            }, "id1");

            failureMechanism.DikeProfiles.AddRange(new[]
            {
                dikeProfile
            }, "path");

            GrassCoverErosionInwardsFailureMechanismView view = CreateView(failureMechanism, new AssessmentSectionStub());

            IMapControl map = ((RiskeerMapControl)view.Controls[0]).MapControl;

            MapData dikeProfileData = map.Data.Collection.ElementAt(foreshoreProfilesIndex);

            var mocks = new MockRepository();

            IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection);
            observers[dikeProfilesObserverIndex].Expect(obs => obs.UpdateObserver());
            observers[foreshoreProfileObserverIndex].Expect(obs => obs.UpdateObserver());
            mocks.ReplayAll();

            // Precondition
            MapDataTestHelper.AssertForeshoreProfilesMapData(failureMechanism.DikeProfiles.Select(dp => dp.ForeshoreProfile), dikeProfileData);

            // When
            DikeProfile dikeProfileToUpdateFrom = DikeProfileTestFactory.CreateDikeProfile(new[]
            {
                new Point2D(2, 2),
                new Point2D(3, 3)
            }, "id1");

            dikeProfile.CopyProperties(dikeProfileToUpdateFrom);
            failureMechanism.DikeProfiles.NotifyObservers();

            // Then
            MapDataTestHelper.AssertForeshoreProfilesMapData(failureMechanism.DikeProfiles.Select(dp => dp.ForeshoreProfile), dikeProfileData);
            mocks.VerifyAll();
        }
Beispiel #15
0
        public void GivenViewWithForeshoreProfileData_WhenForeshoreProfileUpdatedAndNotified_ThenMapDataUpdated()
        {
            // Given
            var foreshoreProfile = new TestForeshoreProfile("originalProfile ID", new[]
            {
                new Point2D(0, 0),
                new Point2D(1, 1)
            });

            var failureMechanism = new StabilityStoneCoverFailureMechanism();

            failureMechanism.ForeshoreProfiles.AddRange(new[]
            {
                foreshoreProfile
            }, "path");

            StabilityStoneCoverFailureMechanismView view = CreateView(failureMechanism, new AssessmentSectionStub());

            IMapControl map = ((RiskeerMapControl)view.Controls[0]).MapControl;

            var mocks = new MockRepository();

            IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection);
            observers[foreshoreProfileObserverIndex].Expect(obs => obs.UpdateObserver());
            mocks.ReplayAll();

            MapData foreshoreProfileData = map.Data.Collection.ElementAt(foreshoreProfilesIndex);

            // Precondition
            MapDataTestHelper.AssertForeshoreProfilesMapData(failureMechanism.ForeshoreProfiles, foreshoreProfileData);

            // When
            var foreshoreProfileToUpdateFrom = new TestForeshoreProfile("originalProfile ID", new[]
            {
                new Point2D(2, 2),
                new Point2D(3, 3)
            });

            foreshoreProfile.CopyProperties(foreshoreProfileToUpdateFrom);
            foreshoreProfile.NotifyObservers();

            // Then
            MapDataTestHelper.AssertForeshoreProfilesMapData(failureMechanism.ForeshoreProfiles, foreshoreProfileData);
            mocks.VerifyAll();
        }
        public void UpdateObserver_ReferenceLineUpdated_MapDataUpdated()
        {
            // Setup
            var referenceLine = new ReferenceLine();

            referenceLine.SetGeometry(new List <Point2D>
            {
                new Point2D(1.0, 2.0),
                new Point2D(2.0, 1.0)
            });

            var assessmentSection = new AssessmentSectionStub
            {
                ReferenceLine = referenceLine
            };

            AssessmentSectionReferenceLineView view = ShowCalculationsView(assessmentSection);

            IMapControl map = ((RiskeerMapControl)view.Controls[0]).MapControl;

            var       mocks    = new MockRepository();
            IObserver observer = AttachReferenceLineMapDataObserver(mocks, map.Data.Collection);

            observer.Expect(obs => obs.UpdateObserver());
            mocks.ReplayAll();

            MapData referenceLineMapData = map.Data.Collection.ElementAt(referenceLineIndex);

            // Precondition
            MapDataTestHelper.AssertReferenceLineMapData(referenceLine, referenceLineMapData);
            Assert.IsTrue(referenceLineMapData.IsVisible);

            // Call
            referenceLine.SetGeometry(new List <Point2D>
            {
                new Point2D(2.0, 5.0),
                new Point2D(4.0, 3.0)
            });
            referenceLine.NotifyObservers();

            // Assert
            MapDataTestHelper.AssertReferenceLineMapData(referenceLine, referenceLineMapData);
            Assert.IsTrue(referenceLineMapData.IsVisible);
            mocks.VerifyAll();
        }
Beispiel #17
0
        public void Constructor_ExpectedValues()
        {
            // Setup
            var assessmentSection = new AssessmentSectionStub();

            assessmentSection.SetHydraulicBoundaryLocationCalculations(new[]
            {
                new HydraulicBoundaryLocation(1, "test", 1.0, 2.0)
            });

            // Call
            using (var mapLayer = new HydraulicBoundaryLocationsMapLayer(assessmentSection))
            {
                // Assert
                Assert.IsInstanceOf <IDisposable>(mapLayer);
                MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, mapLayer.MapData);
            }
        }
Beispiel #18
0
        public void UpdateObserver_ReferenceLineUpdated_MapDataUpdated()
        {
            // Setup
            var referenceLine = new ReferenceLine();

            referenceLine.SetGeometry(new List <Point2D>
            {
                new Point2D(1.0, 2.0),
                new Point2D(2.0, 1.0)
            });

            var assessmentSection = new AssessmentSectionStub
            {
                ReferenceLine = referenceLine
            };

            using (StandAloneFailureMechanismView <IFailureMechanism <FailureMechanismSectionResult>, FailureMechanismSectionResult> view =
                       CreateView(new TestFailureMechanism(), assessmentSection))
            {
                IMapControl map = ((RiskeerMapControl)view.Controls[0]).MapControl;

                var         mocks     = new MockRepository();
                IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection);
                observers[referenceLineIndex].Expect(obs => obs.UpdateObserver());
                mocks.ReplayAll();

                MapData referenceLineMapData = map.Data.Collection.ElementAt(referenceLineIndex);

                // Precondition
                MapDataTestHelper.AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData);

                // Call
                referenceLine.SetGeometry(new List <Point2D>
                {
                    new Point2D(2.0, 5.0),
                    new Point2D(4.0, 3.0)
                });
                referenceLine.NotifyObservers();

                // Assert
                MapDataTestHelper.AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData);
                mocks.VerifyAll();
            }
        }
Beispiel #19
0
        public void GivenMapLayerWithHydraulicBoundaryLocationsData_WhenCalculationsForUserDefinedTargetProbabilitiesUpdatedAndNotified_ThenMapDataUpdated(
            Func <IAssessmentSection, ObservableList <HydraulicBoundaryLocationCalculationsForTargetProbability> > getTargetProbabilitiesFunc)
        {
            // Given
            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

            observer.Expect(o => o.UpdateObserver());
            mocks.ReplayAll();

            var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "test1", 1.0, 2.0);
            var assessmentSection         = new AssessmentSectionStub();

            assessmentSection.SetHydraulicBoundaryLocationCalculations(new[]
            {
                hydraulicBoundaryLocation
            });

            using (var mapLayer = new HydraulicBoundaryLocationsMapLayer(assessmentSection))
            {
                ObservableList <HydraulicBoundaryLocationCalculationsForTargetProbability> targetProbabilities = getTargetProbabilitiesFunc(assessmentSection);
                var newTargetProbability = new HydraulicBoundaryLocationCalculationsForTargetProbability(0.1);
                newTargetProbability.HydraulicBoundaryLocationCalculations.AddRange(assessmentSection.HydraulicBoundaryDatabase.Locations
                                                                                    .Select(l => new HydraulicBoundaryLocationCalculation(l))
                                                                                    .ToArray());
                targetProbabilities.Add(newTargetProbability);
                targetProbabilities.NotifyObservers();

                mapLayer.MapData.Attach(observer);

                // Precondition
                MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, mapLayer.MapData);

                // When
                HydraulicBoundaryLocationCalculation calculation = newTargetProbability.HydraulicBoundaryLocationCalculations.First();
                calculation.Output = new TestHydraulicBoundaryLocationCalculationOutput(new Random(21).NextDouble());
                calculation.NotifyObservers();

                // Then
                MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, mapLayer.MapData);
            }

            mocks.VerifyAll();
        }
Beispiel #20
0
        public void GivenMapLayerWithHydraulicBoundaryLocationsData_WhenNotSelectedTargetProbabilityRemovedAndNotified_ThenMapDataUpdated(
            Func <IAssessmentSection, ObservableList <HydraulicBoundaryLocationCalculationsForTargetProbability> > getTargetProbabilitiesFunc, string displayName)
        {
            // Given
            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

            observer.Expect(o => o.UpdateObserver());
            mocks.ReplayAll();

            var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "test1", 1.0, 2.0);
            var assessmentSection         = new AssessmentSectionStub();

            assessmentSection.SetHydraulicBoundaryLocationCalculations(new[]
            {
                hydraulicBoundaryLocation
            });

            using (var mapLayer = new HydraulicBoundaryLocationsMapLayer(assessmentSection))
            {
                ObservableList <HydraulicBoundaryLocationCalculationsForTargetProbability> targetProbabilities     = getTargetProbabilitiesFunc(assessmentSection);
                HydraulicBoundaryLocationCalculationsForTargetProbability calculationsForTargetProbabilityToRemove = targetProbabilities.First();
                HydraulicBoundaryLocationCalculationsForTargetProbability calculationsForTargetProbability         = targetProbabilities.Last();
                mapLayer.MapData.SelectedMetaDataAttribute = string.Format(displayName, ProbabilityFormattingHelper.Format(calculationsForTargetProbability.TargetProbability));
                mapLayer.MapData.NotifyObservers();

                mapLayer.MapData.Attach(observer);

                // Precondition
                MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, mapLayer.MapData);

                // When
                targetProbabilities.Remove(calculationsForTargetProbabilityToRemove);
                targetProbabilities.NotifyObservers();

                // Then
                MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, mapLayer.MapData);
                Assert.AreEqual(string.Format(displayName, ProbabilityFormattingHelper.Format(calculationsForTargetProbability.TargetProbability)),
                                mapLayer.MapData.SelectedMetaDataAttribute);
            }

            mocks.VerifyAll();
        }
        public void GivenViewWithReferenceLineData_WhenReferenceLineUpdatedAndNotified_ThenMapDataUpdated()
        {
            // Given
            var referenceLine = new ReferenceLine();

            referenceLine.SetGeometry(new List <Point2D>
            {
                new Point2D(1.0, 2.0),
                new Point2D(2.0, 1.0)
            });

            var assessmentSection = new AssessmentSectionStub
            {
                ReferenceLine = referenceLine
            };

            GrassCoverErosionInwardsFailureMechanismView view = CreateView(new GrassCoverErosionInwardsFailureMechanism(), assessmentSection);

            IMapControl map = ((RiskeerMapControl)view.Controls[0]).MapControl;

            MapData referenceLineMapData = map.Data.Collection.ElementAt(referenceLineIndex);

            var mocks = new MockRepository();

            IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection);
            observers[referenceLineIndex].Expect(obs => obs.UpdateObserver());
            mocks.ReplayAll();

            // Precondition
            MapDataTestHelper.AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData);

            // When
            referenceLine.SetGeometry(new List <Point2D>
            {
                new Point2D(2.0, 5.0),
                new Point2D(4.0, 3.0)
            });
            referenceLine.NotifyObservers();

            // Then
            MapDataTestHelper.AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData);
            mocks.VerifyAll();
        }
        public void GivenViewWithReferenceLineData_WhenReferenceLineUpdatedAndNotified_ThenMapDataUpdatedAndObserversNotified()
        {
            // Given
            var referenceLine = new ReferenceLine();

            referenceLine.SetGeometry(new List <Point2D>
            {
                new Point2D(1.0, 2.0),
                new Point2D(2.0, 1.0)
            });
            var assessmentSection = new AssessmentSectionStub
            {
                ReferenceLine = referenceLine
            };

            var failureMechanism = new SpecificFailureMechanism();
            SpecificFailureMechanismView view = CreateView(failureMechanism, assessmentSection);

            IEnumerable <MapData> mapDataCollection = view.Map.Data.Collection;
            MapData referenceLineMapData            = mapDataCollection.ElementAt(referenceLineIndex);

            var mocks = new MockRepository();

            IObserver[] observers = AttachMapDataObservers(mocks, mapDataCollection);
            observers[referenceLineIndex].Expect(obs => obs.UpdateObserver());
            mocks.ReplayAll();

            // Precondition
            MapDataTestHelper.AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData);

            // When
            referenceLine.SetGeometry(new List <Point2D>
            {
                new Point2D(2.0, 5.0),
                new Point2D(4.0, 3.0)
            });
            referenceLine.NotifyObservers();

            // Then
            MapDataTestHelper.AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData);
            mocks.VerifyAll();
        }
        public void SetAllData_Always_SetsAllDataToMapControl()
        {
            // Setup
            var            mapDataCollection = new MapDataCollection("Collection");
            WmtsMapData    backgroundMapData = WmtsMapDataTestHelper.CreateDefaultPdokMapData();
            BackgroundData backgroundData    = BackgroundDataConverter.ConvertTo(backgroundMapData);

            using (new UseCustomSettingsHelper(testSettingsHelper))
                using (new UseCustomTileSourceFactoryConfig(backgroundMapData))
                    using (var riskeerMapControl = new RiskeerMapControl())
                    {
                        // Call
                        riskeerMapControl.SetAllData(mapDataCollection, backgroundData);

                        // Assert
                        Assert.AreSame(mapDataCollection, riskeerMapControl.MapControl.Data);
                        Assert.IsNotNull(riskeerMapControl.MapControl.BackgroundMapData);
                        MapDataTestHelper.AssertImageBasedMapData(backgroundData, riskeerMapControl.MapControl.BackgroundMapData);
                    }
        }
Beispiel #24
0
        public void UpdateObserver_FailureMechanismUpdated_MapDataUpdated()
        {
            // Setup
            var failureMechanism = new TestFailureMechanism();

            using (StandAloneFailureMechanismView <IFailureMechanism <FailureMechanismSectionResult>, FailureMechanismSectionResult> view =
                       CreateView(failureMechanism, new AssessmentSectionStub()))
            {
                IMapControl map = ((RiskeerMapControl)view.Controls[0]).MapControl;

                IEnumerable <MapData> sectionsCollection = ((MapDataCollection)map.Data.Collection.ElementAt(sectionsCollectionIndex)).Collection;
                var sectionMapData       = (MapLineData)sectionsCollection.ElementAt(sectionsIndex);
                var sectionStartsMapData = (MapPointData)sectionsCollection.ElementAt(sectionsStartPointIndex);
                var sectionsEndsMapData  = (MapPointData)sectionsCollection.ElementAt(sectionsEndPointIndex);

                var         mocks     = new MockRepository();
                IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection);
                observers[sectionsObserverIndex].Expect(obs => obs.UpdateObserver());
                observers[sectionsStartPointObserverIndex].Expect(obs => obs.UpdateObserver());
                observers[sectionsEndPointObserverIndex].Expect(obs => obs.UpdateObserver());
                mocks.ReplayAll();

                // Call
                FailureMechanismTestHelper.SetSections(failureMechanism, new[]
                {
                    new FailureMechanismSection(string.Empty, new[]
                    {
                        new Point2D(1, 2),
                        new Point2D(1, 2)
                    })
                });
                failureMechanism.NotifyObservers();

                // Assert
                MapDataTestHelper.AssertFailureMechanismSectionsMapData(failureMechanism.Sections, sectionMapData);
                MapDataTestHelper.AssertFailureMechanismSectionsStartPointMapData(failureMechanism.Sections, sectionStartsMapData);
                MapDataTestHelper.AssertFailureMechanismSectionsEndPointMapData(failureMechanism.Sections, sectionsEndsMapData);
                mocks.VerifyAll();
            }
        }
Beispiel #25
0
        public void Constructor_WithReferenceLineAndHydraulicBoundaryDatabase_DataUpdatedToCollectionOfFilledMapData()
        {
            // Setup
            var referenceLine = new ReferenceLine();

            referenceLine.SetGeometry(new[]
            {
                new Point2D(1.0, 2.0),
                new Point2D(2.0, 1.0)
            });

            var assessmentSection = new AssessmentSectionStub
            {
                ReferenceLine = referenceLine
            };

            assessmentSection.SetHydraulicBoundaryLocationCalculations(new[]
            {
                new HydraulicBoundaryLocation(1, "test", 1.0, 2.0)
            });

            // Call
            AssessmentSectionExtendedView extendedView = ShowCalculationsView(assessmentSection);

            // Assert
            Assert.IsInstanceOf <MapDataCollection>(extendedView.Map.Data);
            MapDataCollection mapData = extendedView.Map.Data;

            Assert.IsNotNull(mapData);

            MapData hydraulicBoundaryLocationsMapData = mapData.Collection.ElementAt(hydraulicBoundaryLocationsIndex);

            MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, hydraulicBoundaryLocationsMapData);

            MapData referenceLineMapData = mapData.Collection.ElementAt(referenceLineIndex);

            MapDataTestHelper.AssertReferenceLineMapData(referenceLine, referenceLineMapData);
            Assert.IsTrue(referenceLineMapData.IsVisible);
        }
        public void GivenViewWithFailureMechanismSectionsData_WhenFailureMechanismUpdatedAndNotified_ThenMapDataUpdated()
        {
            // Given
            var failureMechanism = new StabilityPointStructuresFailureMechanism();

            StabilityPointStructuresFailureMechanismView view = CreateView(failureMechanism, new AssessmentSectionStub());

            IMapControl map = ((RiskeerMapControl)view.Controls[0]).MapControl;

            IEnumerable <MapData> sectionsCollection = ((MapDataCollection)map.Data.Collection.ElementAt(sectionsCollectionIndex)).Collection;
            var sectionMapData       = (MapLineData)sectionsCollection.ElementAt(sectionsIndex);
            var sectionStartsMapData = (MapPointData)sectionsCollection.ElementAt(sectionsStartPointIndex);
            var sectionsEndsMapData  = (MapPointData)sectionsCollection.ElementAt(sectionsEndPointIndex);

            var mocks = new MockRepository();

            IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection);
            observers[sectionsObserverIndex].Expect(obs => obs.UpdateObserver());
            observers[sectionsStartPointObserverIndex].Expect(obs => obs.UpdateObserver());
            observers[sectionsEndPointObserverIndex].Expect(obs => obs.UpdateObserver());
            mocks.ReplayAll();

            // When
            FailureMechanismTestHelper.SetSections(failureMechanism, new[]
            {
                new FailureMechanismSection(string.Empty, new[]
                {
                    new Point2D(1, 2),
                    new Point2D(1, 2)
                })
            });
            failureMechanism.NotifyObservers();

            // Then
            MapDataTestHelper.AssertFailureMechanismSectionsMapData(failureMechanism.Sections, sectionMapData);
            MapDataTestHelper.AssertFailureMechanismSectionsStartPointMapData(failureMechanism.Sections, sectionStartsMapData);
            MapDataTestHelper.AssertFailureMechanismSectionsEndPointMapData(failureMechanism.Sections, sectionsEndsMapData);
            mocks.VerifyAll();
        }
        public void GivenViewWithStructuresData_WhenStructuresUpdatedAndNotified_ThenMapDataUpdated()
        {
            // Given
            var failureMechanism = new ClosingStructuresFailureMechanism();

            failureMechanism.ClosingStructures.AddRange(new[]
            {
                new TestClosingStructure(new Point2D(0, 0), "Id1")
            }, "path");

            ClosingStructuresFailureMechanismView view = CreateView(failureMechanism, new AssessmentSectionStub());

            IMapControl map = ((RiskeerMapControl)view.Controls[0]).MapControl;

            var mocks = new MockRepository();

            IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection);
            observers[structuresObserverIndex].Expect(obs => obs.UpdateObserver());
            mocks.ReplayAll();

            MapData structuresData = map.Data.Collection.ElementAt(structuresIndex);

            // Precondition
            MapDataTestHelper.AssertStructuresMapData(failureMechanism.ClosingStructures,
                                                      structuresData);

            // When
            failureMechanism.ClosingStructures.AddRange(new[]
            {
                new TestClosingStructure(new Point2D(1, 1), "Id2")
            }, "some path");
            failureMechanism.ClosingStructures.NotifyObservers();

            // Then
            MapDataTestHelper.AssertStructuresMapData(failureMechanism.ClosingStructures,
                                                      structuresData);
            mocks.VerifyAll();
        }
Beispiel #28
0
        public void GivenMapLayerWithHydraulicBoundaryLocations_WhenChangingHydraulicBoundaryLocationsDataAndObserversNotified_ThenMapDataUpdated()
        {
            // Given
            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

            observer.Expect(o => o.UpdateObserver());
            mocks.ReplayAll();

            var assessmentSection = new AssessmentSectionStub();

            assessmentSection.SetHydraulicBoundaryLocationCalculations(new[]
            {
                new HydraulicBoundaryLocation(1, "test1", 1.0, 2.0)
            });

            using (var mapLayer = new HydraulicBoundaryLocationsMapLayer(assessmentSection))
            {
                mapLayer.MapData.Attach(observer);

                // Precondition
                MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, mapLayer.MapData);

                // When
                assessmentSection.SetHydraulicBoundaryLocationCalculations(new[]
                {
                    new HydraulicBoundaryLocation(2, "test2", 2.0, 3.0)
                });
                assessmentSection.HydraulicBoundaryDatabase.Locations.NotifyObservers();

                // Then
                MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, mapLayer.MapData);
            }

            mocks.VerifyAll();
        }
        public void Constructor_ExpectedValues()
        {
            // Setup
            var random           = new Random(21);
            var failureMechanism = new TestFailureMechanism();

            failureMechanism.SetSections(new[]
            {
                FailureMechanismSectionTestFactory.CreateFailureMechanismSection()
            }, string.Empty);

            var assemblyResult = new FailureMechanismSectionAssemblyResult(
                random.NextDouble(), random.NextDouble(), random.NextDouble(),
                random.NextEnumValue <FailureMechanismSectionAssemblyGroup>());

            // Call
            using (var mapLayer = new NonCalculatableFailureMechanismSectionResultsMapLayer <TestFailureMechanismSectionResult>(
                       failureMechanism, result => assemblyResult))
            {
                // Assert
                Assert.IsInstanceOf <IDisposable>(mapLayer);
                MapDataTestHelper.AssertAssemblyMapData(failureMechanism, assemblyResult, mapLayer.MapData);
            }
        }
Beispiel #30
0
        public void GivenMapLayerWithHydraulicBoundaryLocationsData_WhenTargetProbabilityUpdatedAndNotified_ThenMapDataUpdated(
            Func <IAssessmentSection, ObservableList <HydraulicBoundaryLocationCalculationsForTargetProbability> > getTargetProbabilitiesFunc)
        {
            // Given
            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

            observer.Expect(o => o.UpdateObserver());
            mocks.ReplayAll();

            var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "test1", 1.0, 2.0);
            var assessmentSection         = new AssessmentSectionStub();

            assessmentSection.SetHydraulicBoundaryLocationCalculations(new[]
            {
                hydraulicBoundaryLocation
            });

            using (var mapLayer = new HydraulicBoundaryLocationsMapLayer(assessmentSection))
            {
                mapLayer.MapData.Attach(observer);

                // Precondition
                MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, mapLayer.MapData);

                // When
                ObservableList <HydraulicBoundaryLocationCalculationsForTargetProbability> targetProbabilities = getTargetProbabilitiesFunc(assessmentSection);
                targetProbabilities.First().TargetProbability = 0.01;
                targetProbabilities.First().NotifyObservers();

                // Then
                MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, mapLayer.MapData);
            }

            mocks.VerifyAll();
        }