public void GetFailureMechanisms_Always_ReturnAllFailureMechanisms(AssessmentSectionComposition composition) { // Setup var assessmentSection = new AssessmentSection(composition); // Call IFailureMechanism[] failureMechanisms = assessmentSection.GetFailureMechanisms().ToArray(); // Assert Assert.AreEqual(15, failureMechanisms.Length); CollectionAssert.AreEqual(new IFailureMechanism[] { assessmentSection.Piping, assessmentSection.GrassCoverErosionInwards, assessmentSection.MacroStabilityInwards, assessmentSection.Microstability, assessmentSection.StabilityStoneCover, assessmentSection.WaveImpactAsphaltCover, assessmentSection.WaterPressureAsphaltCover, assessmentSection.GrassCoverErosionOutwards, assessmentSection.GrassCoverSlipOffOutwards, assessmentSection.GrassCoverSlipOffInwards, assessmentSection.HeightStructures, assessmentSection.ClosingStructures, assessmentSection.PipingStructure, assessmentSection.StabilityPointStructures, assessmentSection.DuneErosion }, failureMechanisms); }
public void ChangeComposition_ToTargetValue_UpdateFailureMechanismInAssemblyStates(AssessmentSectionComposition composition, bool[] inAssemblyStates) { // Setup AssessmentSectionComposition initialComposition = composition == AssessmentSectionComposition.Dike ? AssessmentSectionComposition.Dune : AssessmentSectionComposition.Dike; var assessmentSection = new AssessmentSection(initialComposition); // Precondition Assert.AreNotEqual(assessmentSection.Composition, composition); // Call assessmentSection.ChangeComposition(composition); // Assert Assert.AreEqual(inAssemblyStates[0], assessmentSection.Piping.InAssembly); Assert.AreEqual(inAssemblyStates[1], assessmentSection.GrassCoverErosionInwards.InAssembly); Assert.AreEqual(inAssemblyStates[2], assessmentSection.MacroStabilityInwards.InAssembly); Assert.AreEqual(inAssemblyStates[3], assessmentSection.StabilityStoneCover.InAssembly); Assert.AreEqual(inAssemblyStates[4], assessmentSection.WaveImpactAsphaltCover.InAssembly); Assert.AreEqual(inAssemblyStates[5], assessmentSection.GrassCoverErosionOutwards.InAssembly); Assert.AreEqual(inAssemblyStates[6], assessmentSection.HeightStructures.InAssembly); Assert.AreEqual(inAssemblyStates[7], assessmentSection.ClosingStructures.InAssembly); Assert.AreEqual(inAssemblyStates[8], assessmentSection.StabilityPointStructures.InAssembly); Assert.AreEqual(inAssemblyStates[9], assessmentSection.PipingStructure.InAssembly); Assert.AreEqual(inAssemblyStates[10], assessmentSection.DuneErosion.InAssembly); }
public void GivenAssessmentSectionProperties_WhenChangingCompositionValue_ThenCompositionSetAndNotifiesObserver() { // Given const AssessmentSectionComposition newComposition = AssessmentSectionComposition.DikeAndDune; var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); assessmentSection.Stub(section => section.Composition).Return(AssessmentSectionComposition.Dike); assessmentSection.Stub(section => section.FailureMechanismContribution).Return(new FailureMechanismContribution(0.1, 0.1)); var observable = mocks.StrictMock <IObservable>(); observable.Expect(o => o.NotifyObservers()); var assessmentSectionCompositionChangeHandler = mocks.StrictMock <IAssessmentSectionCompositionChangeHandler>(); assessmentSectionCompositionChangeHandler.Expect(handler => handler.ChangeComposition(assessmentSection, newComposition)) .Return(new[] { observable }); mocks.ReplayAll(); var properties = new RegistrationStateAssessmentSectionProperties(assessmentSection, assessmentSectionCompositionChangeHandler); // When properties.Composition = newComposition; // Then mocks.VerifyAll(); }
/// <inheritdoc /> /// <exception cref="InvalidEnumArgumentException">Thrown when <paramref name="newComposition"/> /// is not a valid enum value of <see cref="AssessmentSectionComposition"/>.</exception> public void ChangeComposition(AssessmentSectionComposition newComposition) { if (!Enum.IsDefined(typeof(AssessmentSectionComposition), newComposition)) { throw new InvalidEnumArgumentException(nameof(newComposition), (int)newComposition, typeof(AssessmentSectionComposition)); } Composition = newComposition; SetFailureMechanismsToBeInAssembly(); }
public void Create_WithoutCollector_ThrowsArgumentNullException(AssessmentSectionComposition assessmentSectionComposition) { // Setup var assessmentSection = new AssessmentSection(assessmentSectionComposition); // Call void Call() => assessmentSection.Create(null); // Assert string parameterName = Assert.Throws <ArgumentNullException>(Call).ParamName; Assert.AreEqual("registry", parameterName); }
public void ChangeComposition_ChangeToSameValue_DoNothing() { // Setup var mocks = new MockRepository(); var viewCommands = mocks.StrictMock <IViewCommands>(); mocks.ReplayAll(); AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllCalculationConfigurations(); AssessmentSectionComposition originalComposition = assessmentSection.Composition; ICalculation[] calculationsWithOutput = assessmentSection.GetFailureMechanisms() .OfType <ICalculatableFailureMechanism>() .SelectMany(fm => fm.Calculations) .Where(c => c.HasOutput) .ToArray(); IEnumerable <DuneLocationCalculation> duneLocationCalculationsWithOutput = assessmentSection.DuneErosion.DuneLocationCalculationsForUserDefinedTargetProbabilities.SelectMany(tp => tp.DuneLocationCalculations) .Where(HasDuneLocationCalculationOutput) .ToArray(); IEnumerable <HydraulicBoundaryLocationCalculation> hydraulicBoundaryLocationCalculationsWithOutput = assessmentSection.WaterLevelCalculationsForMaximumAllowableFloodingProbability.Where(HasHydraulicBoundaryLocationCalculationOutput) .Concat(assessmentSection.WaterLevelCalculationsForSignalFloodingProbability.Where(HasHydraulicBoundaryLocationCalculationOutput)) .Concat(assessmentSection.WaterLevelCalculationsForUserDefinedTargetProbabilities.SelectMany(tp => tp.HydraulicBoundaryLocationCalculations)) .ToArray(); var handler = new AssessmentSectionCompositionChangeHandler(viewCommands); // Call IEnumerable <IObservable> affectedObjects = handler.ChangeComposition(assessmentSection, originalComposition); // Assert Assert.True(calculationsWithOutput.All(c => c.HasOutput), "All calculations that had output still have them."); Assert.True(duneLocationCalculationsWithOutput.All(HasDuneLocationCalculationOutput)); Assert.True(hydraulicBoundaryLocationCalculationsWithOutput.All(calc => calc.HasOutput)); CollectionAssert.IsEmpty(affectedObjects); mocks.VerifyAll(); }
/// <summary> /// Initializes a new instance of the <see cref="AssessmentSection"/> class. /// </summary> /// <param name="composition">The composition of the assessment section, e.g. what /// type of elements can be found within the assessment section.</param> /// <param name="maximumAllowableFloodingProbability">The maximum allowable flooding probability of the assessment section.</param> /// <param name="signalFloodingProbability">The signal flooding probability of the assessment section.</param> /// <exception cref="ArgumentOutOfRangeException">Thrown when: /// <list type="bullet"> /// <item><paramref name="maximumAllowableFloodingProbability"/> is not in the interval [0.000001, 0.1] or is <see cref="double.NaN"/>;</item> /// <item><paramref name="signalFloodingProbability"/> is not in the interval [0.000001, 0.1] or is <see cref="double.NaN"/>;</item> /// <item>The <paramref name="signalFloodingProbability"/> is larger than <paramref name="maximumAllowableFloodingProbability"/>.</item> /// </list> /// </exception> /// <exception cref="InvalidEnumArgumentException">Thrown when <paramref name="composition"/> /// is not a valid enum value of <see cref="AssessmentSectionComposition"/>.</exception> /// <exception cref="NotSupportedException">Thrown when <paramref name="composition"/> /// is not supported.</exception> public AssessmentSection(AssessmentSectionComposition composition, double maximumAllowableFloodingProbability = defaultFloodingProbability, double signalFloodingProbability = defaultFloodingProbability) { Name = Resources.AssessmentSection_DisplayName; Comments = new Comment(); BackgroundData = new BackgroundData(new WellKnownBackgroundDataConfiguration(defaultWellKnownTileSource)) { Name = defaultWellKnownTileSource.GetDisplayName() }; ReferenceLine = new ReferenceLine(); HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); SpecificFailureMechanisms = new ObservableList <SpecificFailureMechanism>(); waterLevelCalculationsForSignalFloodingProbability = new ObservableList <HydraulicBoundaryLocationCalculation>(); waterLevelCalculationsForMaximumAllowableFloodingProbability = new ObservableList <HydraulicBoundaryLocationCalculation>(); WaterLevelCalculationsForUserDefinedTargetProbabilities = new ObservableList <HydraulicBoundaryLocationCalculationsForTargetProbability>(); WaveHeightCalculationsForUserDefinedTargetProbabilities = new ObservableList <HydraulicBoundaryLocationCalculationsForTargetProbability>(); Piping = new PipingFailureMechanism(); GrassCoverErosionInwards = new GrassCoverErosionInwardsFailureMechanism(); MacroStabilityInwards = new MacroStabilityInwardsFailureMechanism(); Microstability = new MicrostabilityFailureMechanism(); StabilityStoneCover = new StabilityStoneCoverFailureMechanism(); WaveImpactAsphaltCover = new WaveImpactAsphaltCoverFailureMechanism(); WaterPressureAsphaltCover = new WaterPressureAsphaltCoverFailureMechanism(); GrassCoverErosionOutwards = new GrassCoverErosionOutwardsFailureMechanism(); GrassCoverSlipOffOutwards = new GrassCoverSlipOffOutwardsFailureMechanism(); GrassCoverSlipOffInwards = new GrassCoverSlipOffInwardsFailureMechanism(); HeightStructures = new HeightStructuresFailureMechanism(); ClosingStructures = new ClosingStructuresFailureMechanism(); StabilityPointStructures = new StabilityPointStructuresFailureMechanism(); PipingStructure = new PipingStructureFailureMechanism(); DuneErosion = new DuneErosionFailureMechanism(); FailureMechanismContribution = new FailureMechanismContribution(maximumAllowableFloodingProbability, signalFloodingProbability); ChangeComposition(composition); }
public void Create_WithCollector_ReturnsAssessmentSectionEntityWithCompositionAndFailureMechanisms(AssessmentSectionComposition assessmentSectionComposition) { // Setup const string testId = "testId"; const string testName = "testName"; const string comments = "Some text"; const double maximumAllowableFloodingProbability = 0.05; const double signalFloodingProbability = 0.02; var random = new Random(65); const string mapDataName = "map data name"; const double transparency = 0.3; const bool isVisible = true; const BackgroundDataType backgroundType = BackgroundDataType.Wmts; var normativeProbabilityType = random.NextEnumValue <NormativeProbabilityType>(); IEnumerable <SpecificFailureMechanism> specificFailureMechanisms = Enumerable.Repeat(new SpecificFailureMechanism(), random.Next(1, 10)) .ToArray(); var assessmentSection = new AssessmentSection(assessmentSectionComposition) { Id = testId, Name = testName, Comments = { Body = comments }, FailureMechanismContribution = { MaximumAllowableFloodingProbability = maximumAllowableFloodingProbability, SignalFloodingProbability = signalFloodingProbability, NormativeProbabilityType = normativeProbabilityType }, BackgroundData = { Name = mapDataName, Transparency = (RoundedDouble)transparency, IsVisible = isVisible, Configuration = new WmtsBackgroundDataConfiguration(false,null, null, null) } }; assessmentSection.SpecificFailureMechanisms.AddRange(specificFailureMechanisms); var registry = new PersistenceRegistry(); // Call AssessmentSectionEntity entity = assessmentSection.Create(registry); // Assert Assert.IsNotNull(entity); Assert.AreEqual(Convert.ToByte(assessmentSectionComposition), entity.Composition); Assert.AreEqual(testId, entity.Id); Assert.AreEqual(testName, entity.Name); Assert.AreEqual(comments, entity.Comments); Assert.AreEqual(maximumAllowableFloodingProbability, entity.MaximumAllowableFloodingProbability); Assert.AreEqual(signalFloodingProbability, entity.SignalFloodingProbability); Assert.AreEqual(Convert.ToByte(normativeProbabilityType), entity.NormativeProbabilityType); Assert.AreEqual(15, entity.FailureMechanismEntities.Count); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.Piping)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.GrassRevetmentTopErosionAndInwards)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.MacroStabilityInwards)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.Microstability)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.StabilityStoneRevetment)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.WaveImpactOnAsphaltRevetment)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.WaterOverpressureAsphaltRevetment)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.GrassRevetmentErosionOutwards)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.GrassRevetmentSlidingOutwards)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.GrassRevetmentSlidingInwards)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.StructureHeight)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.ReliabilityClosingOfStructure)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.PipingAtStructure)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.StabilityPointStructures)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.DuneErosion)); Assert.AreEqual(assessmentSection.SpecificFailureMechanisms.Count, entity.SpecificFailureMechanismEntities.Count); Assert.IsNull(entity.ReferenceLinePointXml); Assert.AreEqual(1, entity.BackgroundDataEntities.Count); BackgroundDataEntity backgroundDataEntity = entity.BackgroundDataEntities.Single(); Assert.IsNotNull(backgroundDataEntity); Assert.AreEqual(mapDataName, backgroundDataEntity.Name); Assert.AreEqual(transparency, backgroundDataEntity.Transparency); Assert.AreEqual(Convert.ToByte(isVisible), backgroundDataEntity.IsVisible); Assert.AreEqual(Convert.ToByte(backgroundType), backgroundDataEntity.BackgroundDataType); Assert.AreEqual(1, backgroundDataEntity.BackgroundDataMetaEntities.Count); BackgroundDataMetaEntity isConfiguredMetaEntity = backgroundDataEntity.BackgroundDataMetaEntities.Single(); Assert.AreEqual("IsConfigured", isConfiguredMetaEntity.Key); Assert.AreEqual("0", isConfiguredMetaEntity.Value); }
public void ChangeComposition_InAssemblyChanged_CloseViewsForNotInAssemblyFailureMechanisms(AssessmentSectionComposition oldComposition, AssessmentSectionComposition newComposition, int expectedNumberOfCalls) { // Setup var mocks = new MockRepository(); var viewCommands = mocks.StrictMock <IViewCommands>(); viewCommands.Expect(vc => vc.RemoveAllViewsForItem(Arg <IFailureMechanism> .Matches(fm => !fm.InAssembly))) .Repeat.Times(expectedNumberOfCalls); mocks.ReplayAll(); var assessmentSection = new AssessmentSection(oldComposition); var handler = new AssessmentSectionCompositionChangeHandler(viewCommands); // Call handler.ChangeComposition(assessmentSection, newComposition); // Assert mocks.VerifyAll(); }
public void ChangeComposition_SetNewValue_ChangesCompositionAndReturnAffectedObjects(AssessmentSectionComposition oldComposition, AssessmentSectionComposition newComposition) { // Setup var mocks = new MockRepository(); var viewCommands = mocks.Stub <IViewCommands>(); mocks.ReplayAll(); var assessmentSection = new AssessmentSection(oldComposition); var handler = new AssessmentSectionCompositionChangeHandler(viewCommands); // Call IEnumerable <IObservable> affectedObjects = handler.ChangeComposition(assessmentSection, newComposition); // Assert IEnumerable <IObservable> expectedAffectedObjects = new List <IObservable>(assessmentSection.GetFailureMechanisms()) { assessmentSection, assessmentSection.FailureMechanismContribution }; CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); mocks.VerifyAll(); }
public void Constructor_ExpectedValues(AssessmentSectionComposition composition) { // Call var assessmentSection = new AssessmentSection(composition); // Assert Assert.IsInstanceOf <Observable>(assessmentSection); Assert.IsInstanceOf <IAssessmentSection>(assessmentSection); Assert.AreEqual("Traject", assessmentSection.Name); Assert.IsNull(assessmentSection.Comments.Body); Assert.AreEqual(composition, assessmentSection.Composition); Assert.IsInstanceOf <FailureMechanismContribution>(assessmentSection.FailureMechanismContribution); ReferenceLine referenceLine = assessmentSection.ReferenceLine; Assert.IsNotNull(referenceLine); CollectionAssert.IsEmpty(referenceLine.Points); HydraulicBoundaryDatabase hydraulicBoundaryDatabase = assessmentSection.HydraulicBoundaryDatabase; Assert.IsNotNull(hydraulicBoundaryDatabase); CollectionAssert.IsEmpty(hydraulicBoundaryDatabase.Locations); Assert.IsNull(hydraulicBoundaryDatabase.FilePath); Assert.IsNull(hydraulicBoundaryDatabase.Version); Assert.IsFalse(hydraulicBoundaryDatabase.HydraulicLocationConfigurationSettings.CanUsePreprocessor); CollectionAssert.IsEmpty(assessmentSection.SpecificFailureMechanisms); CollectionAssert.IsEmpty(assessmentSection.WaterLevelCalculationsForSignalFloodingProbability); CollectionAssert.IsEmpty(assessmentSection.WaterLevelCalculationsForMaximumAllowableFloodingProbability); CollectionAssert.IsEmpty(assessmentSection.WaterLevelCalculationsForUserDefinedTargetProbabilities); CollectionAssert.IsEmpty(assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities); CollectionAssert.IsEmpty(assessmentSection.Piping.StochasticSoilModels); CollectionAssert.IsEmpty(assessmentSection.Piping.SurfaceLines); Assert.NotNull(assessmentSection.Piping); Assert.NotNull(assessmentSection.GrassCoverErosionInwards); Assert.NotNull(assessmentSection.MacroStabilityInwards); Assert.NotNull(assessmentSection.Microstability); Assert.NotNull(assessmentSection.StabilityStoneCover); Assert.NotNull(assessmentSection.WaveImpactAsphaltCover); Assert.NotNull(assessmentSection.WaterPressureAsphaltCover); Assert.NotNull(assessmentSection.GrassCoverErosionOutwards); Assert.NotNull(assessmentSection.GrassCoverSlipOffOutwards); Assert.NotNull(assessmentSection.GrassCoverSlipOffInwards); Assert.NotNull(assessmentSection.HeightStructures); Assert.NotNull(assessmentSection.ClosingStructures); Assert.NotNull(assessmentSection.PipingStructure); Assert.NotNull(assessmentSection.StabilityPointStructures); Assert.NotNull(assessmentSection.DuneErosion); BackgroundData backgroundData = assessmentSection.BackgroundData; Assert.IsTrue(backgroundData.IsVisible); Assert.AreEqual(0.60, backgroundData.Transparency, backgroundData.Transparency.GetAccuracy()); Assert.AreEqual("Bing Maps - Satelliet", backgroundData.Name); var configuration = (WellKnownBackgroundDataConfiguration)backgroundData.Configuration; Assert.AreEqual(RiskeerWellKnownTileSource.BingAerial, configuration.WellKnownTileSource); }
public IEnumerable <IObservable> ChangeComposition(IAssessmentSection assessmentSection, AssessmentSectionComposition newComposition) { if (assessmentSection == null) { throw new ArgumentNullException(nameof(assessmentSection)); } Dictionary <IFailureMechanism, bool> oldFailureMechanismsInAssembly = assessmentSection.GetFailureMechanisms().ToDictionary(f => f, f => f.InAssembly, new ReferenceEqualityComparer <IFailureMechanism>()); var affectedObjects = new List <IObservable>(); if (assessmentSection.Composition != newComposition) { assessmentSection.ChangeComposition(newComposition); affectedObjects.Add(assessmentSection); affectedObjects.Add(assessmentSection.FailureMechanismContribution); affectedObjects.AddRange(assessmentSection.GetFailureMechanisms()); CloseViewsForFailureMechanismsNotPartOfAssembly(GetFailureMechanismsWithInAssemblyUpdated(oldFailureMechanismsInAssembly)); } return(affectedObjects); }
public void ChangeComposition(AssessmentSectionComposition newComposition) { throw new NotImplementedException("Stub only verifies Observable and basic behavior, use a proper stub when this function is necessary."); }