Ejemplo n.º 1
0
        public void WaveHeightCalculationsView_CalculationUpdated_IllustrationPointsControlCorrectlyUpdated()
        {
            // Setup
            IObservableEnumerable <HydraulicBoundaryLocationCalculation> hydraulicBoundaryLocationCalculations = GetTestHydraulicBoundaryLocationCalculations();

            ShowFullyConfiguredWaveHeightCalculationsView(hydraulicBoundaryLocationCalculations, testForm);

            IllustrationPointsControl illustrationPointsControl       = GetIllustrationPointsControl();
            DataGridViewControl       calculationsDataGridViewControl = GetCalculationsDataGridViewControl();

            calculationsDataGridViewControl.SetCurrentCell(calculationsDataGridViewControl.GetCell(2, 0));

            // Precondition
            CollectionAssert.IsEmpty(illustrationPointsControl.Data);

            var topLevelIllustrationPoints = new[]
            {
                new TopLevelSubMechanismIllustrationPoint(WindDirectionTestFactory.CreateTestWindDirection(),
                                                          "Regular",
                                                          new TestSubMechanismIllustrationPoint())
            };
            var generalResult = new TestGeneralResultSubMechanismIllustrationPoint(topLevelIllustrationPoints);
            var output        = new TestHydraulicBoundaryLocationCalculationOutput(generalResult);

            // Call
            HydraulicBoundaryLocationCalculation hydraulicBoundaryLocationCalculation = hydraulicBoundaryLocationCalculations.ElementAt(2);

            hydraulicBoundaryLocationCalculation.Output = output;
            hydraulicBoundaryLocationCalculation.NotifyObservers();

            // Assert
            IEnumerable <IllustrationPointControlItem> expectedControlItems = CreateControlItems(generalResult);

            CollectionAssert.AreEqual(expectedControlItems, illustrationPointsControl.Data, new IllustrationPointControlItemComparer());
        }
Ejemplo n.º 2
0
        public void CalculateForSelectedButton_OneSelected_CallsCalculateWaveHeights()
        {
            // Setup
            IObservableEnumerable <HydraulicBoundaryLocationCalculation> hydraulicBoundaryLocationCalculations = GetTestHydraulicBoundaryLocationCalculations();

            WaveHeightCalculationsView view = ShowFullyConfiguredWaveHeightCalculationsView(hydraulicBoundaryLocationCalculations, testForm);

            DataGridViewControl       calculationsDataGridViewControl = GetCalculationsDataGridViewControl();
            DataGridViewRowCollection rows = calculationsDataGridViewControl.Rows;

            rows[0].Cells[calculateColumnIndex].Value = true;

            var guiService = mockRepository.StrictMock <IHydraulicBoundaryLocationCalculationGuiService>();

            HydraulicBoundaryLocationCalculation[] performedCalculations = null;
            guiService.Expect(ch => ch.CalculateWaveHeights(null, null, int.MinValue, null)).IgnoreArguments().WhenCalled(
                invocation =>
            {
                performedCalculations = ((IEnumerable <HydraulicBoundaryLocationCalculation>)invocation.Arguments[0]).ToArray();
            });
            mockRepository.ReplayAll();

            view.CalculationGuiService = guiService;
            var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm);

            // Call
            buttonTester.Click();

            // Assert
            Assert.AreEqual(1, performedCalculations.Length);
            Assert.AreSame(hydraulicBoundaryLocationCalculations.First(), performedCalculations.First());
        }
