Exemple #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());
        }
Exemple #2
0
        public void GetIllustrationPointControlItems_ViewWithData_ReturnsExpectedControlItems()
        {
            // Setup
            var topLevelIllustrationPoints = new[]
            {
                new TopLevelSubMechanismIllustrationPoint(WindDirectionTestFactory.CreateTestWindDirection(),
                                                          "Regular",
                                                          new TestSubMechanismIllustrationPoint())
            };

            var generalResult = new TestGeneralResultSubMechanismIllustrationPoint(topLevelIllustrationPoints);
            var output        = new TestHydraulicBoundaryLocationCalculationOutput(generalResult);

            var calculation = new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation())
            {
                Output = output
            };
            var calculations = new ObservableList <HydraulicBoundaryLocationCalculation>
            {
                calculation
            };

            TestHydraulicBoundaryCalculationsView view = ShowTestHydraulicBoundaryCalculationsView(calculations);

            // Call
            IEnumerable <IllustrationPointControlItem> actualControlItems =
                view.PublicGetIllustrationPointControlItems();

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

            CollectionAssert.AreEqual(expectedControlItems, actualControlItems,
                                      new IllustrationPointControlItemComparer());
        }
        private static IEnumerable <TestCaseData> GetCalculations()
        {
            var outputWithoutGeneralResult = new TestHydraulicBoundaryLocationCalculationOutput(1.0, CalculationConvergence.CalculatedConverged);
            var outputWithGeneralResult    = new TestHydraulicBoundaryLocationCalculationOutput(1.0, new TestGeneralResultSubMechanismIllustrationPoint());

            yield return(new TestCaseData(new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation())
            {
                InputParameters =
                {
                    ShouldIllustrationPointsBeCalculated = true
                },
                Output = outputWithGeneralResult
            }, false)
                         .SetName("OutputSufficientScenario1"));

            yield return(new TestCaseData(new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation())
            {
                Output = outputWithoutGeneralResult
            }, false)
                         .SetName("OutputSufficientScenario2"));

            yield return(new TestCaseData(new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation()), true)
                         .SetName("NoOutputScenario1"));

            yield return(new TestCaseData(new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation())
            {
                InputParameters =
                {
                    ShouldIllustrationPointsBeCalculated = true
                }
            }, true)
                         .SetName("NoOutputScenario2"));

            yield return(new TestCaseData(new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation())
            {
                Output = outputWithGeneralResult
            }, true)
                         .SetName("OutputWithRedundantGeneralResult"));

            yield return(new TestCaseData(new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation())
            {
                InputParameters =
                {
                    ShouldIllustrationPointsBeCalculated = true
                },
                Output = outputWithoutGeneralResult
            }, true)
                         .SetName("OutputWithMissingGeneralResult"));
        }
Exemple #4
0
        public void Result_WithCalculationOutput_ReturnsResult()
        {
            // Setup
            var hydraulicBoundaryLocationCalculation = new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation());

            var row = new HydraulicBoundaryLocationCalculationRow(hydraulicBoundaryLocationCalculation);

            var random = new Random(432);
            var output = new TestHydraulicBoundaryLocationCalculationOutput(random.NextDouble());

            // Call
            hydraulicBoundaryLocationCalculation.Output = output;

            // Assert
            Assert.AreEqual(output.Result, row.Result);
        }
        public void ClearIllustrationPoints_CalculationWithOutput_ClearsIllustrationPointResult(bool hasIllustrationPoints)
        {
            // Setup
            var random         = new Random(21);
            var originalOutput = new TestHydraulicBoundaryLocationCalculationOutput(random.NextDouble(),
                                                                                    hasIllustrationPoints
                                                                                        ? new TestGeneralResultSubMechanismIllustrationPoint()
                                                                                        : null);
            var calculation = new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation())
            {
                Output = originalOutput
            };

            // Call
            calculation.ClearIllustrationPoints();

            // Assert
            Assert.AreSame(originalOutput, calculation.Output);
            Assert.IsNull(calculation.Output.GeneralResult);
        }
