コード例 #1
0
        public void IsEnabled_SourcePathSet_ReturnTrue()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();
            var failureMechanism  = mocks.Stub <ICalculatableFailureMechanism>();

            mocks.ReplayAll();

            var foreshoreProfiles = new ForeshoreProfileCollection();

            foreshoreProfiles.AddRange(Enumerable.Empty <ForeshoreProfile>(),
                                       "path");

            var context = new ForeshoreProfilesContext(foreshoreProfiles, failureMechanism, assessmentSection);

            using (var plugin = new RiskeerPlugin())
            {
                UpdateInfo updateInfo = GetUpdateInfo(plugin);

                // Call
                bool isEnabled = updateInfo.IsEnabled(context);

                // Assert
                Assert.IsTrue(isEnabled);
            }

            mocks.VerifyAll();
        }
コード例 #2
0
        public void UpdateForeshoreProfilesWithImportedData_CollectionAndImportedCollectionNotEmpty_ReplaceCurrentWithImportedData()
        {
            // Setup
            var foreshoreProfiles = new ForeshoreProfileCollection();

            foreshoreProfiles.AddRange(new[]
            {
                new TestForeshoreProfile("Profile 1", "ID 1")
            }, sourceFilePath);

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

            var importedForeshoreProfiles = new[]
            {
                new TestForeshoreProfile("Profile 2", "ID 2")
            };

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

            // Assert
            CollectionAssert.AreEqual(importedForeshoreProfiles, foreshoreProfiles);
            CollectionAssert.AreEqual(new IObservable[]
            {
                foreshoreProfiles
            }, affectedObjects);
        }
コード例 #3
0
        public void CurrentPath_ForeshoreProfileCollectionHasPathSet_ReturnsExpectedPath()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();
            var failureMechanism  = mocks.Stub <ICalculatableFailureMechanism>();

            mocks.ReplayAll();

            const string expectedFilePath  = "some/path";
            var          foreshoreProfiles = new ForeshoreProfileCollection();

            foreshoreProfiles.AddRange(new[]
            {
                new TestForeshoreProfile()
            }, expectedFilePath);

            var context = new ForeshoreProfilesContext(foreshoreProfiles, failureMechanism, assessmentSection);

            using (var plugin = new RiskeerPlugin())
            {
                UpdateInfo updateInfo = GetUpdateInfo(plugin);

                // Call
                string currentFilePath = updateInfo.CurrentPath(context);

                // Assert
                Assert.AreEqual(expectedFilePath, currentFilePath);
                mocks.VerifyAll();
            }
        }
コード例 #4
0
        public void ForeColor_CollectionHasElements_ReturnControlText()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();
            var failureMechanism  = mocks.Stub <ICalculatableFailureMechanism>();

            mocks.ReplayAll();

            var collection = new ForeshoreProfileCollection();

            collection.AddRange(new[]
            {
                new TestForeshoreProfile()
            }, "path");

            var context = new ForeshoreProfilesContext(collection, failureMechanism, assessmentSection);

            // Call
            Color color = info.ForeColor(context);

            // Assert
            Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), color);
            mocks.ReplayAll();
        }
コード例 #5
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);
        }
コード例 #6
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);
        }
コード例 #7
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);
        }
コード例 #8
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);
        }
コード例 #9
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);
        }
コード例 #10
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);
        }
コード例 #11
0
        public void Constructor_WithData_ReturnExpectedValues()
        {
            // Setup
            const string someFilePath = "location/to/a/file";
            var          collection   = new ForeshoreProfileCollection();

            collection.AddRange(Enumerable.Empty <ForeshoreProfile>(), someFilePath);

            // Call
            var properties = new ForeshoreProfileCollectionProperties(collection);

            // Assert
            Assert.IsInstanceOf <ObjectProperties <ForeshoreProfileCollection> >(properties);
            Assert.AreSame(collection, properties.Data);
            Assert.AreEqual(someFilePath, properties.SourcePath);
        }
コード例 #12
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);
        }
コード例 #13
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);
        }
コード例 #14
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);
        }
コード例 #15
0
        public void ChildNodeObjects_Always_ReturnChildrenOfCollection()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();
            var failureMechanism  = mocks.Stub <ICalculatableFailureMechanism>();

            mocks.ReplayAll();

            ForeshoreProfile profile1 = new TestForeshoreProfile("A", "ID A");
            ForeshoreProfile profile2 = new TestForeshoreProfile("B", "ID B");
            ForeshoreProfile profile3 = new TestForeshoreProfile("C", "ID C");
            var collection            = new ForeshoreProfileCollection();

            collection.AddRange(new[]
            {
                profile1,
                profile2,
                profile3
            }, "path");

            var context = new ForeshoreProfilesContext(collection, failureMechanism, assessmentSection);

            // Call
            object[] children = info.ChildNodeObjects(context);

            // Assert
            ForeshoreProfile[] expectedChildren =
            {
                profile1,
                profile2,
                profile3
            };
            CollectionAssert.AreEqual(expectedChildren, children);
            mocks.ReplayAll();
        }
コード例 #16
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);
        }