public void UpdateStructuresWithImportedData_SingleChange_UpdatesOnlySingleChange(StabilityPointStructure readStructure) { // Setup StabilityPointStructure structure = new TestStabilityPointStructure(); var failureMechanism = new StabilityPointStructuresFailureMechanism(); StructureCollection <StabilityPointStructure> targetCollection = failureMechanism.StabilityPointStructures; targetCollection.AddRange(new[] { structure }, sourceFilePath); var strategy = new StabilityPointStructureUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(new[] { readStructure }, sourceFilePath); // Assert AssertStabilityPointStructure(readStructure, structure); CollectionAssert.AreEqual(new IObservable[] { targetCollection, structure }, affectedObjects); }
public void UpdateStructuresWithImportedData_WithCurrentStructuresAndImportedHasNoOverlap_UpdatesTargetCollection() { // Setup var targetStructure = new TestStabilityPointStructure("target id"); var failureMechanism = new StabilityPointStructuresFailureMechanism(); StructureCollection <StabilityPointStructure> structures = failureMechanism.StabilityPointStructures; structures.AddRange(new[] { targetStructure }, sourceFilePath); var readStructure = new TestStabilityPointStructure("read id"); TestStabilityPointStructure[] importedStructures = { readStructure }; var strategy = new StabilityPointStructureUpdateDataStrategy(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_WithoutCurrentStructuresAndReadStructuresHaveDuplicateNames_ThrowsUpdateDataException() { // Setup const string duplicateId = "I am a duplicate id"; var readStructures = new[] { new TestStabilityPointStructure(duplicateId, "First Name"), new TestStabilityPointStructure(duplicateId, "Second Name") }; var targetCollection = new StructureCollection <StabilityPointStructure>(); var strategy = new StabilityPointStructureUpdateDataStrategy(new StabilityPointStructuresFailureMechanism()); // 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.IsEmpty(targetCollection); }
public void UpdateStructuresWithImportedData_CalculationWithStructureImportedStructureWithSameId_UpdatesCalculationInput() { // Setup const string sameId = "sameId"; StabilityPointStructure readStructure = new TestStabilityPointStructure(sameId, "new structure"); StabilityPointStructure structure = new TestStabilityPointStructure(sameId, "original structure"); var calculation = new TestStabilityPointStructuresCalculationScenario { InputParameters = { Structure = structure }, Output = new TestStructuresOutput() }; var failureMechanism = new StabilityPointStructuresFailureMechanism { CalculationsGroup = { Children = { calculation } } }; StructureCollection <StabilityPointStructure> targetDataCollection = failureMechanism.StabilityPointStructures; targetDataCollection.AddRange(new[] { structure }, sourceFilePath); var strategy = new StabilityPointStructureUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(new[] { readStructure }, sourceFilePath); // Assert Assert.IsTrue(calculation.HasOutput); AssertStabilityPointStructure(readStructure, structure); CollectionAssert.AreEqual(new IObservable[] { targetDataCollection, structure, calculation.InputParameters }, affectedObjects); }
public void UpdateStructuresWithImportedData_SectionResultWithStructureImportedStructureWithSameIdRemoved_UpdatesCalculationInput() { // Setup const string sameId = "id"; var originalMatchingPoint = new Point2D(0, 0); StabilityPointStructure removedStructure = new TestStabilityPointStructure(originalMatchingPoint, sameId); var calculation = new TestStabilityPointStructuresCalculationScenario { InputParameters = { Structure = removedStructure } }; var failureMechanism = new StabilityPointStructuresFailureMechanism { CalculationsGroup = { Children = { calculation } } }; failureMechanism.StabilityPointStructures.AddRange(new[] { removedStructure }, sourceFilePath); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[] { originalMatchingPoint, new Point2D(10, 10) }) }); var strategy = new StabilityPointStructureUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(Enumerable.Empty <StabilityPointStructure>(), sourceFilePath); // Assert CollectionAssert.AreEqual(new IObservable[] { failureMechanism.StabilityPointStructures, calculation.InputParameters }, affectedObjects); }
public void UpdateStructuresWithImportedData_SourcePathNull_ThrowsArgumentNullException() { // Setup var strategy = new StabilityPointStructureUpdateDataStrategy(new StabilityPointStructuresFailureMechanism()); // Call void Call() => strategy.UpdateStructuresWithImportedData(Enumerable.Empty <StabilityPointStructure>(), null); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("sourceFilePath", exception.ParamName); }
public void UpdateStructuresWithImportedData_ReadStructuresNull_ThrowsArgumentNullException() { // Setup var strategy = new StabilityPointStructureUpdateDataStrategy(new StabilityPointStructuresFailureMechanism()); // Call void Call() => strategy.UpdateStructuresWithImportedData(null, string.Empty); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("importedDataCollection", exception.ParamName); }
public void UpdateStructuresWithImportedData_CalculationWithSameReference_OnlyReturnsDistinctCalculationInput() { // Setup const string affectedId = "affectedId"; var affectedStructure = new TestStabilityPointStructure(affectedId, "Old name"); var affectedCalculation = new TestStabilityPointStructuresCalculationScenario { InputParameters = { Structure = affectedStructure }, Output = new TestStructuresOutput() }; var failureMechanism = new StabilityPointStructuresFailureMechanism { CalculationsGroup = { Children = { affectedCalculation, affectedCalculation } } }; StructureCollection <StabilityPointStructure> structures = failureMechanism.StabilityPointStructures; structures.AddRange(new[] { affectedStructure }, sourceFilePath); var structureToUpdateFrom = new TestStabilityPointStructure(affectedId, "New name"); var strategy = new StabilityPointStructureUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(new[] { structureToUpdateFrom }, sourceFilePath); // Assert CollectionAssert.AreEquivalent(new IObservable[] { structures, affectedStructure, affectedCalculation.InputParameters }, affectedObjects); }
public void UpdateStructuresWithImportedData_WithCurrentStructuresAndImportedHasPartialOverlap_UpdatesTargetCollection() { // Setup const string commonId = "common id"; var updatedStructure = new TestStabilityPointStructure(commonId, "old name"); var removedStructure = new TestStabilityPointStructure("removed id"); var failureMechanism = new StabilityPointStructuresFailureMechanism(); StructureCollection <StabilityPointStructure> structures = failureMechanism.StabilityPointStructures; structures.AddRange(new[] { removedStructure, updatedStructure }, sourceFilePath); var structureToUpdateFrom = new TestStabilityPointStructure(commonId, "new name"); var addedStructure = new TestStabilityPointStructure("added id"); TestStabilityPointStructure[] importedStructures = { structureToUpdateFrom, addedStructure }; var strategy = new StabilityPointStructureUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(importedStructures, sourceFilePath); // Assert Assert.AreEqual(2, structures.Count); Assert.AreSame(updatedStructure, structures[0]); AssertStabilityPointStructure(structureToUpdateFrom, updatedStructure); Assert.AreSame(addedStructure, structures[1]); CollectionAssert.AreEquivalent(new IObservable[] { updatedStructure, structures }, affectedObjects); }
public void UpdateStructuresWithImportedData_SectionResultWithStructureImportedStructureWithSameId_UpdatesCalculationInput() { // Setup const string sameId = "sameId"; var originalMatchingPoint = new Point2D(0, 0); var updatedMatchingPoint = new Point2D(20, 20); StabilityPointStructure readStructure = new TestStabilityPointStructure(updatedMatchingPoint, sameId); StabilityPointStructure structure = new TestStabilityPointStructure(originalMatchingPoint, sameId); var calculation = new TestStabilityPointStructuresCalculationScenario { InputParameters = { Structure = structure } }; var failureMechanism = new StabilityPointStructuresFailureMechanism { CalculationsGroup = { Children = { calculation } } }; failureMechanism.StabilityPointStructures.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 StabilityPointStructureUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(new[] { readStructure }, sourceFilePath); // Assert AssertStabilityPointStructure(readStructure, structure); CollectionAssert.AreEqual(new IObservable[] { failureMechanism.StabilityPointStructures, structure, calculation.InputParameters }, affectedObjects); }
public void UpdateStructuresWithImportedData_MultipleCalculationWithStructuresOneWithRemovedStructure_OnlyUpdatesCalculationWithRemovedStructure() { // Setup const string removedId = "removedId"; const string unaffectedId = "unaffectedId"; const string unaffectedStructureName = "unaffectedStructure"; var removedStructure = new TestStabilityPointStructure(removedId, "Old name"); var unaffectedStructure = new TestStabilityPointStructure(unaffectedId, unaffectedStructureName); var affectedCalculation = new TestStabilityPointStructuresCalculationScenario { InputParameters = { Structure = removedStructure }, Output = new TestStructuresOutput() }; var unaffectedCalculation = new TestStabilityPointStructuresCalculationScenario { InputParameters = { Structure = unaffectedStructure }, Output = new TestStructuresOutput() }; var failureMechanism = new StabilityPointStructuresFailureMechanism { CalculationsGroup = { Children = { affectedCalculation, unaffectedCalculation } } }; StructureCollection <StabilityPointStructure> targetDataCollection = failureMechanism.StabilityPointStructures; targetDataCollection.AddRange(new[] { removedStructure, unaffectedStructure }, sourceFilePath); var strategy = new StabilityPointStructureUpdateDataStrategy(failureMechanism); StabilityPointStructure readUnaffectedStructure = new TestStabilityPointStructure(unaffectedId, unaffectedStructureName); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(new[] { readUnaffectedStructure }, sourceFilePath); // Assert Assert.IsFalse(affectedCalculation.HasOutput); Assert.IsNull(affectedCalculation.InputParameters.Structure); Assert.IsTrue(unaffectedCalculation.HasOutput); StabilityPointStructure inputParametersUnaffectedStructure = unaffectedCalculation.InputParameters.Structure; Assert.AreSame(unaffectedStructure, inputParametersUnaffectedStructure); AssertStabilityPointStructure(readUnaffectedStructure, inputParametersUnaffectedStructure); CollectionAssert.AreEquivalent(new IObservable[] { affectedCalculation, affectedCalculation.InputParameters, targetDataCollection }, affectedObjects); }