Exemple #6
0
        public void ClearHydraulicBoundaryLocationCalculationIllustrationPoints_CalculationsWithAndWithoutIllustrationPoints_ClearsIllustrationPointAndReturnsAffectedCalculations()
        {
            // Setup
            var random = new Random(21);

            var originalOutputWithIllustrationPoints1 = new TestHydraulicBoundaryLocationCalculationOutput(random.NextDouble(),
                                                                                                           new TestGeneralResultSubMechanismIllustrationPoint());
            var calculationWithIllustrationPoints1 = new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation())
            {
                Output = originalOutputWithIllustrationPoints1
            };

            var originalOutputWithIllustrationPoints2 = new TestHydraulicBoundaryLocationCalculationOutput(random.NextDouble(),
                                                                                                           new TestGeneralResultSubMechanismIllustrationPoint());
            var calculationWithIllustrationPoints2 = new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation())
            {
                Output = originalOutputWithIllustrationPoints2
            };

            var originalOutput1        = new TestHydraulicBoundaryLocationCalculationOutput(random.NextDouble());
            var calculationWithOutput1 = new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation())
            {
                Output = originalOutput1
            };

            var originalOutput2        = new TestHydraulicBoundaryLocationCalculationOutput(random.NextDouble());
            var calculationWithOutput2 = new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation())
            {
                Output = originalOutput2
            };

            HydraulicBoundaryLocationCalculation[] calculations =
            {
                new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation()),
                calculationWithOutput1,
                calculationWithIllustrationPoints1,
                new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation()),
                calculationWithOutput2,
                calculationWithIllustrationPoints2,
                new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation())
            };

            // Call
            IEnumerable <IObservable> affectedCalculations = RiskeerCommonDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationIllustrationPoints(calculations);

            // Assert
            CollectionAssert.AreEquivalent(new[]
            {
                calculationWithIllustrationPoints1,
                calculationWithIllustrationPoints2
            }, affectedCalculations);

            HydraulicBoundaryLocationCalculation[] calculationWithOutputs =
            {
                calculationWithOutput1,
                calculationWithIllustrationPoints1,
                calculationWithOutput2,
                calculationWithIllustrationPoints2
            };
            Assert.IsTrue(calculationWithOutputs.All(calc => calc.HasOutput));
            Assert.IsTrue(calculationWithOutputs.All(calc => !calc.Output.HasGeneralResult));

            AssertHydraulicBoundaryLocationOutput(originalOutput1, calculationWithOutput1.Output);
            AssertHydraulicBoundaryLocationOutput(originalOutput2, calculationWithOutput2.Output);

            AssertHydraulicBoundaryLocationOutput(originalOutputWithIllustrationPoints1, calculationWithIllustrationPoints1.Output);
            AssertHydraulicBoundaryLocationOutput(originalOutputWithIllustrationPoints2, calculationWithIllustrationPoints2.Output);
        }
        public void Run_InvalidCalculation_LogsErrorOutputNotUpdatedAndActivityStateFailed(bool endInFailure, string lastErrorFileContent)
        {
            // Setup
            const string locationName          = "locationName";
            const string calculationIdentifier = "1/100";

            var calculator = new TestDesignWaterLevelCalculator
            {
                EndInFailure         = endInFailure,
                LastErrorFileContent = lastErrorFileContent
            };

            var mockRepository    = new MockRepository();
            var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>();

            calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(null))
            .IgnoreArguments()
            .Return(calculator);
            mockRepository.ReplayAll();

            var output = new TestHydraulicBoundaryLocationCalculationOutput(double.NaN, CalculationConvergence.CalculatedConverged);
            var hydraulicBoundaryLocationCalculation = new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation(locationName))
            {
                InputParameters =
                {
                    ShouldIllustrationPointsBeCalculated = true
                },
                Output = output
            };

            var activity = new DesignWaterLevelCalculationActivity(hydraulicBoundaryLocationCalculation,
                                                                   CreateCalculationSettings(),
                                                                   0.01,
                                                                   calculationIdentifier);

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                // Call
                void Call() => activity.Run();

                // Assert
                TestHelper.AssertLogMessages(Call, m =>
                {
                    string[] messages = m.ToArray();
                    Assert.AreEqual(7, messages.Length);
                    Assert.AreEqual($"{GetActivityDescription(locationName, calculationIdentifier)} is gestart.", messages[0]);
                    CalculationServiceTestHelper.AssertValidationStartMessage(messages[1]);
                    CalculationServiceTestHelper.AssertValidationEndMessage(messages[2]);
                    CalculationServiceTestHelper.AssertCalculationStartMessage(messages[3]);

                    string expectedFailureMessage = string.IsNullOrEmpty(lastErrorFileContent)
                                                        ? $"Er is een fout opgetreden tijdens de waterstand berekening voor locatie '{locationName}' ({calculationIdentifier}). Er is geen foutrapport beschikbaar."
                                                        : $"Er is een fout opgetreden tijdens de waterstand berekening voor locatie '{locationName}' ({calculationIdentifier}). Bekijk het foutrapport door op details te klikken.{Environment.NewLine}{lastErrorFileContent}";
                    Assert.AreEqual(expectedFailureMessage, messages[4]);

                    StringAssert.StartsWith("Waterstand berekening is uitgevoerd op de tijdelijke locatie", messages[5]);
                    CalculationServiceTestHelper.AssertCalculationEndMessage(messages[6]);
                });

                Assert.AreSame(output, hydraulicBoundaryLocationCalculation.Output);
                Assert.AreEqual(CalculationConvergence.CalculatedConverged, hydraulicBoundaryLocationCalculation.Output.CalculationConvergence);
                Assert.AreEqual(ActivityState.Failed, activity.State);
            }

            mockRepository.VerifyAll();
        }