예제 #1
0
        public void UpdateForeshoreProfilesWithImportedData_WithCurrentCollectionNotEmptyAndImportedCollectionHasProfilesWithSameId_ThrowsUpdateException()
        {
            // Setup

            var foreshoreProfiles         = new ForeshoreProfileCollection();
            var originalForeshoreProfiles = new[]
            {
                new TestForeshoreProfile("name 1", "different ID")
            };

            foreshoreProfiles.AddRange(originalForeshoreProfiles, sourceFilePath);

            const string duplicateId = "duplicate ID";
            var          importedForeshoreProfiles = new[]
            {
                new TestForeshoreProfile("Name A", duplicateId),
                new TestForeshoreProfile("Name B", duplicateId)
            };

            var strategy = new ForeshoreProfileUpdateDataStrategy(new TestCalculatableFailureMechanism(), foreshoreProfiles);

            // Call
            void Call() => strategy.UpdateForeshoreProfilesWithImportedData(importedForeshoreProfiles, 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(originalForeshoreProfiles, foreshoreProfiles);
        }
예제 #2
0
        public void UpdateForeshoreProfilesWithImportedData_CurrentCollectionEmptyImportedCollectionContainDuplicateIDs_ThrowUpdateException()
        {
            // Setup
            var foreshoreProfiles = new ForeshoreProfileCollection();

            const string duplicateId = "duplicate ID";
            var          importedForeshoreProfiles = new[]
            {
                new TestForeshoreProfile("Name A", duplicateId),
                new TestForeshoreProfile("Name B", duplicateId)
            };

            var strategy = new ForeshoreProfileUpdateDataStrategy(new TestCalculatableFailureMechanism(), foreshoreProfiles);

            // Call
            void Call() => strategy.UpdateForeshoreProfilesWithImportedData(importedForeshoreProfiles, 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(foreshoreProfiles);
        }
예제 #3
0
        public void UpdateForeshoreProfilesWithImportedData_ForeshoreProfilePropertiesChanged_UpdateRelevantProperties(
            ForeshoreProfile readForeshoreProfile)
        {
            // Setup
            var profileToBeUpdated = new TestForeshoreProfile();

            var targetCollection = new ForeshoreProfileCollection();

            targetCollection.AddRange(new[]
            {
                profileToBeUpdated
            }, sourceFilePath);

            var strategy = new ForeshoreProfileUpdateDataStrategy(new TestCalculatableFailureMechanism(), targetCollection);

            // Call
            strategy.UpdateForeshoreProfilesWithImportedData(new[]
            {
                readForeshoreProfile
            }, sourceFilePath);

            // Assert
            Assert.AreEqual(1, targetCollection.Count);
            Assert.AreSame(profileToBeUpdated, targetCollection[0]);
            AssertForeshoreProfile(readForeshoreProfile, profileToBeUpdated);
        }
예제 #4
0
        public void UpdateForeshoreProfilesWithImportedData_MultipleCalculationsWithOutputAndProfile_UpdatesCalculationWithUpdatedProfile()
        {
            // Setup
            var affectedProfile = new TestForeshoreProfile("Name", "Updated ID");
            TestCalculationWithForeshoreProfile affectedCalculation =
                TestCalculationWithForeshoreProfile.CreateCalculationWithOutput(affectedProfile);
            ForeshoreProfile profileToUpdateFrom = DeepCloneAndModify(affectedProfile);

            const string unaffectedProfileId   = "Unaffected ID";
            const string unaffectedProfileName = "Name";
            var          unaffectedProfile     = new TestForeshoreProfile(unaffectedProfileName, unaffectedProfileId);
            TestCalculationWithForeshoreProfile unaffectedCalculation =
                TestCalculationWithForeshoreProfile.CreateCalculationWithOutput(unaffectedProfile);

            var foreshoreProfiles = new ForeshoreProfileCollection();

            TestForeshoreProfile[] originalForeshoreProfiles =
            {
                affectedProfile,
                unaffectedProfile
            };
            foreshoreProfiles.AddRange(originalForeshoreProfiles, sourceFilePath);

            var failureMechanism = new TestCalculatableFailureMechanism(new[]
            {
                affectedCalculation,
                unaffectedCalculation
            });

            var strategy = new ForeshoreProfileUpdateDataStrategy(failureMechanism, foreshoreProfiles);

            // Call
            IEnumerable <IObservable> affectedObjects =
                strategy.UpdateForeshoreProfilesWithImportedData(new[]
            {
                new TestForeshoreProfile(unaffectedProfileName,
                                         unaffectedProfileId),
                profileToUpdateFrom
            },
                                                                 sourceFilePath);

            // Assert
            Assert.IsTrue(unaffectedCalculation.HasOutput);
            Assert.AreSame(unaffectedProfile,
                           unaffectedCalculation.InputParameters.ForeshoreProfile);

            Assert.IsFalse(affectedCalculation.HasOutput);
            Assert.AreSame(affectedProfile, affectedCalculation.InputParameters.ForeshoreProfile);

            CollectionAssert.AreEquivalent(originalForeshoreProfiles, foreshoreProfiles);

            CollectionAssert.AreEquivalent(new IObservable[]
            {
                affectedCalculation,
                affectedCalculation.InputParameters,
                affectedProfile,
                foreshoreProfiles
            }, affectedObjects);
        }
예제 #5
0
        public void Constructor_CreatesNewInstance()
        {
            // Call
            var strategy = new ForeshoreProfileUpdateDataStrategy(new TestCalculatableFailureMechanism(), new ForeshoreProfileCollection());

            // Assert
            Assert.IsInstanceOf <IForeshoreProfileUpdateDataStrategy>(strategy);
            Assert.IsInstanceOf <UpdateDataStrategyBase <ForeshoreProfile, ICalculatableFailureMechanism> >(strategy);
        }
예제 #6
0
        public void UpdateForeshoreProfilesWithImportedData_CalculationWithOutputAndForeshoreProfileUpdatedWithProfileWithoutGeometry_UpdatesCalculation()
        {
            // Setup
            const string          id       = "profile ID";
            IEnumerable <Point2D> geometry = new[]
            {
                new Point2D(1, 2),
                new Point2D(3, 4)
            };

            var affectedProfile = new TestForeshoreProfile(id, geometry);
            TestCalculationWithForeshoreProfile affectedCalculation =
                TestCalculationWithForeshoreProfile.CreateCalculationWithOutput(affectedProfile);

            affectedCalculation.InputParameters.UseForeshore = true;

            var profileToUpdateFrom = new TestForeshoreProfile(id, Enumerable.Empty <Point2D>());

            var foreshoreProfiles = new ForeshoreProfileCollection();

            TestForeshoreProfile[] originalForeshoreProfiles =
            {
                affectedProfile
            };
            foreshoreProfiles.AddRange(originalForeshoreProfiles, sourceFilePath);

            var failureMechanism = new TestCalculatableFailureMechanism(new[]
            {
                affectedCalculation
            });

            var strategy = new ForeshoreProfileUpdateDataStrategy(failureMechanism, foreshoreProfiles);

            // Call
            IEnumerable <IObservable> affectedObjects =
                strategy.UpdateForeshoreProfilesWithImportedData(new[]
            {
                profileToUpdateFrom
            },
                                                                 sourceFilePath);

            // Assert
            Assert.IsFalse(affectedCalculation.HasOutput);
            Assert.IsFalse(affectedCalculation.InputParameters.UseForeshore);
            AssertForeshoreProfile(affectedProfile, profileToUpdateFrom);

            CollectionAssert.AreEquivalent(new IObservable[]
            {
                affectedCalculation,
                affectedCalculation.InputParameters,
                affectedProfile,
                foreshoreProfiles
            }, affectedObjects);
        }
예제 #7
0
        public void UpdateForeshoreProfilesWithImportedData_WithCurrentCollectionAndImportedCollectionHasPartialOverlap_UpdatesTargetDataCollection()
        {
            // Setup
            var commonName = "Name";
            var foreshoreProfileToBeUpdated = new TestForeshoreProfile(commonName, "Updated ID");
            var foreshoreProfileToBeRemoved = new TestForeshoreProfile(commonName, "Removed ID");

            var foreshoreProfiles = new ForeshoreProfileCollection();

            foreshoreProfiles.AddRange(new[]
            {
                foreshoreProfileToBeUpdated,
                foreshoreProfileToBeRemoved
            }, sourceFilePath);

            ForeshoreProfile foreshoreProfileToUpdateFrom = DeepCloneAndModify(foreshoreProfileToBeUpdated);
            var foreshoreProfileToBeAdded = new TestForeshoreProfile(commonName, "Added ID");

            ForeshoreProfile[] importedForeshoreProfiles =
            {
                foreshoreProfileToUpdateFrom,
                foreshoreProfileToBeAdded
            };

            var strategy = new ForeshoreProfileUpdateDataStrategy(new TestCalculatableFailureMechanism(), foreshoreProfiles);

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.UpdateForeshoreProfilesWithImportedData(importedForeshoreProfiles,
                                                                                                         sourceFilePath);

            // Assert
            Assert.AreEqual(2, foreshoreProfiles.Count);
            CollectionAssert.AreEqual(new[]
            {
                foreshoreProfileToBeUpdated,
                foreshoreProfileToBeAdded
            }, foreshoreProfiles);

            ForeshoreProfile updatedForeshoreProfile = foreshoreProfiles[0];

            Assert.AreSame(foreshoreProfileToBeUpdated, updatedForeshoreProfile);
            AssertForeshoreProfile(foreshoreProfileToUpdateFrom, updatedForeshoreProfile);

            ForeshoreProfile addedForeshoreProfile = foreshoreProfiles[1];

            Assert.AreSame(foreshoreProfileToBeAdded, addedForeshoreProfile);
            AssertForeshoreProfile(foreshoreProfileToBeAdded, addedForeshoreProfile);

            CollectionAssert.AreEquivalent(new IObservable[]
            {
                foreshoreProfileToBeUpdated,
                foreshoreProfiles
            }, affectedObjects);
        }
예제 #8
0
        public void UpdateForeshoreProfilesWithImportedData_SourceFilePathNull_ThrowsArgumentNullException()
        {
            // Setup
            var strategy = new ForeshoreProfileUpdateDataStrategy(new TestCalculatableFailureMechanism(), new ForeshoreProfileCollection());

            // Call
            void Call() => strategy.UpdateForeshoreProfilesWithImportedData(Enumerable.Empty <ForeshoreProfile>(), null);

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

            Assert.AreEqual("sourceFilePath", exception.ParamName);
        }
예제 #9
0
        public void UpdateForeshoreProfilesWithImportedData_MultipleCalculationsWithSameReference_OnlyReturnsDistinctCalculations()
        {
            // Setup
            var affectedProfile = new TestForeshoreProfile("Name", "Updated ID");
            TestCalculationWithForeshoreProfile affectedCalculation =
                TestCalculationWithForeshoreProfile.CreateCalculationWithOutput(affectedProfile);
            ForeshoreProfile profileToUpdateFrom = DeepCloneAndModify(affectedProfile);

            TestCalculationWithForeshoreProfile calculationSameReference = affectedCalculation;

            var foreshoreProfiles = new ForeshoreProfileCollection();

            TestForeshoreProfile[] originalForeshoreProfiles =
            {
                affectedProfile
            };
            foreshoreProfiles.AddRange(originalForeshoreProfiles, sourceFilePath);

            var failureMechanism = new TestCalculatableFailureMechanism(new[]
            {
                affectedCalculation,
                calculationSameReference
            });

            var strategy = new ForeshoreProfileUpdateDataStrategy(failureMechanism, foreshoreProfiles);

            // Call
            IEnumerable <IObservable> affectedObjects =
                strategy.UpdateForeshoreProfilesWithImportedData(new[]
            {
                profileToUpdateFrom
            },
                                                                 sourceFilePath);

            // Assert
            CollectionAssert.AreEquivalent(new IObservable[]
            {
                affectedCalculation,
                affectedCalculation.InputParameters,
                affectedProfile,
                foreshoreProfiles
            }, affectedObjects);
        }
예제 #10
0
        public void UpdateForeshoreProfilesWithImportedData_CalculationWithOutputAssignedToRemovedProfile_UpdatesCalculation()
        {
            // Setup
            var profileToBeRemoved = new TestForeshoreProfile("Name", "Removed ID");
            TestCalculationWithForeshoreProfile calculation =
                TestCalculationWithForeshoreProfile.CreateCalculationWithOutput(profileToBeRemoved);
            var foreshoreProfiles = new ForeshoreProfileCollection();

            foreshoreProfiles.AddRange(new[]
            {
                profileToBeRemoved
            }, sourceFilePath);

            var failureMechanism = new TestCalculatableFailureMechanism(new[]
            {
                calculation
            });

            var strategy = new ForeshoreProfileUpdateDataStrategy(failureMechanism, foreshoreProfiles);

            // Call
            IEnumerable <IObservable> affectedObjects =
                strategy.UpdateForeshoreProfilesWithImportedData(Enumerable.Empty <ForeshoreProfile>(),
                                                                 sourceFilePath);

            // Assert
            Assert.IsFalse(calculation.HasOutput);
            Assert.IsNull(calculation.InputParameters.ForeshoreProfile);

            CollectionAssert.IsEmpty(foreshoreProfiles);
            CollectionAssert.AreEquivalent(new IObservable[]
            {
                calculation,
                calculation.InputParameters,
                foreshoreProfiles
            }, affectedObjects);
        }
예제 #11
0
        public void UpdateForeshoreProfilesWithImportedData_CurrentCollectionAndImportedCollectionHasNoOverlap_UpdatesTargetCollection()
        {
            // Setup
            const string currentForeshoreProfile = "Current ID";
            var          targetForeshoreProfile  = new TestForeshoreProfile(string.Empty, currentForeshoreProfile);

            const string readForeshoreProfileId = "Read ID";
            var          readForeshoreProfile   = new TestForeshoreProfile(string.Empty, readForeshoreProfileId);

            TestForeshoreProfile[] readForeshoreProfiles =
            {
                readForeshoreProfile
            };

            var foreshoreProfiles = new ForeshoreProfileCollection();

            foreshoreProfiles.AddRange(new[]
            {
                targetForeshoreProfile
            }, sourceFilePath);

            var strategy = new ForeshoreProfileUpdateDataStrategy(new TestCalculatableFailureMechanism(), foreshoreProfiles);

            // Call
            IEnumerable <IObservable> affectedObjects =
                strategy.UpdateForeshoreProfilesWithImportedData(readForeshoreProfiles,
                                                                 sourceFilePath);

            // Assert
            Assert.AreEqual(1, foreshoreProfiles.Count);
            Assert.AreSame(readForeshoreProfile, foreshoreProfiles[0]);

            CollectionAssert.AreEqual(new[]
            {
                foreshoreProfiles
            }, affectedObjects);
        }
예제 #12
0
        public void UpdateForeshoreProfilesWithImportedData_WithCurrentCollectionAndImportedCollectionHasFullOverlap_UpdatesTargetDataCollection()
        {
            // Setup

            var foreshoreProfiles      = new ForeshoreProfileCollection();
            var targetForeshoreProfile = new TestForeshoreProfile("Name", "ID");

            foreshoreProfiles.AddRange(new[]
            {
                targetForeshoreProfile
            }, sourceFilePath);

            ForeshoreProfile readForeshoreProfile = DeepCloneAndModify(targetForeshoreProfile);

            ForeshoreProfile[] importedForeshoreProfiles =
            {
                readForeshoreProfile
            };

            var strategy = new ForeshoreProfileUpdateDataStrategy(new TestCalculatableFailureMechanism(), foreshoreProfiles);

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.UpdateForeshoreProfilesWithImportedData(importedForeshoreProfiles,
                                                                                                         sourceFilePath);

            // Assert
            Assert.AreEqual(1, foreshoreProfiles.Count);
            Assert.AreSame(targetForeshoreProfile, foreshoreProfiles[0]);
            AssertForeshoreProfile(readForeshoreProfile, targetForeshoreProfile);

            CollectionAssert.AreEquivalent(new IObservable[]
            {
                targetForeshoreProfile,
                foreshoreProfiles
            }, affectedObjects);
        }
예제 #13
0
        public void UpdateForeshoreProfilesWithImportedData_SupportedFailureMechanisms_UpdatesAffectedCalculationAndReturnsAffectedData(
            ICalculatableFailureMechanism failureMechanism,
            ForeshoreProfileCollection foreshoreProfiles,
            ForeshoreProfile unaffectedForeshoreProfile)
        {
            // Setup
            ForeshoreProfile profileToBeUpdated  = foreshoreProfiles[0];
            ForeshoreProfile profileToUpdateFrom = DeepCloneAndModify(profileToBeUpdated);
            ForeshoreProfile profileToBeRemoved  = foreshoreProfiles[1];

            var strategy = new ForeshoreProfileUpdateDataStrategy(failureMechanism, foreshoreProfiles);

            ICalculation <ICalculationInput>[] calculationsWithUpdatedForeshoreProfile =
                failureMechanism.Calculations
                .Cast <ICalculation <ICalculationInput> >()
                .Where(calc => ReferenceEquals(GetForeshoreProfile(calc),
                                               profileToBeUpdated))
                .ToArray();

            ICalculation <ICalculationInput>[] calculationsWithUpdatedForeshoreProfileWithOutputs =
                calculationsWithUpdatedForeshoreProfile.Where(calc => calc.HasOutput)
                .ToArray();

            ICalculation <ICalculationInput>[] calculationsWithRemovedForeshoreProfile =
                failureMechanism.Calculations
                .Cast <ICalculation <ICalculationInput> >()
                .Where(calc => ReferenceEquals(GetForeshoreProfile(calc),
                                               profileToBeRemoved))
                .ToArray();

            ICalculation <ICalculationInput>[] calculationsWithRemovedForeshoreProfileWithOutputs =
                calculationsWithRemovedForeshoreProfile.Where(calc => calc.HasOutput)
                .ToArray();

            ICalculation <ICalculationInput>[] calculationsWithUnaffectedForeshoreProfile =
                failureMechanism.Calculations
                .Cast <ICalculation <ICalculationInput> >()
                .Where(calc => ReferenceEquals(GetForeshoreProfile(calc),
                                               unaffectedForeshoreProfile))
                .ToArray();

            ICalculation <ICalculationInput>[] calculationsWithUnaffectedForeshoreProfileAndOutput =
                failureMechanism.Calculations
                .Cast <ICalculation <ICalculationInput> >()
                .Where(calc => ReferenceEquals(GetForeshoreProfile(calc),
                                               unaffectedForeshoreProfile))
                .ToArray();

            // Call
            IEnumerable <IObservable> affectedObjects =
                strategy.UpdateForeshoreProfilesWithImportedData(new[]
            {
                profileToUpdateFrom,
                new TestForeshoreProfile(unaffectedForeshoreProfile.Name,
                                         unaffectedForeshoreProfile.Id)
            },
                                                                 sourceFilePath);

            // Assert
            Assert.IsTrue(calculationsWithUnaffectedForeshoreProfileAndOutput.All(calc => calc.HasOutput));
            Assert.IsTrue(calculationsWithUnaffectedForeshoreProfile.All(calc => ReferenceEquals(GetForeshoreProfile(calc),
                                                                                                 unaffectedForeshoreProfile)));

            Assert.IsTrue(calculationsWithUpdatedForeshoreProfile.All(calc => !calc.HasOutput));
            Assert.IsTrue(calculationsWithUpdatedForeshoreProfile.All(calc => ReferenceEquals(GetForeshoreProfile(calc),
                                                                                              profileToBeUpdated)));

            Assert.IsTrue(calculationsWithRemovedForeshoreProfile.All(calc => !calc.HasOutput));
            Assert.IsTrue(calculationsWithRemovedForeshoreProfile.All(calc => GetForeshoreProfile(calc) == null));

            var expectedAffectedObjects = new List <IObservable>
            {
                foreshoreProfiles,
                profileToBeUpdated
            };

            expectedAffectedObjects.AddRange(calculationsWithUpdatedForeshoreProfileWithOutputs);
            expectedAffectedObjects.AddRange(calculationsWithRemovedForeshoreProfileWithOutputs);
            expectedAffectedObjects.AddRange(calculationsWithUpdatedForeshoreProfile.Select(calc => calc.InputParameters));
            expectedAffectedObjects.AddRange(calculationsWithRemovedForeshoreProfile.Select(calc => calc.InputParameters));

            CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects);
        }