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_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 Constructor_WithFailureMechanism_CreatesNewInstance() { // Setup var failureMechanism = new HeightStructuresFailureMechanism(); // Call var strategy = new HeightStructureUpdateDataStrategy(failureMechanism); // Assert Assert.IsInstanceOf <UpdateDataStrategyBase <HeightStructure, HeightStructuresFailureMechanism> >(strategy); Assert.IsInstanceOf <IStructureUpdateStrategy <HeightStructure> >(strategy); }
public void UpdateStructuresWithImportedData_SectionResultWithStructureImportedStructureWithSameIdRemoved_UpdatesCalculationInput() { // Setup const string sameId = "id"; var originalMatchingPoint = new Point2D(0, 0); HeightStructure removedStructure = new TestHeightStructure(originalMatchingPoint, sameId); var calculation = new TestHeightStructuresCalculationScenario { InputParameters = { Structure = removedStructure } }; var failureMechanism = new HeightStructuresFailureMechanism { CalculationsGroup = { Children = { calculation } } }; failureMechanism.HeightStructures.AddRange(new[] { removedStructure }, sourceFilePath); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[] { originalMatchingPoint, new Point2D(10, 10) }) }); var strategy = new HeightStructureUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(Enumerable.Empty <HeightStructure>(), sourceFilePath); // Assert CollectionAssert.AreEqual(new IObservable[] { failureMechanism.HeightStructures, calculation.InputParameters }, affectedObjects); }
public void UpdateStructuresWithImportedData_SourcePathNull_ThrowsArgumentNullException() { // Setup var strategy = new HeightStructureUpdateDataStrategy(new HeightStructuresFailureMechanism()); // Call void Call() => strategy.UpdateStructuresWithImportedData(Enumerable.Empty <HeightStructure>(), null); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("sourceFilePath", exception.ParamName); }
public void UpdateStructuresWithImportedData_ReadStructuresNull_ThrowsArgumentNullException() { // Setup var strategy = new HeightStructureUpdateDataStrategy(new HeightStructuresFailureMechanism()); // 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 TestHeightStructure(affectedId, "Old name"); var affectedCalculation = new TestHeightStructuresCalculationScenario { InputParameters = { Structure = affectedStructure }, Output = new TestStructuresOutput() }; var failureMechanism = new HeightStructuresFailureMechanism { CalculationsGroup = { Children = { affectedCalculation, affectedCalculation } } }; StructureCollection <HeightStructure> structures = failureMechanism.HeightStructures; structures.AddRange(new[] { affectedStructure }, sourceFilePath); var structureToUpdateFrom = new TestHeightStructure(affectedId, "New name"); var strategy = new HeightStructureUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(new[] { structureToUpdateFrom }, sourceFilePath); // Assert CollectionAssert.AreEquivalent(new IObservable[] { structures, affectedStructure, affectedCalculation.InputParameters }, affectedObjects); }
public void UpdateStructuresWithImportedData_CalculationWithRemovedStructure_UpdatesCalculation() { // Setup const string removedId = "sameId"; HeightStructure structure = new TestHeightStructure(removedId, "original structure"); var calculation = new TestHeightStructuresCalculationScenario { InputParameters = { Structure = structure }, Output = new TestStructuresOutput() }; var failureMechanism = new HeightStructuresFailureMechanism { CalculationsGroup = { Children = { calculation } } }; StructureCollection <HeightStructure> targetDataCollection = failureMechanism.HeightStructures; targetDataCollection.AddRange(new[] { structure }, sourceFilePath); var strategy = new HeightStructureUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(Enumerable.Empty <HeightStructure>(), sourceFilePath); // Assert Assert.IsFalse(calculation.HasOutput); Assert.IsNull(calculation.InputParameters.Structure); CollectionAssert.AreEqual(new IObservable[] { targetDataCollection, calculation, calculation.InputParameters }, affectedObjects); }
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_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); }
public void UpdateStructuresWithImportedData_SectionResultWithStructureImportedStructureWithSameId_UpdatesCalculationInput() { // Setup const string sameId = "sameId"; var originalMatchingPoint = new Point2D(0, 0); var updatedMatchingPoint = new Point2D(20, 20); HeightStructure readStructure = new TestHeightStructure(updatedMatchingPoint, sameId); HeightStructure structure = new TestHeightStructure(originalMatchingPoint, sameId); var calculation = new TestHeightStructuresCalculationScenario { InputParameters = { Structure = structure } }; var failureMechanism = new HeightStructuresFailureMechanism { CalculationsGroup = { Children = { calculation } } }; failureMechanism.HeightStructures.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 HeightStructureUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(new[] { readStructure }, sourceFilePath); // Assert AssertHeightStructures(readStructure, structure); CollectionAssert.AreEqual(new IObservable[] { failureMechanism.HeightStructures, structure, calculation.InputParameters }, affectedObjects); }
public void UpdateStructuresWithImportedData_MultipleCalculationWithStructuresOneWithRemovedStructure_OnlyUpdatesCalculationWithRemovedStructure() { // Setup const string removedId = "affectedId"; const string unaffectedId = "unaffectedId"; const string unaffectedStructureName = "unaffectedStructure"; var removedStructure = new TestHeightStructure(removedId, "Old name"); var unaffectedStructure = new TestHeightStructure(unaffectedId, unaffectedStructureName); var affectedCalculation = new TestHeightStructuresCalculationScenario { InputParameters = { Structure = removedStructure }, Output = new TestStructuresOutput() }; var unaffectedCalculation = new TestHeightStructuresCalculationScenario { InputParameters = { Structure = unaffectedStructure }, Output = new TestStructuresOutput() }; var failureMechanism = new HeightStructuresFailureMechanism { CalculationsGroup = { Children = { affectedCalculation, unaffectedCalculation } } }; StructureCollection <HeightStructure> targetDataCollection = failureMechanism.HeightStructures; targetDataCollection.AddRange(new[] { removedStructure, unaffectedStructure }, sourceFilePath); var strategy = new HeightStructureUpdateDataStrategy(failureMechanism); HeightStructure readUnaffectedStructure = new TestHeightStructure(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); HeightStructure inputParametersUnaffectedStructure = unaffectedCalculation.InputParameters.Structure; Assert.AreSame(unaffectedStructure, inputParametersUnaffectedStructure); AssertHeightStructures(readUnaffectedStructure, inputParametersUnaffectedStructure); CollectionAssert.AreEquivalent(new IObservable[] { affectedCalculation, affectedCalculation.InputParameters, targetDataCollection }, affectedObjects); }