Example #1
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);
        }
Example #2
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);
        }
Example #3
0
        public void UpdateForeshoreProfilesWithImportedData_CalculationsWithForeshoreProfilesAndOutput_CalculationUpdatedAndReturnsAffectedData()
        {
            // Setup
            var foreshoreProfile = new TestForeshoreProfile();
            TestCalculationWithForeshoreProfile calculationWithForeshoreProfileAndOutput =
                TestCalculationWithForeshoreProfile.CreateCalculationWithOutput(foreshoreProfile);
            TestCalculationWithForeshoreProfile calculationWithForeshoreProfile =
                TestCalculationWithForeshoreProfile.CreateCalculationWithoutOutput(foreshoreProfile);
            TestCalculationWithForeshoreProfile calculationWithoutForeshoreProfile =
                TestCalculationWithForeshoreProfile.CreateDefaultCalculation();

            var failureMechanism = new TestCalculatableFailureMechanism(new[]
            {
                calculationWithForeshoreProfileAndOutput,
                calculationWithForeshoreProfile,
                calculationWithoutForeshoreProfile
            });

            var foreshoreProfiles = new ForeshoreProfileCollection();

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

            TestCalculationWithForeshoreProfile[] calculationsWithForeshoreProfile =
            {
                calculationWithForeshoreProfileAndOutput,
                calculationWithForeshoreProfile
            };

            var strategy = new ForeshoreProfileReplaceDataStrategy(failureMechanism, foreshoreProfiles);

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

            // Assert
            CollectionAssert.IsEmpty(foreshoreProfiles);
            Assert.IsFalse(calculationWithForeshoreProfileAndOutput.HasOutput);
            Assert.IsTrue(calculationsWithForeshoreProfile.All(calc => calc.InputParameters.ForeshoreProfile == null));

            IEnumerable <IObservable> expectedAffectedObjects =
                calculationsWithForeshoreProfile.Select(calc => calc.InputParameters)
                .Concat(new IObservable[]
            {
                foreshoreProfiles,
                calculationWithForeshoreProfileAndOutput
            });

            CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects);
        }
Example #4
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);
        }
Example #5
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);
        }