Ejemplo n.º 3
0
            /// <summary>
            /// Is invoked when the origin set has been changed.
            /// </summary>
            /// <param name="collection">Modified collection</param>
            /// <param name="args">Event arguments</param>
            private void OnOriginSetChanged(IObservableEnumerable <TElement> collection, CollectionChangedEventArgs <TElement> args)
            {
                lock (_originSet) {
                    if (_elementCache == null)
                    {
                        return;                        // Elements haven't been request yet
                    }
                    // If the origin set has been clear, there can't be any elements
                    if (args.Reason == ECollectionChangeReason.Cleared)
                    {
                        _elementCache.Clear();
                        RaiseSubsetChangedEvent(ClearEvent, default(TElement));
                        return;
                    }

                    // An item has been added or removed, but is it relevant for this subset?
                    bool isRelevant = _wherePredicate(args.Item);
                    if (!isRelevant)
                    {
                        return;
                    }

                    if (args.Reason == ECollectionChangeReason.Added)
                    {
                        _elementCache.Add(args.Item);
                        RaiseSubsetChangedEvent(AddEvent, args.Item);
                    }
                    else
                    {
                        _elementCache.Remove(args.Item);
                        RaiseSubsetChangedEvent(RemoveEvent, args.Item);
                    }
                }
            }
        /// <summary>
        /// Creates a new instance of <see cref="HydraulicBoundaryCalculationsView"/>.
        /// </summary>
        /// <param name="calculations">The calculations to show in the view.</param>
        /// <param name="assessmentSection">The assessment section which the calculations belong to.</param>
        /// <exception cref="ArgumentNullException">Thrown when any input parameter is <c>null</c>.</exception>
        protected HydraulicBoundaryCalculationsView(IObservableEnumerable <HydraulicBoundaryLocationCalculation> calculations,
                                                    IAssessmentSection assessmentSection)
        {
            if (calculations == null)
            {
                throw new ArgumentNullException(nameof(calculations));
            }

            if (assessmentSection == null)
            {
                throw new ArgumentNullException(nameof(assessmentSection));
            }

            AssessmentSection = assessmentSection;

            calculationsObserver = new Observer(UpdateDataGridViewDataSource);
            calculationObserver  = new RecursiveObserver <IObservableEnumerable <HydraulicBoundaryLocationCalculation>, HydraulicBoundaryLocationCalculation>(HandleHydraulicBoundaryLocationCalculationUpdate, hblc => hblc);

            this.calculations = calculations;

            calculationsObserver.Observable = calculations;
            calculationObserver.Observable  = calculations;

            UpdateDataGridViewDataSource();
        }
 /// <summary>
 /// Creates a new instance of <see cref="NonAdoptableFailureMechanismResultView{TFailureMechanism}"/>.
 /// </summary>
 /// <param name="failureMechanismSectionResults">The collection of <see cref="NonAdoptableFailureMechanismSectionResult"/> to
 /// show in the view.</param>
 /// <param name="failureMechanism">The failure mechanism the results belong to.</param>
 /// <param name="assessmentSection">The assessment section the failure mechanism results belong to.</param>
 /// <param name="performFailureMechanismAssemblyFunc">The function to perform an assembly on the failure mechanism.</param>
 /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
 public NonAdoptableFailureMechanismResultView(IObservableEnumerable <NonAdoptableFailureMechanismSectionResult> failureMechanismSectionResults,
                                               TFailureMechanism failureMechanism,
                                               IAssessmentSection assessmentSection,
                                               Func <TFailureMechanism, IAssessmentSection, FailureMechanismAssemblyResultWrapper> performFailureMechanismAssemblyFunc)
     : base(failureMechanismSectionResults, failureMechanism, assessmentSection, performFailureMechanismAssemblyFunc)
 {
 }
        /// <summary>
        /// Creates a new instance of <see cref="NonAdoptableWithProfileProbabilityFailureMechanismResultView{TFailureMechanism}"/>.
        /// </summary>
        /// <param name="failureMechanismSectionResults">The collection of <see cref="NonAdoptableWithProfileProbabilityFailureMechanismSectionResult"/> to
        /// show in the view.</param>
        /// <param name="failureMechanism">The failure mechanism the results belong to.</param>
        /// <param name="assessmentSection">The assessment section the failure mechanism belongs to.</param>
        /// <param name="performFailureMechanismAssemblyFunc">Function to perform the assembly for a failure mechanism.</param>
        /// <param name="getUseLengthEffectFunc">The <see cref="Func{T1,TResult}"/> to get whether to use the length effect.</param>
        /// <param name="performFailureMechanismSectionAssemblyFunc">Function to perform the assembly for a failure mechanism section result.</param>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        public NonAdoptableWithProfileProbabilityFailureMechanismResultView(IObservableEnumerable <NonAdoptableWithProfileProbabilityFailureMechanismSectionResult> failureMechanismSectionResults,
                                                                            TFailureMechanism failureMechanism,
                                                                            IAssessmentSection assessmentSection,
                                                                            Func <TFailureMechanism, IAssessmentSection, FailureMechanismAssemblyResultWrapper> performFailureMechanismAssemblyFunc,
                                                                            Func <TFailureMechanism, bool> getUseLengthEffectFunc,
                                                                            Func <NonAdoptableWithProfileProbabilityFailureMechanismSectionResult, FailureMechanismSectionAssemblyResultWrapper> performFailureMechanismSectionAssemblyFunc)
            : base(failureMechanismSectionResults, failureMechanism, assessmentSection, performFailureMechanismAssemblyFunc)
        {
            if (assessmentSection == null)
            {
                throw new ArgumentNullException(nameof(assessmentSection));
            }

            if (getUseLengthEffectFunc == null)
            {
                throw new ArgumentNullException(nameof(getUseLengthEffectFunc));
            }

            if (performFailureMechanismSectionAssemblyFunc == null)
            {
                throw new ArgumentNullException(nameof(performFailureMechanismSectionAssemblyFunc));
            }

            this.getUseLengthEffectFunc = getUseLengthEffectFunc;
            this.performFailureMechanismSectionAssemblyFunc = performFailureMechanismSectionAssemblyFunc;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates a new instance of <see cref="PipingFailureMechanismResultView"/>.
        /// </summary>
        /// <param name="failureMechanismSectionResults">The collection of <see cref="AdoptableWithProfileProbabilityFailureMechanismSectionResult"/> to
        /// show in the view.</param>
        /// <param name="failureMechanism">The failure mechanism the results belong to.</param>
        /// <param name="assessmentSection">The assessment section the failure mechanism results belong to.</param>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        public PipingFailureMechanismResultView(IObservableEnumerable <AdoptableWithProfileProbabilityFailureMechanismSectionResult> failureMechanismSectionResults,
                                                PipingFailureMechanism failureMechanism,
                                                IAssessmentSection assessmentSection)
            : base(failureMechanismSectionResults, failureMechanism, assessmentSection, PipingFailureMechanismAssemblyFactory.AssembleFailureMechanism)
        {
            // The concat is needed to observe the input of calculations in child groups.
            calculationInputsObserver = new RecursiveObserver <CalculationGroup, ICalculationInput>(
                UpdateInternalViewData,
                cg => cg.Children.Concat <object>(cg.Children
                                                  .OfType <IPipingCalculationScenario <PipingInput> >()
                                                  .Select(c => c.InputParameters)))
            {
                Observable = failureMechanism.CalculationsGroup
            };
            calculationGroupObserver = new RecursiveObserver <CalculationGroup, ICalculationBase>(
                UpdateInternalViewData,
                c => c.Children)
            {
                Observable = failureMechanism.CalculationsGroup
            };

            scenarioConfigurationsPerSectionObserver = new RecursiveObserver <IObservableEnumerable <PipingScenarioConfigurationPerFailureMechanismSection>, PipingScenarioConfigurationPerFailureMechanismSection>(
                UpdateInternalViewData,
                sc => sc)
            {
                Observable = failureMechanism.ScenarioConfigurationsPerFailureMechanismSection
            };
        }
        public void CalculateForSelectedButton_OneCalculationSelected_CalculateForSelectedCalculationAndKeepOriginalSelection()
        {
            // Setup
            var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase
            {
                FilePath = hydraulicBoundaryDatabaseFilePath
            };

            HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(hydraulicBoundaryDatabase);

            var assessmentSection = mocks.Stub <IAssessmentSection>();

            assessmentSection.Stub(a => a.Id).Return("1");
            assessmentSection.Stub(a => a.FailureMechanismContribution).Return(FailureMechanismContributionTestFactory.CreateFailureMechanismContribution());
            assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(hydraulicBoundaryDatabase);
            assessmentSection.Stub(a => a.Attach(null)).IgnoreArguments();
            assessmentSection.Stub(a => a.Detach(null)).IgnoreArguments();

            var calculationsObserver = mocks.StrictMock <IObserver>();

            var calculatorFactory = mocks.StrictMock <IHydraRingCalculatorFactory>();

            calculatorFactory.Expect(cf => cf.CreateDunesBoundaryConditionsCalculator(null))
            .IgnoreArguments()
            .Return(new TestDunesBoundaryConditionsCalculator());
            mocks.ReplayAll();

            IObservableEnumerable <DuneLocationCalculation> calculations = GenerateDuneLocationCalculations();
            var failureMechanism = new DuneErosionFailureMechanism();

            using (DuneLocationCalculationsView view = ShowDuneLocationCalculationsView(calculations,
                                                                                        failureMechanism,
                                                                                        assessmentSection))
            {
                var    dataGridView            = (DataGridView)view.Controls.Find("dataGridView", true)[0];
                object originalDataSource      = dataGridView.DataSource;
                DataGridViewRowCollection rows = dataGridView.Rows;
                rows[0].Cells[calculateColumnIndex].Value = true;

                calculations.Attach(calculationsObserver);

                var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm);

                using (var viewParent = new TestViewParentForm())
                    using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
                    {
                        view.CalculationGuiService = new DuneLocationCalculationGuiService(viewParent);

                        // Call
                        buttonTester.Click();

                        // Assert
                        Assert.AreSame(originalDataSource, dataGridView.DataSource);

                        Assert.IsTrue((bool)rows[0].Cells[calculateColumnIndex].Value);
                        Assert.IsFalse((bool)rows[1].Cells[calculateColumnIndex].Value);
                    }
            }
        }
 private RecursiveObserver <IObservableEnumerable <DuneLocationCalculation>, DuneLocationCalculation> CreateDuneLocationCalculationsObserver(
     IObservableEnumerable <DuneLocationCalculation> calculations)
 {
     return(new RecursiveObserver <IObservableEnumerable <DuneLocationCalculation>, DuneLocationCalculation>(
                UpdateFeatures, calc => calc)
     {
         Observable = calculations
     });
 }
        /// <summary>
        /// Creates a new instance of <see cref="DuneLocationCalculationsView"/>.
        /// </summary>
        /// <param name="calculations">The calculations to show in the view.</param>
        /// <param name="failureMechanism">The failure mechanism which the calculations belong to.</param>
        /// <param name="assessmentSection">The assessment section which the calculations belong to.</param>
        /// <param name="getTargetProbabilityFunc"><see cref="Func{TResult}"/> for getting the target probability to use during calculations.</param>
        /// <param name="getCalculationIdentifierFunc"><see cref="Func{TResult}"/> for getting the calculation identifier to use in all messages.</param>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        public DuneLocationCalculationsView(IObservableEnumerable <DuneLocationCalculation> calculations,
                                            DuneErosionFailureMechanism failureMechanism,
                                            IAssessmentSection assessmentSection,
                                            Func <double> getTargetProbabilityFunc,
                                            Func <string> getCalculationIdentifierFunc)
        {
            if (calculations == null)
            {
                throw new ArgumentNullException(nameof(calculations));
            }

            if (failureMechanism == null)
            {
                throw new ArgumentNullException(nameof(failureMechanism));
            }

            if (assessmentSection == null)
            {
                throw new ArgumentNullException(nameof(assessmentSection));
            }

            if (getTargetProbabilityFunc == null)
            {
                throw new ArgumentNullException(nameof(getTargetProbabilityFunc));
            }

            if (getCalculationIdentifierFunc == null)
            {
                throw new ArgumentNullException(nameof(getCalculationIdentifierFunc));
            }

            InitializeComponent();

            this.calculations                 = calculations;
            this.getTargetProbabilityFunc     = getTargetProbabilityFunc;
            this.getCalculationIdentifierFunc = getCalculationIdentifierFunc;
            FailureMechanism  = failureMechanism;
            AssessmentSection = assessmentSection;

            duneLocationCalculationsObserver = new Observer(UpdateDataGridViewDataSource)
            {
                Observable = calculations
            };

            duneLocationCalculationObserver = new RecursiveObserver <IObservableEnumerable <DuneLocationCalculation>, DuneLocationCalculation>(() => dataGridViewControl.RefreshDataGridView(), list => list)
            {
                Observable = calculations
            };

            failureMechanismObserver = new Observer(UpdateCalculateForSelectedButton)
            {
                Observable = failureMechanism
            };

            UpdateDataGridViewDataSource();
        }
        public void Init(
            UnityAction <BlueprintContainer> viewButtonCallback,
            UnityAction <BlueprintContainer> viewSelectionCallback,
            IObservableEnumerable <BlueprintContainer> enumerable)
        {
            this.viewButtonCallback = viewButtonCallback;

            selectedViewRemoved.AddListener(viewSelectionCallback);
            Source = enumerable;
        }
