public void UpdateStructuresWithImportedData_WithCurrentStructureAndImportedMultipleStructuresWithSameId_ThrowsUpdateDataException() { // Setup const string duplicateId = "I am a duplicate id"; var expectedStructure = new TestHeightStructure(duplicateId, "expectedStructure"); TestHeightStructure[] expectedCollection = { expectedStructure }; var targetCollection = new StructureCollection <HeightStructure>(); targetCollection.AddRange(expectedCollection, sourceFilePath); var readStructures = new[] { new TestHeightStructure(duplicateId, "Structure"), new TestHeightStructure(duplicateId, "Other structure") }; var strategy = new HeightStructureUpdateDataStrategy(new HeightStructuresFailureMechanism()); // 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_SingleChange_UpdatesOnlySingleChange(HeightStructure readStructure) { // Setup HeightStructure structure = new TestHeightStructure(); var failureMechanism = new HeightStructuresFailureMechanism(); StructureCollection <HeightStructure> targetCollection = failureMechanism.HeightStructures; targetCollection.AddRange(new[] { structure }, sourceFilePath); var strategy = new HeightStructureUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(new[] { readStructure }, sourceFilePath); // Assert AssertHeightStructures(readStructure, structure); CollectionAssert.AreEqual(new IObservable[] { targetCollection, structure }, affectedObjects); }
public void UpdateStructuresWithImportedData_WithCurrentStructuresAndImportedHasNoOverlap_UpdatesTargetCollection() { // Setup var targetStructure = new TestHeightStructure("target id"); var failureMechanism = new HeightStructuresFailureMechanism(); StructureCollection <HeightStructure> structures = failureMechanism.HeightStructures; structures.AddRange(new[] { targetStructure }, sourceFilePath); var readStructure = new TestHeightStructure("read id"); TestHeightStructure[] importedStructures = { readStructure }; var strategy = new HeightStructureUpdateDataStrategy(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 UpdateStructuresWithImportedData_WithCurrentAndImportedDataAreDifferent_ReplacesCurrentWithImportedData() { // Setup var failureMechanism = new HeightStructuresFailureMechanism(); failureMechanism.HeightStructures.AddRange(new[] { new TestHeightStructure("id", "Original") }, sourceFilePath); var importedStructure = new TestHeightStructure("Different id", "Imported"); var strategy = new HeightStructureReplaceDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(new[] { importedStructure }, sourceFilePath); // Assert CollectionAssert.AreEqual(new[] { failureMechanism.HeightStructures }, affectedObjects); TestHeightStructure[] expected = { importedStructure }; CollectionAssert.AreEqual(expected, failureMechanism.HeightStructures); }
public void Import_EmptyConfigurations_DataAddedToModel(string file) { // Setup string filePath = Path.Combine(importerPath, file); var calculationGroup = new CalculationGroup(); var structure = new TestHeightStructure("kunstwerk1", "kunstwerk1"); var importer = new HeightStructuresCalculationConfigurationImporter( filePath, calculationGroup, Enumerable.Empty <HydraulicBoundaryLocation>(), Enumerable.Empty <ForeshoreProfile>(), new[] { structure }); var expectedCalculation = new StructuresCalculationScenario <HeightStructuresInput> { Name = "Berekening 1" }; // Call bool successful = importer.Import(); // Assert Assert.IsTrue(successful); Assert.AreEqual(1, calculationGroup.Children.Count); AssertCalculation(expectedCalculation, (StructuresCalculationScenario <HeightStructuresInput>)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 TestHeightStructure("kunstwerk1", "kunstwerk1"); var foreshoreProfile = new TestForeshoreProfile("profiel 1"); var importer = new HeightStructuresCalculationConfigurationImporter(filePath, calculationGroup, Enumerable.Empty <HydraulicBoundaryLocation>(), new ForeshoreProfile[] { foreshoreProfile }, new HeightStructure[] { 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 Import_StochastWithStandardDeviationOrVariationCoefficientOnly_DataAddedToModel() { // Setup string filePath = Path.Combine(importerPath, "validConfigurationStochastStandardDeviationVariationCoefficientOnly.xml"); var calculationGroup = new CalculationGroup(); var structure = new TestHeightStructure("kunstwerk1", "kunstwerk1"); var importer = new HeightStructuresCalculationConfigurationImporter( filePath, calculationGroup, Enumerable.Empty <HydraulicBoundaryLocation>(), Enumerable.Empty <ForeshoreProfile>(), new[] { structure }); var expectedCalculation = new StructuresCalculationScenario <HeightStructuresInput> { Name = "Berekening 1", InputParameters = { Structure = structure, FlowWidthAtBottomProtection = { StandardDeviation = (RoundedDouble)0.1 }, WidthFlowApertures = { StandardDeviation = (RoundedDouble)0.1 }, StorageStructureArea = { CoefficientOfVariation = (RoundedDouble)0.01 }, AllowedLevelIncreaseStorage = { StandardDeviation = (RoundedDouble)0.01 }, LevelCrestStructure = { StandardDeviation = (RoundedDouble)0.1 }, CriticalOvertoppingDischarge = { CoefficientOfVariation = (RoundedDouble)0.1 } } }; // Call bool successful = importer.Import(); // Assert Assert.IsTrue(successful); Assert.AreEqual(1, calculationGroup.Children.Count); AssertCalculation(expectedCalculation, (StructuresCalculationScenario <HeightStructuresInput>)calculationGroup.Children[0]); }
public void UpdateStructuresWithImportedData_CalculationWithStructureImportedStructureWithSameId_UpdatesCalculationInput() { // Setup const string sameId = "sameId"; HeightStructure readStructure = new TestHeightStructure(sameId, "new structure"); HeightStructure structure = new TestHeightStructure(sameId, "original structure"); var calculation = new TestHeightStructuresCalculationScenario { InputParameters = { Structure = structure }, Output = new TestStructuresOutput() }; var failureMechanism = new HeightStructuresFailureMechanism { CalculationsGroup = { Children = { calculation } } }; failureMechanism.HeightStructures.AddRange(new[] { structure }, sourceFilePath); var strategy = new HeightStructureUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(new[] { readStructure }, sourceFilePath); // Assert Assert.IsTrue(calculation.HasOutput); AssertHeightStructures(readStructure, structure); CollectionAssert.AreEqual(new IObservable[] { failureMechanism.HeightStructures, structure, calculation.InputParameters }, affectedObjects); }
public void UpdateStructuresWithImportedData_CalculationWithOutputAndStructure_CalculationUpdatedAndReturnsAffectedObject() { // Setup var structure = new TestHeightStructure(); var calculation = new TestHeightStructuresCalculationScenario { InputParameters = { Structure = structure }, Output = new TestStructuresOutput() }; var failureMechanism = new HeightStructuresFailureMechanism { CalculationsGroup = { Children = { calculation } } }; failureMechanism.HeightStructures.AddRange(new[] { structure }, sourceFilePath); var strategy = new HeightStructureReplaceDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(Enumerable.Empty <HeightStructure>(), sourceFilePath).ToArray(); // Assert Assert.IsFalse(calculation.HasOutput); Assert.IsNull(calculation.InputParameters.Structure); CollectionAssert.AreEquivalent(new IObservable[] { calculation, calculation.InputParameters, failureMechanism.HeightStructures }, affectedObjects); }
public void UpdateStructuresWithImportedData_WithCurrentStructuresAndImportedHasPartialOverlap_UpdatesTargetCollection() { // Setup const string commonId = "common id"; var updatedStructure = new TestHeightStructure(commonId, "old name"); var removedStructure = new TestHeightStructure("removed id"); var failureMechanism = new HeightStructuresFailureMechanism(); StructureCollection <HeightStructure> structures = failureMechanism.HeightStructures; structures.AddRange(new[] { removedStructure, updatedStructure }, sourceFilePath); var structureToUpdateFrom = new TestHeightStructure(commonId, "new name"); var addedStructure = new TestHeightStructure("added id"); TestHeightStructure[] importedStructures = { structureToUpdateFrom, addedStructure }; var strategy = new HeightStructureUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(importedStructures, sourceFilePath); // Assert Assert.AreEqual(2, structures.Count); Assert.AreSame(updatedStructure, structures[0]); AssertHeightStructures(structureToUpdateFrom, updatedStructure); Assert.AreSame(addedStructure, structures[1]); CollectionAssert.AreEquivalent(new IObservable[] { updatedStructure, structures }, affectedObjects); }