public void UpdateStructuresWithImportedData_SingleChange_UpdatesOnlySingleChange(ClosingStructure readStructure) { // Setup ClosingStructure structure = new TestClosingStructure(); var failureMechanism = new ClosingStructuresFailureMechanism(); StructureCollection <ClosingStructure> targetCollection = failureMechanism.ClosingStructures; targetCollection.AddRange(new[] { structure }, sourceFilePath); var strategy = new ClosingStructureUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(new[] { readStructure }, sourceFilePath); // Assert AssertClosingStructures(readStructure, structure); CollectionAssert.AreEqual(new IObservable[] { targetCollection, structure }, affectedObjects); }
public void Create_WithClosingStructures_ClosingStructureEntitiesCreated() { // Setup ClosingStructure structure = new TestClosingStructure(); var failureMechanism = new ClosingStructuresFailureMechanism(); const string filePath = "some path"; failureMechanism.ClosingStructures.AddRange(new[] { structure }, filePath); var persistenceRegistry = new PersistenceRegistry(); // Call FailureMechanismEntity entity = failureMechanism.Create(persistenceRegistry); // Assert Assert.AreEqual(1, entity.ClosingStructureEntities.Count); Assert.IsTrue(persistenceRegistry.Contains(structure)); ClosingStructuresFailureMechanismMetaEntity metaEntity = entity.ClosingStructuresFailureMechanismMetaEntities.Single(); string entitySourcePath = metaEntity.ClosingStructureCollectionSourcePath; TestHelper.AssertAreEqualButNotSame(filePath, entitySourcePath); }
public void UpdateStructuresWithImportedData_WithCurrentStructuresAndImportedHasNoOverlap_UpdatesTargetCollection() { // Setup var targetStructure = new TestClosingStructure("target id"); var failureMechanism = new ClosingStructuresFailureMechanism(); StructureCollection <ClosingStructure> structures = failureMechanism.ClosingStructures; structures.AddRange(new[] { targetStructure }, sourceFilePath); var readStructure = new TestClosingStructure("read id"); TestClosingStructure[] importedStructures = { readStructure }; var strategy = new ClosingStructureUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(importedStructures, sourceFilePath); // Assert CollectionAssert.AreEqual(importedStructures, structures); Assert.AreSame(readStructure, structures[0]); CollectionAssert.AreEquivalent(new IObservable[] { structures }, affectedObjects); }
public void ContextMenuStrip_Always_CallsContextMenuBuilderMethods() { // Setup var menuBuilder = mocks.StrictMock <IContextMenuBuilder>(); using (mocks.Ordered()) { menuBuilder.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilder); menuBuilder.Expect(mb => mb.Build()).Return(null); } using (var treeViewControl = new TreeViewControl()) { ClosingStructure nodeData = new TestClosingStructure(); var gui = mocks.Stub <IGui>(); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); mocks.ReplayAll(); plugin.Gui = gui; // Call info.ContextMenuStrip(nodeData, null, treeViewControl); } // Assert // Assert expectancies are called in TearDown() }
public void ChildNodeObjects_Always_ReturnClosingStructures() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); ClosingStructure closingStructure1 = new TestClosingStructure("structure1"); ClosingStructure closingStructure2 = new TestClosingStructure("structure2"); var failureMechanism = new ClosingStructuresFailureMechanism(); failureMechanism.ClosingStructures.AddRange(new[] { closingStructure1, closingStructure2 }, "some path"); var closingStructuresContext = new ClosingStructuresContext(failureMechanism.ClosingStructures, failureMechanism, assessmentSection); // Call object[] children = info.ChildNodeObjects(closingStructuresContext); // Assert Assert.AreEqual(2, children.Length); Assert.AreSame(closingStructure1, children.ElementAt(0)); Assert.AreSame(closingStructure2, children.ElementAt(1)); mocks.VerifyAll(); }
public void UpdateStructuresWithImportedData_WithCurrentStructureAndImportedMultipleStructuresWithSameId_ThrowsUpdateDataException() { // Setup const string duplicateId = "I am a duplicate id"; var expectedStructure = new TestClosingStructure(duplicateId, "expectedStructure"); TestClosingStructure[] expectedCollection = { expectedStructure }; var targetCollection = new StructureCollection <ClosingStructure>(); targetCollection.AddRange(expectedCollection, sourceFilePath); var readStructures = new[] { new TestClosingStructure(duplicateId, "Structure"), new TestClosingStructure(duplicateId, "Other structure") }; var strategy = new ClosingStructureUpdateDataStrategy(new ClosingStructuresFailureMechanism()); // Call void Call() => strategy.UpdateStructuresWithImportedData(readStructures, sourceFilePath); // Assert var exception = Assert.Throws <UpdateDataException>(Call); const string expectedMessage = "Geïmporteerde data moet unieke elementen bevatten."; Assert.AreEqual(expectedMessage, exception.Message); CollectionAssert.AreEqual(expectedCollection, targetCollection); }
public void UpdateStructuresWithImportedData_WithCurrentAndImportedDataAreDifferent_ReplacesCurrentWithImportedData() { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); failureMechanism.ClosingStructures.AddRange(new[] { new TestClosingStructure("id", "Original") }, sourceFilePath); var importedStructure = new TestClosingStructure("Different id", "Imported"); var strategy = new ClosingStructureReplaceDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(new[] { importedStructure }, sourceFilePath); // Assert CollectionAssert.AreEqual(new[] { failureMechanism.ClosingStructures }, affectedObjects); TestClosingStructure[] expected = { importedStructure }; CollectionAssert.AreEqual(expected, failureMechanism.ClosingStructures); }
public void Import_EmptyConfigurations_DataAddedToModel(string file) { // Setup string filePath = Path.Combine(importerPath, file); var calculationGroup = new CalculationGroup(); var structure = new TestClosingStructure("kunstwerk1", "kunstwerk1"); var importer = new ClosingStructuresCalculationConfigurationImporter( filePath, calculationGroup, Enumerable.Empty <HydraulicBoundaryLocation>(), Enumerable.Empty <ForeshoreProfile>(), new[] { structure }); var expectedCalculation = new StructuresCalculationScenario <ClosingStructuresInput> { Name = "Berekening 1" }; // Call bool successful = importer.Import(); // Assert Assert.IsTrue(successful); Assert.AreEqual(1, calculationGroup.Children.Count); AssertCalculation(expectedCalculation, (StructuresCalculationScenario <ClosingStructuresInput>)calculationGroup.Children[0]); }
public void Import_ValidConfigurationInvalidData_LogMessageAndContinueImport(string file, string expectedErrorMessage) { // Setup string filePath = Path.Combine(importerPath, file); var calculationGroup = new CalculationGroup(); var structure = new TestClosingStructure("kunstwerk1", "kunstwerk1"); var foreshoreProfile = new TestForeshoreProfile("profiel 1"); var importer = new ClosingStructuresCalculationConfigurationImporter(filePath, calculationGroup, Enumerable.Empty <HydraulicBoundaryLocation>(), new ForeshoreProfile[] { foreshoreProfile }, new ClosingStructure[] { structure }); var successful = false; // Call void Call() => successful = importer.Import(); // Assert string expectedMessage = $"{expectedErrorMessage} Berekening 'Berekening 1' is overgeslagen."; TestHelper.AssertLogMessageWithLevelIsGenerated(Call, Tuple.Create(expectedMessage, LogLevelConstant.Error), 2); Assert.IsTrue(successful); CollectionAssert.IsEmpty(calculationGroup.Children); }
public void Structure_NotNull_ExpectedValues() { // Setup var input = new ClosingStructuresInput(); var structure = new TestClosingStructure(); // Call input.Structure = structure; // Assert AssertClosingStructureInput(structure, input); }
public void UpdateStructuresWithImportedData_SectionResultWithStructureImportedStructureWithSameIdRemoved_UpdatesCalculationInput() { // Setup const string sameId = "id"; var originalMatchingPoint = new Point2D(0, 0); ClosingStructure removedStructure = new TestClosingStructure(originalMatchingPoint, sameId); var calculation = new TestClosingStructuresCalculationScenario { InputParameters = { Structure = removedStructure } }; var failureMechanism = new ClosingStructuresFailureMechanism { CalculationsGroup = { Children = { calculation } } }; failureMechanism.ClosingStructures.AddRange(new[] { removedStructure }, sourceFilePath); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[] { originalMatchingPoint, new Point2D(10, 10) }) }); var strategy = new ClosingStructureUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(Enumerable.Empty <ClosingStructure>(), sourceFilePath); // Assert CollectionAssert.AreEqual(new IObservable[] { failureMechanism.ClosingStructures, calculation.InputParameters }, affectedObjects); }
public void Text_Always_ReturnNameOfStructure() { // Setup mocks.ReplayAll(); const string name = "very nice name!"; ClosingStructure structure = new TestClosingStructure("id", name); // Call string text = info.Text(structure); // Assert Assert.AreEqual(name, text); }
public void Create_PersistenceRegistryNull_ThrowArgumentNullException() { // Setup ClosingStructure structure = new TestClosingStructure(); // Call TestDelegate call = () => structure.Create(null, 0); // Assert string paramName = Assert.Throws <ArgumentNullException>(call).ParamName; Assert.AreEqual("registry", paramName); }
public void UpdateStructuresWithImportedData_CalculationWithSameReference_OnlyReturnsDistinctCalculationInput() { // Setup const string affectedId = "affectedId"; var affectedStructure = new TestClosingStructure(affectedId, "Old name"); var affectedCalculation = new TestClosingStructuresCalculationScenario { InputParameters = { Structure = affectedStructure }, Output = new TestStructuresOutput() }; var failureMechanism = new ClosingStructuresFailureMechanism { CalculationsGroup = { Children = { affectedCalculation, affectedCalculation } } }; StructureCollection <ClosingStructure> structures = failureMechanism.ClosingStructures; structures.AddRange(new[] { affectedStructure }, sourceFilePath); var structureToUpdateFrom = new TestClosingStructure(affectedId, "New name"); var strategy = new ClosingStructureUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(new[] { structureToUpdateFrom }, sourceFilePath); // Assert CollectionAssert.AreEquivalent(new IObservable[] { structures, affectedStructure, affectedCalculation.InputParameters }, affectedObjects); }
public void UpdateStructuresWithImportedData_CalculationWithStructureImportedStructureWithSameId_UpdatesCalculationInput() { // Setup const string sameId = "sameId"; ClosingStructure readStructure = new TestClosingStructure(sameId, "new structure"); ClosingStructure structure = new TestClosingStructure(sameId, "original structure"); var calculation = new TestClosingStructuresCalculationScenario { InputParameters = { Structure = structure }, Output = new TestStructuresOutput() }; var failureMechanism = new ClosingStructuresFailureMechanism { CalculationsGroup = { Children = { calculation } } }; failureMechanism.ClosingStructures.AddRange(new[] { structure }, sourceFilePath); var strategy = new ClosingStructureUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(new[] { readStructure }, sourceFilePath); // Assert Assert.IsTrue(calculation.HasOutput); AssertClosingStructures(readStructure, structure); CollectionAssert.AreEqual(new IObservable[] { failureMechanism.ClosingStructures, structure, calculation.InputParameters }, affectedObjects); }
public void UpdateStructuresWithImportedData_CalculationWithRemovedStructure_UpdatesCalculation() { // Setup const string sameId = "sameId"; ClosingStructure structure = new TestClosingStructure(sameId, "original structure"); var calculation = new TestClosingStructuresCalculationScenario { InputParameters = { Structure = structure }, Output = new TestStructuresOutput() }; var failureMechanism = new ClosingStructuresFailureMechanism { CalculationsGroup = { Children = { calculation } } }; StructureCollection <ClosingStructure> targetDataCollection = failureMechanism.ClosingStructures; targetDataCollection.AddRange(new[] { structure }, sourceFilePath); var strategy = new ClosingStructureUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(Enumerable.Empty <ClosingStructure>(), sourceFilePath); // Assert Assert.IsFalse(calculation.HasOutput); Assert.IsNull(calculation.InputParameters.Structure); CollectionAssert.AreEqual(new IObservable[] { targetDataCollection, calculation, calculation.InputParameters }, affectedObjects); }
public void Read_EntityRegistered_ReturnRegisteredStructure() { // Setup var entity = new ClosingStructureEntity(); ClosingStructure registeredStructure = new TestClosingStructure(); var collector = new ReadConversionCollector(); collector.Read(entity, registeredStructure); // Call ClosingStructure readStructure = entity.Read(collector); // Assert Assert.AreSame(registeredStructure, readStructure); }
public void IsStructureInputSynchronized_StructureAndInputInSync_ReturnTrue() { // Setup var structure = new TestClosingStructure(); var input = new ClosingStructuresInput { Structure = structure }; // Call bool isStructureInputSynchronized = input.IsStructureInputSynchronized; // Assert Assert.IsTrue(isStructureInputSynchronized); }
public void Create_StructureAlreadyRegistered_ReturnRegisteredEntity() { // Setup ClosingStructure structure = new TestClosingStructure(); var registeredEntity = new ClosingStructureEntity(); var registry = new PersistenceRegistry(); registry.Register(registeredEntity, structure); // Call ClosingStructureEntity entity = structure.Create(registry, 0); // Assert Assert.AreSame(registeredEntity, entity); }
public void Create_ValidStructure_ReturnEntity() { // Setup ClosingStructure structure = new TestClosingStructure(); var registry = new PersistenceRegistry(); const int order = 4; // Call ClosingStructureEntity entity = structure.Create(registry, order); // Assert Assert.AreEqual(structure.Name, entity.Name); Assert.AreNotSame(structure.Name, entity.Name); Assert.AreEqual(structure.Id, entity.Id); Assert.AreNotSame(structure.Id, entity.Id); Assert.AreEqual(structure.Location.X, entity.X); Assert.AreEqual(structure.Location.Y, entity.Y); Assert.AreEqual(structure.StructureNormalOrientation.Value, entity.StructureNormalOrientation); Assert.AreEqual(structure.StorageStructureArea.Mean.Value, entity.StorageStructureAreaMean); Assert.AreEqual(structure.StorageStructureArea.CoefficientOfVariation.Value, entity.StorageStructureAreaCoefficientOfVariation); Assert.AreEqual(structure.AllowedLevelIncreaseStorage.Mean.Value, entity.AllowedLevelIncreaseStorageMean); Assert.AreEqual(structure.AllowedLevelIncreaseStorage.StandardDeviation.Value, entity.AllowedLevelIncreaseStorageStandardDeviation); Assert.AreEqual(structure.WidthFlowApertures.Mean.Value, entity.WidthFlowAperturesMean); Assert.AreEqual(structure.WidthFlowApertures.StandardDeviation.Value, entity.WidthFlowAperturesStandardDeviation); Assert.AreEqual(structure.LevelCrestStructureNotClosing.Mean.Value, entity.LevelCrestStructureNotClosingMean); Assert.AreEqual(structure.LevelCrestStructureNotClosing.StandardDeviation.Value, entity.LevelCrestStructureNotClosingStandardDeviation); Assert.AreEqual(structure.InsideWaterLevel.Mean.Value, entity.InsideWaterLevelMean); Assert.AreEqual(structure.InsideWaterLevel.StandardDeviation.Value, entity.InsideWaterLevelStandardDeviation); Assert.AreEqual(structure.ThresholdHeightOpenWeir.Mean.Value, entity.ThresholdHeightOpenWeirMean); Assert.AreEqual(structure.ThresholdHeightOpenWeir.StandardDeviation.Value, entity.ThresholdHeightOpenWeirStandardDeviation); Assert.AreEqual(structure.AreaFlowApertures.Mean.Value, entity.AreaFlowAperturesMean); Assert.AreEqual(structure.AreaFlowApertures.StandardDeviation.Value, entity.AreaFlowAperturesStandardDeviation); Assert.AreEqual(structure.CriticalOvertoppingDischarge.Mean.Value, entity.CriticalOvertoppingDischargeMean); Assert.AreEqual(structure.CriticalOvertoppingDischarge.CoefficientOfVariation.Value, entity.CriticalOvertoppingDischargeCoefficientOfVariation); Assert.AreEqual(structure.FlowWidthAtBottomProtection.Mean.Value, entity.FlowWidthAtBottomProtectionMean); Assert.AreEqual(structure.FlowWidthAtBottomProtection.StandardDeviation.Value, entity.FlowWidthAtBottomProtectionStandardDeviation); Assert.AreEqual(structure.ProbabilityOpenStructureBeforeFlooding, entity.ProbabilityOpenStructureBeforeFlooding); Assert.AreEqual(structure.FailureProbabilityOpenStructure, entity.FailureProbabilityOpenStructure); Assert.AreEqual(structure.IdenticalApertures, entity.IdenticalApertures); Assert.AreEqual(structure.FailureProbabilityReparation, entity.FailureProbabilityReparation); Assert.AreEqual(Convert.ToByte(structure.InflowModelType), entity.InflowModelType); Assert.AreEqual(order, entity.Order); Assert.IsTrue(registry.Contains(structure)); }
public void IsStructureInputSynchronized_StructureAndInputNotInSync_ReturnFalse(ClosingStructure modifiedStructure) { // Setup var structure = new TestClosingStructure(); var input = new ClosingStructuresInput { Structure = structure }; structure.CopyProperties(modifiedStructure); // Call bool isStructureInputSynchronized = input.IsStructureInputSynchronized; // Assert Assert.IsFalse(isStructureInputSynchronized); }
public void UpdateStructuresWithImportedData_CalculationWithOutputAndStructure_CalculationUpdatedAndReturnsAffectedObject() { // Setup var structure = new TestClosingStructure(); var calculation = new TestClosingStructuresCalculationScenario { InputParameters = { Structure = structure }, Output = new TestStructuresOutput() }; var failureMechanism = new ClosingStructuresFailureMechanism { CalculationsGroup = { Children = { calculation } } }; failureMechanism.ClosingStructures.AddRange(new[] { structure }, sourceFilePath); var strategy = new ClosingStructureReplaceDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(Enumerable.Empty <ClosingStructure>(), sourceFilePath).ToArray(); // Assert Assert.IsFalse(calculation.HasOutput); Assert.IsNull(calculation.InputParameters.Structure); CollectionAssert.AreEquivalent(new IObservable[] { calculation, calculation.InputParameters, failureMechanism.ClosingStructures }, affectedObjects); }
private void ShowFullyConfiguredClosingStructuresScenariosView() { var structure1 = new TestClosingStructure(new Point2D(0.0, 0.0)); var structure2 = new TestClosingStructure(new Point2D(5.0, 0.0)); var failureMechanism = new ClosingStructuresFailureMechanism(); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { new FailureMechanismSection("Section 1", new[] { new Point2D(0.0, 0.0), new Point2D(5.0, 0.0) }), new FailureMechanismSection("Section 2", new[] { new Point2D(5.0, 0.0), new Point2D(10.0, 0.0) }) }); failureMechanism.CalculationsGroup.Children.AddRange(new[] { new StructuresCalculationScenario <ClosingStructuresInput> { Name = "Calculation 1", InputParameters = { Structure = structure1 } }, new StructuresCalculationScenario <ClosingStructuresInput> { Name = "Calculation 2", InputParameters = { Structure = structure2 }, Output = new TestStructuresOutput(0.2) } }); ShowClosingStructuresScenariosView(failureMechanism); }
public void UpdateStructuresWithImportedData_WithCurrentStructuresAndImportedHasPartialOverlap_UpdatesTargetCollection() { // Setup const string commonId = "common id"; var updatedStructure = new TestClosingStructure(commonId, "old name"); var removedStructure = new TestClosingStructure("removed id"); var failureMechanism = new ClosingStructuresFailureMechanism(); StructureCollection <ClosingStructure> structures = failureMechanism.ClosingStructures; structures.AddRange(new[] { removedStructure, updatedStructure }, sourceFilePath); var structureToUpdateFrom = new TestClosingStructure(commonId, "new name"); var addedStructure = new TestClosingStructure("added id"); TestClosingStructure[] importedStructures = { structureToUpdateFrom, addedStructure }; var strategy = new ClosingStructureUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(importedStructures, sourceFilePath); // Assert Assert.AreEqual(2, structures.Count); Assert.AreSame(updatedStructure, structures[0]); AssertClosingStructures(structureToUpdateFrom, updatedStructure); Assert.AreSame(addedStructure, structures[1]); CollectionAssert.AreEquivalent(new IObservable[] { updatedStructure, structures }, affectedObjects); }
public void Read_EntityWithStructureEntity_ReturnCalculationWithStructure() { // Setup ClosingStructure structure = new TestClosingStructure(); var structureEntity = new ClosingStructureEntity(); var entity = new ClosingStructuresCalculationEntity { ClosingStructureEntity = structureEntity, IdenticalApertures = 1, ScenarioContribution = 0 }; var collector = new ReadConversionCollector(); collector.Read(structureEntity, structure); // Call StructuresCalculationScenario <ClosingStructuresInput> calculation = entity.Read(collector); // Assert Assert.AreSame(structure, calculation.InputParameters.Structure); }
public void GivenViewWithStructureData_WhenStructureUpdatedAndNotified_ThenMapDataUpdated() { // Given var structure = new TestClosingStructure(new Point2D(0, 0), "Id"); var failureMechanism = new ClosingStructuresFailureMechanism(); failureMechanism.ClosingStructures.AddRange(new[] { structure }, "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 structure.CopyProperties(new TestClosingStructure(new Point2D(1, 1), "Id")); structure.NotifyObservers(); // Then MapDataTestHelper.AssertStructuresMapData(failureMechanism.ClosingStructures, structuresData); mocks.VerifyAll(); }
public void UpdateStructuresWithImportedData_SectionResultWithStructureImportedStructureWithSameId_UpdatesCalculationInput() { // Setup const string sameId = "sameId"; var originalMatchingPoint = new Point2D(0, 0); var updatedMatchingPoint = new Point2D(20, 20); ClosingStructure readStructure = new TestClosingStructure(updatedMatchingPoint, sameId); ClosingStructure structure = new TestClosingStructure(originalMatchingPoint, sameId); var calculation = new TestClosingStructuresCalculationScenario { InputParameters = { Structure = structure } }; var failureMechanism = new ClosingStructuresFailureMechanism { CalculationsGroup = { Children = { calculation } } }; failureMechanism.ClosingStructures.AddRange(new[] { structure }, sourceFilePath); var intersectionPoint = new Point2D(10, 10); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { new FailureMechanismSection("OldSection", new[] { originalMatchingPoint, intersectionPoint }), new FailureMechanismSection("NewSection", new[] { intersectionPoint, updatedMatchingPoint }) }); var strategy = new ClosingStructureUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(new[] { readStructure }, sourceFilePath); // Assert AssertClosingStructures(readStructure, structure); CollectionAssert.AreEqual(new IObservable[] { failureMechanism.ClosingStructures, structure, calculation.InputParameters }, affectedObjects); }
private ClosingStructuresFailureMechanism CreateFullyConfiguredFailureMechanism() { var section1 = new FailureMechanismSection("A", new[] { new Point2D(-1, 0), new Point2D(2, 0) }); var section2 = new FailureMechanismSection("B", new[] { new Point2D(2, 0), new Point2D(4, 0) }); var structure1 = new TestClosingStructure(new Point2D(1, 0), "structure1"); var structure2 = new TestClosingStructure(new Point2D(3, 0), "structure2"); var profile = new TestForeshoreProfile(); StructuresCalculation <ClosingStructuresInput> calculation1 = new TestClosingStructuresCalculationScenario { InputParameters = { ForeshoreProfile = profile, Structure = structure1 }, Output = new TestStructuresOutput() }; StructuresCalculation <ClosingStructuresInput> calculation2 = new TestClosingStructuresCalculationScenario { InputParameters = { ForeshoreProfile = profile, Structure = structure2 } }; StructuresCalculation <ClosingStructuresInput> calculation3 = new TestClosingStructuresCalculationScenario { InputParameters = { ForeshoreProfile = profile, Structure = structure1 } }; var failureMechanism = new ClosingStructuresFailureMechanism { CalculationsGroup = { Children = { calculation1, new CalculationGroup { Children = { calculation2 } }, calculation3 } } }; failureMechanism.ClosingStructures.AddRange(new[] { structure1, structure2 }, "some path"); failureMechanism.ForeshoreProfiles.AddRange(new[] { profile }, "path"); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { section1, section2 }); return(failureMechanism); }
public void RemoveStructure_FullyConfiguredFailureMechanism_RemovesStructureAndClearsDependentData() { // Setup var failureMechanism = new ClosingStructuresFailureMechanism(); var structureToRemove = new TestClosingStructure(new Point2D(0, 0), "id1"); var structureToKeep = new TestClosingStructure(new Point2D(2, 2), "id2"); failureMechanism.ClosingStructures.AddRange(new[] { structureToRemove, structureToKeep }, "path/to/structures"); var calculationWithOutput = new TestClosingStructuresCalculationScenario { Output = new TestStructuresOutput() }; var calculationWithStructureToRemove = new TestClosingStructuresCalculationScenario { InputParameters = { Structure = structureToRemove } }; var calculationWithStructureToKeepAndOutput = new TestClosingStructuresCalculationScenario { InputParameters = { Structure = structureToKeep }, Output = new TestStructuresOutput() }; var calculationWithStructureToRemoveAndOutput = new TestClosingStructuresCalculationScenario { InputParameters = { Structure = structureToRemove }, Output = new TestStructuresOutput() }; failureMechanism.CalculationsGroup.Children.AddRange(new[] { calculationWithOutput, calculationWithStructureToRemove, calculationWithStructureToKeepAndOutput, calculationWithStructureToRemoveAndOutput }); // Call IEnumerable <IObservable> affectedObjects = ClosingStructuresDataSynchronizationService.RemoveStructure( structureToRemove, failureMechanism); // Assert // Note: To make sure the clear is performed regardless of what is done with // the return result, no ToArray() should be called before these assertions: CollectionAssert.DoesNotContain(failureMechanism.ClosingStructures, structureToRemove); Assert.IsNull(calculationWithStructureToRemove.InputParameters.Structure); Assert.IsNull(calculationWithStructureToRemoveAndOutput.InputParameters.Structure); Assert.IsNull(calculationWithStructureToRemoveAndOutput.Output); Assert.IsNotNull(calculationWithOutput.Output); Assert.IsNotNull(calculationWithStructureToKeepAndOutput.Output); Assert.IsNotNull(calculationWithStructureToKeepAndOutput.InputParameters.Structure); IObservable[] expectedAffectedObjects = { calculationWithStructureToRemove.InputParameters, calculationWithStructureToRemoveAndOutput, calculationWithStructureToRemoveAndOutput.InputParameters, failureMechanism.ClosingStructures }; CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); }
public void GivenInputWithStructure_WhenStructureNull_ThenSchematizationPropertiesSynedToDefaults() { // Given var structure = new TestClosingStructure(); var input = new ClosingStructuresInput { Structure = structure }; RoundedDouble expectedFactorStormDurationOpenStructure = input.FactorStormDurationOpenStructure; NormalDistribution expectedModelFactorSuperCriticalFlow = input.ModelFactorSuperCriticalFlow; LogNormalDistribution expectedDrainCoefficient = input.DrainCoefficient; RoundedDouble expectedDeviationWaveDirection = input.DeviationWaveDirection; double expectedFailureProbabilityStructureWithErosion = input.FailureProbabilityStructureWithErosion; // Precondition AssertClosingStructureInput(structure, input); // When input.Structure = null; // Then Assert.AreEqual(0, input.FailureProbabilityOpenStructure); Assert.AreEqual(0, input.FailureProbabilityReparation); Assert.AreEqual(2, input.FactorStormDurationOpenStructure.NumberOfDecimalPlaces); Assert.AreEqual(expectedFactorStormDurationOpenStructure, input.FactorStormDurationOpenStructure, input.FactorStormDurationOpenStructure.GetAccuracy()); Assert.AreEqual(2, input.DeviationWaveDirection.NumberOfDecimalPlaces); Assert.AreEqual(expectedDeviationWaveDirection, input.DeviationWaveDirection, input.DeviationWaveDirection.GetAccuracy()); DistributionAssert.AreEqual(expectedModelFactorSuperCriticalFlow, input.ModelFactorSuperCriticalFlow); DistributionAssert.AreEqual(expectedDrainCoefficient, input.DrainCoefficient); Assert.AreEqual(expectedFailureProbabilityStructureWithErosion, input.FailureProbabilityStructureWithErosion); var expectedInsideWaterLevel = new NormalDistribution(2) { Mean = RoundedDouble.NaN, StandardDeviation = RoundedDouble.NaN }; var expectedThresholdHeightOpenWeir = new NormalDistribution(2) { Mean = RoundedDouble.NaN, StandardDeviation = RoundedDouble.NaN }; var expectedAreaFlowApertures = new LogNormalDistribution(2) { Mean = RoundedDouble.NaN, StandardDeviation = RoundedDouble.NaN }; var expectedLevelCrestStructureNotClosing = new NormalDistribution(2) { Mean = RoundedDouble.NaN, StandardDeviation = RoundedDouble.NaN }; DistributionAssert.AreEqual(expectedInsideWaterLevel, input.InsideWaterLevel); DistributionAssert.AreEqual(expectedThresholdHeightOpenWeir, input.ThresholdHeightOpenWeir); DistributionAssert.AreEqual(expectedAreaFlowApertures, input.AreaFlowApertures); DistributionAssert.AreEqual(expectedLevelCrestStructureNotClosing, input.LevelCrestStructureNotClosing); Assert.AreEqual(1.0, input.ProbabilityOpenStructureBeforeFlooding); Assert.AreEqual(1, input.IdenticalApertures); Assert.AreEqual(0, (int)input.InflowModelType); }