Ejemplo n.º 12
0
        public ConvertedObservableCollection(IObservableEnumerable <S> sourceCollection, Func <S, T> convertItem, Action <T> detachItem = null)
        {
            this.sourceCollection    = sourceCollection;
            this.convertedCollection = new ObservableCollection <T>();

            this.convertItem = convertItem;
            this.detachItem  = detachItem;

            Build();

            sourceCollection.CollectionChanged    += SourceCollectionChanged;
            convertedCollection.CollectionChanged += ConvertedCollectionChanged;
        }
Ejemplo n.º 13
0
        public void Init(IObservableEnumerable <BlueprintContainer> source)
        {
            blueprintTypes.BuildList(viewController.CreateTab);
            viewController.Init(fleetView.Toggle, fleetView.Remove, source);

            // NOTE: placeholder value, should be updated later
            var unityCapacity = 5;

            fleetView.Create(unityCapacity, viewController.GetView);
            fleetValidator = new FleetValidator();

            Validate();
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Creates a new instance of <see cref="FailureMechanismResultView{TSectionResult,TSectionResultRow,TFailureMechanism}"/>.
        /// </summary>
        /// <param name="failureMechanismSectionResults">The collection of <typeparamref name="TSectionResult"/> to
        /// show in the view.</param>
        /// <param name="failureMechanism">The failure mechanism the results belong to.</param>
        /// <param name="assessmentSection">The assessment section the results belong to.</param>
        /// <param name="performFailureMechanismAssemblyFunc">The function to perform an assembly on the failure mechanism.</param>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        protected FailureMechanismResultView(IObservableEnumerable <TSectionResult> failureMechanismSectionResults,
                                             TFailureMechanism failureMechanism,
                                             IAssessmentSection assessmentSection,
                                             Func <TFailureMechanism, IAssessmentSection, FailureMechanismAssemblyResultWrapper> performFailureMechanismAssemblyFunc)
        {
            if (failureMechanismSectionResults == null)
            {
                throw new ArgumentNullException(nameof(failureMechanismSectionResults));
            }

            if (failureMechanism == null)
            {
                throw new ArgumentNullException(nameof(failureMechanism));
            }

            if (assessmentSection == null)
            {
                throw new ArgumentNullException(nameof(assessmentSection));
            }

            if (performFailureMechanismAssemblyFunc == null)
            {
                throw new ArgumentNullException(nameof(performFailureMechanismAssemblyFunc));
            }

            InitializeComponent();

            FailureMechanism  = failureMechanism;
            AssessmentSection = assessmentSection;
            this.failureMechanismSectionResults      = failureMechanismSectionResults;
            this.performFailureMechanismAssemblyFunc = performFailureMechanismAssemblyFunc;

            failureMechanismObserver = new Observer(UpdateInternalViewData)
            {
                Observable = failureMechanism
            };

            failureMechanismSectionResultObserver = new Observer(UpdateInternalViewData)
            {
                Observable = failureMechanismSectionResults
            };

            failureMechanismSectionResultsObserver = new RecursiveObserver <IObservableEnumerable <TSectionResult>, TSectionResult>(
                UpdateSectionResultRows,
                sr => sr)
            {
                Observable = failureMechanismSectionResults
            };

            InitializeComboBox();
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Creates a new instance of <see cref="HydraulicBoundaryLocationCalculationsProperties"/>.
        /// </summary>
        /// <param name="hydraulicBoundaryLocationCalculations">The collection of hydraulic boundary location calculations to set as data.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="hydraulicBoundaryLocationCalculations"/> is <c>null</c>.</exception>
        protected HydraulicBoundaryLocationCalculationsProperties(IObservableEnumerable <HydraulicBoundaryLocationCalculation> hydraulicBoundaryLocationCalculations)
        {
            if (hydraulicBoundaryLocationCalculations == null)
            {
                throw new ArgumentNullException(nameof(hydraulicBoundaryLocationCalculations));
            }

            Data = hydraulicBoundaryLocationCalculations;

            hydraulicBoundaryLocationCalculationsObserver = new RecursiveObserver <IObservableEnumerable <HydraulicBoundaryLocationCalculation>, HydraulicBoundaryLocationCalculation>(OnRefreshRequired, hblc => hblc)
            {
                Observable = hydraulicBoundaryLocationCalculations
            };
        }
        private DuneLocationCalculationsView ShowDuneLocationCalculationsView(IObservableEnumerable <DuneLocationCalculation> calculations,
                                                                              DuneErosionFailureMechanism failureMechanism,
                                                                              IAssessmentSection assessmentSection)
        {
            var view = new DuneLocationCalculationsView(calculations,
                                                        failureMechanism,
                                                        assessmentSection,
                                                        () => 0.01,
                                                        () => "1/100");

            testForm.Controls.Add(view);
            testForm.Show();

            return(view);
        }
Ejemplo n.º 17
0
        private static WaveHeightCalculationsView ShowWaveHeightCalculationsView(IObservableEnumerable <HydraulicBoundaryLocationCalculation> calculations,
                                                                                 IAssessmentSection assessmentSection,
                                                                                 double targetProbability,
                                                                                 string calculationIdentifier,
                                                                                 Form form)
        {
            var view = new WaveHeightCalculationsView(calculations,
                                                      assessmentSection,
                                                      () => targetProbability,
                                                      () => calculationIdentifier);

            form.Controls.Add(view);
            form.Show();

            return(view);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Creates a new instance of <see cref="FailureMechanismSectionResultContext{T}"/>.
        /// </summary>
        /// <param name="wrappedSectionResults">The <see cref="IObservableEnumerable{T}"/> of <typeparamref name="T"/> to wrap.</param>
        /// <param name="failureMechanism">The <see cref="IFailureMechanism"/> the <paramref name="wrappedSectionResults"/> belongs to.</param>
        /// <param name="assessmentSection">The assessment section the section results belongs to.</param>
        /// <exception cref="ArgumentNullException">Thrown when any input argument is <c>null</c>.</exception>
        public FailureMechanismSectionResultContext(IObservableEnumerable <T> wrappedSectionResults, IFailureMechanism failureMechanism,
                                                    IAssessmentSection assessmentSection)
            : base(wrappedSectionResults)
        {
            if (failureMechanism == null)
            {
                throw new ArgumentNullException(nameof(failureMechanism));
            }

            if (assessmentSection == null)
            {
                throw new ArgumentNullException(nameof(assessmentSection));
            }

            FailureMechanism  = failureMechanism;
            AssessmentSection = assessmentSection;
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Creates a new instance of <see cref="WaterLevelCalculationsForNormTargetProbabilityContext"/>.
        /// </summary>
        /// <param name="wrappedData">The calculations wrapped by the <see cref="WaterLevelCalculationsForNormTargetProbabilityContext"/>.</param>
        /// <param name="assessmentSection">The <see cref="IAssessmentSection"/> that the <see cref="WaterLevelCalculationsForNormTargetProbabilityContext"/> belongs to.</param>
        /// <param name="getNormFunc"><see cref="Func{TResult}"/> for obtaining the norm target probability to use during calculations.</param>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        public WaterLevelCalculationsForNormTargetProbabilityContext(IObservableEnumerable <HydraulicBoundaryLocationCalculation> wrappedData,
                                                                     IAssessmentSection assessmentSection,
                                                                     Func <double> getNormFunc)
            : base(wrappedData)
        {
            if (assessmentSection == null)
            {
                throw new ArgumentNullException(nameof(assessmentSection));
            }

            if (getNormFunc == null)
            {
                throw new ArgumentNullException(nameof(getNormFunc));
            }

            AssessmentSection = assessmentSection;
            GetNormFunc       = getNormFunc;
        }
        public void GivenFullyConfiguredDuneLocationCalculationsView_WhenEachDuneLocationCalculationOutputClearedAndNotified_ThenDataGridViewRowsRefreshedWithNewValues()
        {
            // Given
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            IObservableEnumerable <DuneLocationCalculation> calculations = GenerateDuneLocationCalculations();

            using (DuneLocationCalculationsView view = ShowDuneLocationCalculationsView(calculations,
                                                                                        new DuneErosionFailureMechanism(),
                                                                                        assessmentSection))
            {
                // Precondition
                var dataGridView = (DataGridView)view.Controls.Find("dataGridView", true)[0];
                DataGridViewRowCollection rows = dataGridView.Rows;
                Assert.AreEqual(2, rows.Count);
                DataGridViewRow firstRow  = rows[0];
                DataGridViewRow secondRow = rows[1];

                Assert.AreEqual("-", firstRow.Cells[waterLevelColumnIndex].FormattedValue);
                Assert.AreEqual("-", firstRow.Cells[waveHeightColumnIndex].FormattedValue);
                Assert.AreEqual("-", firstRow.Cells[wavePeriodColumnIndex].FormattedValue);
                Assert.AreEqual(1.23.ToString(CultureInfo.CurrentCulture), secondRow.Cells[waterLevelColumnIndex].FormattedValue);
                Assert.AreEqual(2.34.ToString(CultureInfo.CurrentCulture), secondRow.Cells[waveHeightColumnIndex].FormattedValue);
                Assert.AreEqual(3.45.ToString(CultureInfo.CurrentCulture), secondRow.Cells[wavePeriodColumnIndex].FormattedValue);

                // When
                calculations.ForEachElementDo(calculation =>
                {
                    calculation.Output = null;
                    calculation.NotifyObservers();
                });

                // Then
                Assert.AreEqual(2, rows.Count);
                Assert.AreEqual("-", firstRow.Cells[waterLevelColumnIndex].FormattedValue);
                Assert.AreEqual("-", firstRow.Cells[waveHeightColumnIndex].FormattedValue);
                Assert.AreEqual("-", firstRow.Cells[wavePeriodColumnIndex].FormattedValue);
                Assert.AreEqual("-", secondRow.Cells[waterLevelColumnIndex].FormattedValue);
                Assert.AreEqual("-", secondRow.Cells[waveHeightColumnIndex].FormattedValue);
                Assert.AreEqual("-", secondRow.Cells[wavePeriodColumnIndex].FormattedValue);
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Creates a <see cref="RecursiveObserver{TContainer,TObservable}"/> for an enumeration of hydraulic boundary location calculations.
        /// </summary>
        /// <param name="calculations">The calculations to observe.</param>
        /// <param name="updateObserverAction">The action to perform on notifications coming from one of the calculations.</param>
        /// <returns>The created <see cref="RecursiveObserver{TContainer,TObservable}"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        public static RecursiveObserver <IObservableEnumerable <HydraulicBoundaryLocationCalculation>, HydraulicBoundaryLocationCalculation> CreateHydraulicBoundaryLocationCalculationsObserver(
            IObservableEnumerable <HydraulicBoundaryLocationCalculation> calculations, Action updateObserverAction)
        {
            if (calculations == null)
            {
                throw new ArgumentNullException(nameof(calculations));
            }

            if (updateObserverAction == null)
            {
                throw new ArgumentNullException(nameof(updateObserverAction));
            }

            return(new RecursiveObserver <IObservableEnumerable <HydraulicBoundaryLocationCalculation>, HydraulicBoundaryLocationCalculation>(
                       updateObserverAction, calc => calc)
            {
                Observable = calculations
            });
        }
        public void CreateInput_WithOneFailureMechanism_ReturnsInputCollection(AssessmentSection assessmentSection, IFailureMechanism failureMechanismInAssembly)
        {
            // Setup
            assessmentSection.GetFailureMechanisms()
            .ForEachElementDo(failureMechanism => failureMechanism.InAssembly = failureMechanism == failureMechanismInAssembly);

            using (new AssemblyToolCalculatorFactoryConfig())
            {
                // Call
                IEnumerable <IEnumerable <CombinedAssemblyFailureMechanismSection> > inputs = CombinedAssemblyFailureMechanismSectionFactory.CreateInput(
                    assessmentSection, new[]
                {
                    failureMechanismInAssembly
                });

                // Assert
                IObservableEnumerable <FailureMechanismSectionResult> failureMechanismSectionResults = ((IFailureMechanism <FailureMechanismSectionResult>)failureMechanismInAssembly).SectionResults;
                AssertSections(failureMechanismSectionResults, inputs.Single());
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Creates a new instance of <see cref="WaveHeightCalculationsView"/>.
        /// </summary>
        /// <param name="calculations">The calculations to show in the view.</param>
        /// <param name="assessmentSection">The assessment section which the calculations belong to.</param>
        /// <param name="getTargetProbabilityFunc"><see cref="Func{TResult}"/> for getting the target probability to use during calculations.</param>
        /// <param name="getCalculationIdentifierFunc"><see cref="Func{TResult}"/> for getting the calculation identifier to use in all messages.</param>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        public WaveHeightCalculationsView(IObservableEnumerable <HydraulicBoundaryLocationCalculation> calculations,
                                          IAssessmentSection assessmentSection,
                                          Func <double> getTargetProbabilityFunc,
                                          Func <string> getCalculationIdentifierFunc)
            : base(calculations, assessmentSection)
        {
            if (getTargetProbabilityFunc == null)
            {
                throw new ArgumentNullException(nameof(getTargetProbabilityFunc));
            }

            if (getCalculationIdentifierFunc == null)
            {
                throw new ArgumentNullException(nameof(getCalculationIdentifierFunc));
            }

            InitializeComponent();

            this.getTargetProbabilityFunc     = getTargetProbabilityFunc;
            this.getCalculationIdentifierFunc = getCalculationIdentifierFunc;
        }
Ejemplo n.º 24
0
 /// <summary>
 /// Creates a new instance of <see cref="GrassCoverErosionInwardsFailureMechanismResultView"/>.
 /// </summary>
 /// <param name="failureMechanismSectionResults">The collection of
 /// <see cref="AdoptableWithProfileProbabilityFailureMechanismSectionResult"/> to show in the view.</param>
 /// <param name="failureMechanism">The failure mechanism the results belong to.</param>
 /// <param name="assessmentSection">The assessment section the failure mechanism results belong to.</param>
 /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
 public GrassCoverErosionInwardsFailureMechanismResultView(IObservableEnumerable <AdoptableWithProfileProbabilityFailureMechanismSectionResult> failureMechanismSectionResults,
                                                           GrassCoverErosionInwardsFailureMechanism failureMechanism,
                                                           IAssessmentSection assessmentSection)
     : base(failureMechanismSectionResults, failureMechanism, assessmentSection, GrassCoverErosionInwardsFailureMechanismAssemblyFactory.AssembleFailureMechanism)
 {
     // The concat is needed to observe the input of calculations in child groups.
     calculationInputsObserver = new RecursiveObserver <CalculationGroup, ICalculationInput>(
         UpdateInternalViewData,
         cg => cg.Children.Concat <object>(cg.Children
                                           .OfType <GrassCoverErosionInwardsCalculationScenario>()
                                           .Select(c => c.InputParameters)))
     {
         Observable = failureMechanism.CalculationsGroup
     };
     calculationGroupObserver = new RecursiveObserver <CalculationGroup, ICalculationBase>(
         UpdateInternalViewData,
         c => c.Children)
     {
         Observable = failureMechanism.CalculationsGroup
     };
 }
 /// <summary>
 /// Creates a new instance of <see cref="StructuresFailureMechanismResultView{TFailureMechanism,TStructuresInput}"/>.
 /// </summary>
 /// <param name="failureMechanismSectionResults">The collection of <see cref="AdoptableFailureMechanismSectionResult"/> to
 /// show in the view.</param>
 /// <param name="failureMechanism">The failure mechanism the results belong to.</param>
 /// <param name="assessmentSection">The assessment section the failure mechanism results belong to.</param>
 /// <param name="performFailureMechanismAssemblyFunc">The function to perform an assembly on the failure mechanism.</param>
 /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
 public StructuresFailureMechanismResultView(IObservableEnumerable <AdoptableFailureMechanismSectionResult> failureMechanismSectionResults,
                                             TFailureMechanism failureMechanism,
                                             IAssessmentSection assessmentSection,
                                             Func <TFailureMechanism, IAssessmentSection, FailureMechanismAssemblyResultWrapper> performFailureMechanismAssemblyFunc)
     : base(failureMechanismSectionResults, failureMechanism, assessmentSection, performFailureMechanismAssemblyFunc)
 {
     // The concat is needed to observe the input of calculations in child groups.
     calculationInputsObserver = new RecursiveObserver <CalculationGroup, ICalculationInput>(
         UpdateInternalViewData,
         cg => cg.Children.Concat(cg.Children
                                  .OfType <StructuresCalculationScenario <TStructuresInput> >()
                                  .Select(scenario => scenario.InputParameters)
                                  .Cast <object>()))
     {
         Observable = failureMechanism.CalculationsGroup
     };
     calculationGroupObserver = new RecursiveObserver <CalculationGroup, ICalculationBase>(
         UpdateInternalViewData,
         c => c.Children)
     {
         Observable = failureMechanism.CalculationsGroup
     };
 }
Ejemplo n.º 26
0
        public void WhereIteration()
        {
            // Arrange
            ObservableCollection <int>  set    = new ObservableCollection <int>(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
            IObservableEnumerable <int> subset = set.Where(i => i % 2 == 0);

            CollectionListener collectionListener = new CollectionListener();

            subset.AddListener(collectionListener);

            int[] array1 = subset.ToArray();

            // Act
            set.Add(12);
            set.Add(13);
            set.Add(14);
            int[] array2 = subset.ToArray();

            // Assert
            CollectionAssert.AreEqual(new[] { 2, 4, 6, 8 }, array1);
            CollectionAssert.AreEqual(new[] { 2, 4, 6, 8, 12, 14 }, array2);
            CollectionAssert.AreEqual(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 13, 14 }, set); // Origin set must(!) be modified
            Assert.AreEqual(2, collectionListener.Added);
        }
Ejemplo n.º 27
0
        public void WaveHeightCalculationsView_CalculationUpdated_DataGridViewCorrectlyUpdated()
        {
            // Setup
            IObservableEnumerable <HydraulicBoundaryLocationCalculation> hydraulicBoundaryLocationCalculations = GetTestHydraulicBoundaryLocationCalculations();

            ShowFullyConfiguredWaveHeightCalculationsView(hydraulicBoundaryLocationCalculations, testForm);

            // Precondition
            DataGridViewControl        calculationsDataGridViewControl = GetCalculationsDataGridViewControl();
            DataGridViewRowCollection  rows  = calculationsDataGridViewControl.Rows;
            DataGridViewCellCollection cells = rows[0].Cells;

            Assert.AreEqual(6, cells.Count);
            Assert.AreEqual(false, cells[includeIllustrationPointsColumnIndex].FormattedValue);

            HydraulicBoundaryLocationCalculation calculation = hydraulicBoundaryLocationCalculations.First();

            // Call
            calculation.InputParameters.ShouldIllustrationPointsBeCalculated = true;
            calculation.NotifyObservers();

            // Assert
            Assert.AreEqual(true, cells[includeIllustrationPointsColumnIndex].FormattedValue);
        }
Ejemplo n.º 28
0
 private void initTriggerCollectionProxies()
 {
     macroTriggersCollectionProxy = new ObservableList <MacroTriggerWithArguments>();
     macroTriggersProxyCollection = new ObservableProxyEnumerable <MacroTriggerWithArgumentsProxy, MacroTriggerWithArguments>(macroTriggersCollectionProxy, mtwa => new MacroTriggerWithArgumentsProxy(mtwa));
 }
 /// <summary>
 /// Creates a new instance of <see cref="WaterLevelCalculationsForNormTargetProbabilityProperties"/>.
 /// </summary>
 /// <param name="hydraulicBoundaryLocationCalculations">The collection of hydraulic boundary location calculations to set as data.</param>
 /// <param name="normTargetProbability">The norm target probability.</param>
 /// <exception cref="ArgumentNullException">Thrown when <paramref name="hydraulicBoundaryLocationCalculations"/> is <c>null</c>.</exception>
 public WaterLevelCalculationsForNormTargetProbabilityProperties(IObservableEnumerable <HydraulicBoundaryLocationCalculation> hydraulicBoundaryLocationCalculations,
                                                                 double normTargetProbability)
     : base(hydraulicBoundaryLocationCalculations)
 {
     TargetProbability = normTargetProbability;
 }
 /// <summary>
 /// Creates a new instance of <see cref="ClosingStructuresFailureMechanismSectionResultContext"/>.
 /// </summary>
 /// <param name="wrappedSectionResults">The <see cref="IObservableEnumerable{T}"/>
 /// of <see cref="AdoptableFailureMechanismSectionResult"/> to wrap.</param>
 /// <param name="failureMechanism">The <see cref="ClosingStructuresFailureMechanism"/>
 /// the <paramref name="wrappedSectionResults"/> belongs to.</param>
 /// <param name="assessmentSection">The assessment section the section results belongs to.</param>
 /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
 public ClosingStructuresFailureMechanismSectionResultContext(IObservableEnumerable <AdoptableFailureMechanismSectionResult> wrappedSectionResults,
                                                              IFailureMechanism failureMechanism, IAssessmentSection assessmentSection)
     : base(wrappedSectionResults, failureMechanism, assessmentSection)
 {
 }