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 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 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_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 UpdateStructuresWithImportedData_SourcePathNull_ThrowsArgumentNullException()
        {
            // Setup
            var strategy = new ClosingStructureUpdateDataStrategy(new ClosingStructuresFailureMechanism());

            // Call
            void Call() => strategy.UpdateStructuresWithImportedData(Enumerable.Empty <ClosingStructure>(), null);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(Call);

            Assert.AreEqual("sourceFilePath", exception.ParamName);
        }
        public void UpdateStructuresWithImportedData_ReadStructuresNull_ThrowsArgumentNullException()
        {
            // Setup
            var strategy = new ClosingStructureUpdateDataStrategy(new ClosingStructuresFailureMechanism());

            // 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 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_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 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_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 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);
        }
        public void UpdateStructuresWithImportedData_MultipleCalculationWithStructureOneWithRemovedStructure_OnlyUpdatesCalculationWithRemovedStructure()
        {
            // Setup
            const string removedId               = "affectedId";
            const string unaffectedId            = "unaffectedId";
            const string unaffectedStructureName = "unaffectedStructure";
            var          removedStructure        = new TestClosingStructure(removedId, "Old name");
            var          unaffectedStructure     = new TestClosingStructure(unaffectedId, unaffectedStructureName);

            var affectedCalculation = new TestClosingStructuresCalculationScenario
            {
                InputParameters =
                {
                    Structure = removedStructure
                },
                Output = new TestStructuresOutput()
            };

            var unaffectedCalculation = new TestClosingStructuresCalculationScenario
            {
                InputParameters =
                {
                    Structure = unaffectedStructure
                },
                Output = new TestStructuresOutput()
            };

            var failureMechanism = new ClosingStructuresFailureMechanism
            {
                CalculationsGroup =
                {
                    Children =
                    {
                        affectedCalculation,
                        unaffectedCalculation
                    }
                }
            };

            StructureCollection <ClosingStructure> targetDataCollection = failureMechanism.ClosingStructures;

            targetDataCollection.AddRange(new[]
            {
                removedStructure,
                unaffectedStructure
            }, sourceFilePath);

            var strategy = new ClosingStructureUpdateDataStrategy(failureMechanism);

            ClosingStructure readUnaffectedStructure = new TestClosingStructure(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);
            ClosingStructure inputParametersUnaffectedStructure = unaffectedCalculation.InputParameters.Structure;

            Assert.AreSame(unaffectedStructure, inputParametersUnaffectedStructure);
            AssertClosingStructures(readUnaffectedStructure, inputParametersUnaffectedStructure);

            CollectionAssert.AreEquivalent(new IObservable[]
            {
                affectedCalculation,
                affectedCalculation.InputParameters,
                targetDataCollection
            }, affectedObjects);
        }