/// <summary>
        /// Creates a collection of <see cref="CalculatableActivity"/> for all relevant calculations
        /// in the given <see cref="AssessmentSection"/>.
        /// </summary>
        /// <param name="assessmentSection">The assessment section to create the activities for.</param>
        /// <returns>A collection of <see cref="CalculatableActivity"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="assessmentSection"/> is <c>null</c>.</exception>
        public static IEnumerable <CalculatableActivity> CreateCalculationActivities(AssessmentSection assessmentSection)
        {
            if (assessmentSection == null)
            {
                throw new ArgumentNullException(nameof(assessmentSection));
            }

            var activities = new List <CalculatableActivity>();

            activities.AddRange(PipingCalculationActivityFactory.CreateCalculationActivities(
                                    assessmentSection.Piping,
                                    assessmentSection));
            activities.AddRange(GrassCoverErosionInwardsCalculationActivityFactory.CreateCalculationActivities(
                                    assessmentSection.GrassCoverErosionInwards,
                                    assessmentSection));
            activities.AddRange(MacroStabilityInwardsCalculationActivityFactory.CreateCalculationActivities(
                                    assessmentSection.MacroStabilityInwards,
                                    assessmentSection));
            activities.AddRange(HeightStructuresCalculationActivityFactory.CreateCalculationActivities(
                                    assessmentSection.HeightStructures,
                                    assessmentSection));
            activities.AddRange(ClosingStructuresCalculationActivityFactory.CreateCalculationActivities(
                                    assessmentSection.ClosingStructures,
                                    assessmentSection));
            activities.AddRange(StabilityPointStructuresCalculationActivityFactory.CreateCalculationActivities(
                                    assessmentSection.StabilityPointStructures,
                                    assessmentSection));

            return(activities);
        }
        public void CreateCalculationActivitiesForFailureMechanism_AssessmentSectionNull_ThrowsArgumentNullException()
        {
            // Call
            void Call() => PipingCalculationActivityFactory.CreateCalculationActivities(new PipingFailureMechanism(), null);

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

            Assert.AreEqual("assessmentSection", exception.ParamName);
        }
        public void CreateCalculationActivitiesForFailureMechanism_FailureMechanismNull_ThrowsArgumentNullException()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            // Call
            void Call() => PipingCalculationActivityFactory.CreateCalculationActivities(null, assessmentSection);

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

            Assert.AreEqual("failureMechanism", exception.ParamName);
            mocks.VerifyAll();
        }
        public void CreateCalculationActivitiesForFailureMechanism_UnsupportedCalculationType_ThrowsNotSupportedException()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var failureMechanism = new PipingFailureMechanism();

            failureMechanism.CalculationsGroup.Children.Add(new TestPipingCalculation());

            // Call
            void Call() => PipingCalculationActivityFactory.CreateCalculationActivities(
                failureMechanism, assessmentSection);

            // Assert
            Assert.Throws <NotSupportedException>(Call);
            mocks.VerifyAll();
        }
        public void CreateCalculationActivitiesForCalculationGroup_UnsupportedCalculationType_ThrowsNotSupportedException()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var calculationGroup = new CalculationGroup
            {
                Children =
                {
                    new TestPipingCalculation()
                }
            };

            // Call
            void Call() => PipingCalculationActivityFactory.CreateCalculationActivities(
                calculationGroup, new PipingFailureMechanism(), assessmentSection);

            // Assert
            Assert.Throws <NotSupportedException>(Call);
            mocks.VerifyAll();
        }
        public void CreateCalculationActivitiesForFailureMechanism_WithValidCalculations_ReturnsPipingCalculationActivitiesWithParametersSet()
        {
            // Setup
            var assessmentSection = new AssessmentSectionStub
            {
                FailureMechanismContribution =
                {
                    NormativeProbabilityType = NormativeProbabilityType.MaximumAllowableFloodingProbability
                }
            };

            var hydraulicBoundaryLocation1 = new TestHydraulicBoundaryLocation();
            var hydraulicBoundaryLocation2 = new TestHydraulicBoundaryLocation();
            TestPipingFailureMechanism failureMechanism = TestPipingFailureMechanism.GetFailureMechanismWithSurfaceLinesAndStochasticSoilModels();

            assessmentSection.SetHydraulicBoundaryLocationCalculations(new[]
            {
                hydraulicBoundaryLocation1,
                hydraulicBoundaryLocation2
            });

            assessmentSection.HydraulicBoundaryDatabase.FilePath = validHydraulicBoundaryDatabaseFilePath;
            HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(assessmentSection.HydraulicBoundaryDatabase);

            var random = new Random(39);

            HydraulicBoundaryLocationCalculation hydraulicBoundaryLocationCalculation1 = assessmentSection.WaterLevelCalculationsForMaximumAllowableFloodingProbability.First();

            hydraulicBoundaryLocationCalculation1.Output = new TestHydraulicBoundaryLocationCalculationOutput(random.NextDouble());

            HydraulicBoundaryLocationCalculation hydraulicBoundaryLocationCalculation2 = assessmentSection.WaterLevelCalculationsForMaximumAllowableFloodingProbability.ElementAt(1);

            hydraulicBoundaryLocationCalculation2.Output = new TestHydraulicBoundaryLocationCalculationOutput(random.NextDouble());

            var calculation1 =
                SemiProbabilisticPipingCalculationTestFactory.CreateCalculationWithValidInput <TestSemiProbabilisticPipingCalculation>(
                    hydraulicBoundaryLocation1);
            var calculation2 =
                ProbabilisticPipingCalculationTestFactory.CreateCalculationWithValidInput <TestProbabilisticPipingCalculation>(
                    hydraulicBoundaryLocation1);
            var calculation3 =
                SemiProbabilisticPipingCalculationTestFactory.CreateCalculationWithValidInput <TestSemiProbabilisticPipingCalculation>(
                    hydraulicBoundaryLocation2);
            var calculation4 =
                ProbabilisticPipingCalculationTestFactory.CreateCalculationWithValidInput <TestProbabilisticPipingCalculation>(
                    hydraulicBoundaryLocation2);

            failureMechanism.CalculationsGroup.Children.AddRange(new IPipingCalculation <PipingInput>[]
            {
                calculation1,
                calculation2,
                calculation3,
                calculation4
            });

            // Call
            IEnumerable <CalculatableActivity> activities = PipingCalculationActivityFactory.CreateCalculationActivities(
                failureMechanism, assessmentSection);

            // Assert
            Assert.AreEqual(4, activities.Count());

            CalculatableActivity activity1 = activities.ElementAt(0);

            Assert.IsInstanceOf <SemiProbabilisticPipingCalculationActivity>(activity1);
            AssertSemiProbabilisticPipingCalculationActivity(activity1, calculation1, hydraulicBoundaryLocationCalculation1);

            CalculatableActivity activity2 = activities.ElementAt(1);

            Assert.IsInstanceOf <ProbabilisticPipingCalculationActivity>(activity2);
            AssertProbabilisticPipingCalculationActivity(activity2, calculation2, hydraulicBoundaryLocation1);

            CalculatableActivity activity3 = activities.ElementAt(2);

            Assert.IsInstanceOf <SemiProbabilisticPipingCalculationActivity>(activity3);
            AssertSemiProbabilisticPipingCalculationActivity(activity3, calculation3, hydraulicBoundaryLocationCalculation2);

            CalculatableActivity activity4 = activities.ElementAt(3);

            Assert.IsInstanceOf <ProbabilisticPipingCalculationActivity>(activity4);
            AssertProbabilisticPipingCalculationActivity(activity4, calculation4, hydraulicBoundaryLocation2);
        }