public void Run_HydraulicBoundaryDatabaseWithCanUsePreprocessorFalse_CreateWaveConditionsCosineCalculatorAsExpected() { // Setup IAssessmentSection assessmentSection = CreateAssessmentSectionWithHydraulicBoundaryOutput(); StabilityStoneCoverWaveConditionsCalculation calculation = CreateValidCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First()); CalculatableActivity activity = StabilityStoneCoverWaveConditionsCalculationActivityFactory.CreateCalculationActivity( calculation, new StabilityStoneCoverFailureMechanism(), assessmentSection); var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>(); calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull)) .WhenCalled(invocation => { HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings( HydraulicBoundaryCalculationSettingsFactory.CreateSettings(assessmentSection.HydraulicBoundaryDatabase), (HydraRingCalculationSettings)invocation.Arguments[0]); }) .Return(new TestWaveConditionsCosineCalculator()) .Repeat .Times(GetWaterLevels(calculation, assessmentSection).Count() * 2); mockRepository.ReplayAll(); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call activity.Run(); } // Assert mockRepository.VerifyAll(); }
public void Run_CalculationPerformed_SetsOutput() { // Setup IAssessmentSection assessmentSection = CreateAssessmentSectionWithHydraulicBoundaryOutput(); StabilityStoneCoverWaveConditionsCalculation calculation = CreateValidCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First()); CalculatableActivity activity = StabilityStoneCoverWaveConditionsCalculationActivityFactory.CreateCalculationActivity( calculation, new StabilityStoneCoverFailureMechanism(), assessmentSection); var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>(); calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null)) .IgnoreArguments() .Return(new TestWaveConditionsCosineCalculator()) .Repeat .Times(GetWaterLevels(calculation, assessmentSection).Count() * 2); mockRepository.ReplayAll(); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call activity.Run(); // Assert Assert.IsNotNull(calculation.Output); Assert.AreEqual(3, calculation.Output.ColumnsOutput.Count()); Assert.AreEqual(3, calculation.Output.BlocksOutput.Count()); } mockRepository.VerifyAll(); }
private void Calculate(StabilityStoneCoverWaveConditionsCalculationContext context) { ActivityProgressDialogRunner.Run(Gui.MainWindow, StabilityStoneCoverWaveConditionsCalculationActivityFactory.CreateCalculationActivity( context.WrappedData, context.FailureMechanism, context.AssessmentSection)); }
public void Cancel_WhenPerformingCalculationForBlocks_CurrentCalculationForWaterLevelCompletesAndSubsequentCalculationsDidNotRun() { // Setup IAssessmentSection assessmentSection = CreateAssessmentSectionWithHydraulicBoundaryOutput(); StabilityStoneCoverWaveConditionsCalculation calculation = CreateValidCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First()); CalculatableActivity activity = StabilityStoneCoverWaveConditionsCalculationActivityFactory.CreateCalculationActivity( calculation, new StabilityStoneCoverFailureMechanism(), assessmentSection); var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>(); var calculator = new TestWaveConditionsCosineCalculator(); calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null)) .IgnoreArguments() .Return(calculator); mockRepository.ReplayAll(); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { activity.ProgressChanged += (sender, args) => { if (activity.State != ActivityState.Canceled && activity.ProgressText.Contains("Stap 1 van 6")) { // Call activity.Cancel(); } }; // Assert TestHelper.AssertLogMessages(() => activity.Run(), messages => { string[] msgs = messages.ToArray(); RoundedDouble firstWaterLevel = GetWaterLevels(calculation, assessmentSection).First(); Assert.AreEqual(10, msgs.Length); Assert.AreEqual($"Golfcondities berekenen voor '{calculation.Name}' is gestart.", msgs[0]); CalculationServiceTestHelper.AssertValidationStartMessage(msgs[1]); CalculationServiceTestHelper.AssertValidationEndMessage(msgs[2]); CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[3]); Assert.AreEqual("Berekening voor blokken is gestart.", msgs[4]); Assert.AreEqual($"Berekening voor waterstand '{firstWaterLevel}' is gestart.", msgs[5]); StringAssert.StartsWith("Golfcondities berekening is uitgevoerd op de tijdelijke locatie", msgs[6]); Assert.AreEqual($"Berekening voor waterstand '{firstWaterLevel}' is beëindigd.", msgs[7]); Assert.AreEqual("Berekening voor blokken is beëindigd.", msgs[8]); CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[9]); }); Assert.AreEqual(ActivityState.Canceled, activity.State); } mockRepository.VerifyAll(); }
public void Run_CalculationWithInvalidHydraulicBoundaryDatabaseFilePath_DoesNotPerformCalculationAndLogsError() { // Setup string invalidFilePath = Path.Combine(testDataPath, "NonExisting.sqlite"); var assessmentSection = new AssessmentSectionStub { HydraulicBoundaryDatabase = { FilePath = invalidFilePath } }; var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation }); StabilityStoneCoverWaveConditionsCalculation calculation = CreateValidCalculation(hydraulicBoundaryLocation); CalculatableActivity activity = StabilityStoneCoverWaveConditionsCalculationActivityFactory.CreateCalculationActivity( calculation, new StabilityStoneCoverFailureMechanism(), assessmentSection); var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>(); mockRepository.ReplayAll(); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call void Call() => activity.Run(); // Assert TestHelper.AssertLogMessages(Call, messages => { string[] msgs = messages.ToArray(); Assert.AreEqual(4, msgs.Length); Assert.AreEqual($"Golfcondities berekenen voor '{calculation.Name}' is gestart.", msgs[0]); CalculationServiceTestHelper.AssertValidationStartMessage(msgs[1]); Assert.AreEqual("Herstellen van de verbinding met de hydraulische belastingendatabase is mislukt. " + $"Fout bij het lezen van bestand '{invalidFilePath}': het bestand bestaat niet.", msgs[2]); CalculationServiceTestHelper.AssertValidationEndMessage(msgs[3]); }); Assert.AreEqual(ActivityState.Failed, activity.State); } mockRepository.VerifyAll(); }
public void CreateCalculationActivity_AssessmentSectionNull_ThrowsArgumentNullException() { // Setup var calculation = new StabilityStoneCoverWaveConditionsCalculation(); var failureMechanism = new StabilityStoneCoverFailureMechanism(); // Call void Call() => StabilityStoneCoverWaveConditionsCalculationActivityFactory.CreateCalculationActivity(calculation, failureMechanism, null); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("assessmentSection", exception.ParamName); }
public void CreateCalculationActivity_FailureMechanismNull_ThrowsArgumentNullException() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); // Call void Call() => StabilityStoneCoverWaveConditionsCalculationActivityFactory.CreateCalculationActivity(new StabilityStoneCoverWaveConditionsCalculation(), null, assessmentSection); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("failureMechanism", exception.ParamName); mocks.VerifyAll(); }
public void Run_Always_SetProgressTexts() { // Setup IAssessmentSection assessmentSection = CreateAssessmentSectionWithHydraulicBoundaryOutput(); StabilityStoneCoverWaveConditionsCalculation calculation = CreateValidCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First()); CalculatableActivity activity = StabilityStoneCoverWaveConditionsCalculationActivityFactory.CreateCalculationActivity( calculation, new StabilityStoneCoverFailureMechanism(), assessmentSection); RoundedDouble[] waterLevels = GetWaterLevels(calculation, assessmentSection).ToArray(); var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>(); calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null)) .IgnoreArguments() .Return(new TestWaveConditionsCosineCalculator()) .Repeat .Times(waterLevels.Length * 2); mockRepository.ReplayAll(); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { var progressTexts = new List <string>(); activity.ProgressChanged += (sender, args) => progressTexts.Add(activity.ProgressText); // Call activity.Run(); // Assert int totalSteps = waterLevels.Length * 2; for (var i = 0; i < totalSteps; i++) { string revetment = i < waterLevels.Length ? "blokken" : "zuilen"; var text = $"Stap {i + 1} van {totalSteps} | Waterstand '{waterLevels[i % waterLevels.Length]}' [m+NAP] voor {revetment} berekenen."; Assert.AreEqual(text, progressTexts[i]); } } mockRepository.VerifyAll(); }
public void Run_WhenCanceled_OutputNull() { // Setup IAssessmentSection assessmentSection = CreateAssessmentSectionWithHydraulicBoundaryOutput(); StabilityStoneCoverWaveConditionsCalculation calculation = CreateValidCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First()); CalculatableActivity activity = StabilityStoneCoverWaveConditionsCalculationActivityFactory.CreateCalculationActivity( calculation, new StabilityStoneCoverFailureMechanism(), assessmentSection); var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>(); calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null)) .IgnoreArguments() .Return(new TestWaveConditionsCosineCalculator()); mockRepository.ReplayAll(); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { activity.ProgressChanged += (sender, args) => { if (activity.State != ActivityState.Canceled) { activity.Cancel(); } }; activity.Run(); // Call activity.Finish(); // Assert Assert.AreEqual(ActivityState.Canceled, activity.State); Assert.IsNull(calculation.Output); } mockRepository.VerifyAll(); }
public void Finish_VariousCalculationEndStates_NotifiesObserversOfCalculation(bool endInFailure) { // Setup var mockRepository = new MockRepository(); var observer = mockRepository.StrictMock <IObserver>(); observer.Expect(o => o.UpdateObserver()); var calculatorFactory = mockRepository.Stub <IHydraRingCalculatorFactory>(); calculatorFactory.Stub(cf => cf.CreateWaveConditionsCosineCalculator(null)) .IgnoreArguments() .Return(new TestWaveConditionsCosineCalculator { EndInFailure = endInFailure }); mockRepository.ReplayAll(); IAssessmentSection assessmentSection = CreateAssessmentSectionWithHydraulicBoundaryOutput(); StabilityStoneCoverWaveConditionsCalculation calculation = CreateValidCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First()); calculation.Attach(observer); CalculatableActivity activity = StabilityStoneCoverWaveConditionsCalculationActivityFactory.CreateCalculationActivity( calculation, new StabilityStoneCoverFailureMechanism(), assessmentSection); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { activity.Run(); } // Call activity.Finish(); // Assert mockRepository.VerifyAll(); }
public void Run_CalculationWithInvalidPreprocessorDirectory_DoesNotPerformCalculationAndLogsError() { // Setup IAssessmentSection assessmentSection = CreateAssessmentSectionWithHydraulicBoundaryOutput(); StabilityStoneCoverWaveConditionsCalculation calculation = CreateValidCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First()); assessmentSection.HydraulicBoundaryDatabase.HydraulicLocationConfigurationSettings.CanUsePreprocessor = true; assessmentSection.HydraulicBoundaryDatabase.HydraulicLocationConfigurationSettings.UsePreprocessor = true; assessmentSection.HydraulicBoundaryDatabase.HydraulicLocationConfigurationSettings.PreprocessorDirectory = "InvalidPreprocessorDirectory"; CalculatableActivity activity = StabilityStoneCoverWaveConditionsCalculationActivityFactory.CreateCalculationActivity( calculation, new StabilityStoneCoverFailureMechanism(), assessmentSection); var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>(); mockRepository.ReplayAll(); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call void Call() => activity.Run(); // Assert TestHelper.AssertLogMessages(Call, messages => { string[] msgs = messages.ToArray(); Assert.AreEqual(4, msgs.Length); Assert.AreEqual($"Golfcondities berekenen voor '{calculation.Name}' is gestart.", msgs[0]); CalculationServiceTestHelper.AssertValidationStartMessage(msgs[1]); Assert.AreEqual("De bestandsmap waar de preprocessor bestanden opslaat is ongeldig. De bestandsmap bestaat niet.", msgs[2]); CalculationServiceTestHelper.AssertValidationEndMessage(msgs[3]); }); Assert.AreEqual(ActivityState.Failed, activity.State); } mockRepository.VerifyAll(); }
public void CreateCalculationActivity_WithValidCalculation_ReturnsStabilityStoneCoverWaveConditionsCalculationActivityWithParametersSet() { // Setup StabilityStoneCoverFailureMechanism failureMechanism = new StabilityStoneCoverFailureMechanism(); AssessmentSectionStub assessmentSection = CreateAssessmentSection(); var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); SetHydraulicBoundaryLocationToAssessmentSection(assessmentSection, hydraulicBoundaryLocation); StabilityStoneCoverWaveConditionsCalculation calculation = CreateValidCalculation(hydraulicBoundaryLocation); // Call CalculatableActivity activity = StabilityStoneCoverWaveConditionsCalculationActivityFactory.CreateCalculationActivity(calculation, failureMechanism, assessmentSection); // Assert Assert.IsInstanceOf <StabilityStoneCoverWaveConditionsCalculationActivity>(activity); AssertStabilityStoneCoverWaveConditionsCalculationActivity(activity, calculation, assessmentSection.WaterLevelCalculationsForSignalFloodingProbability.Single().Output.Result, assessmentSection.HydraulicBoundaryDatabase); }
public void Run_CalculationFailed_OutputNull(bool endInFailure, string lastErrorFileContent) { // Setup IAssessmentSection assessmentSection = CreateAssessmentSectionWithHydraulicBoundaryOutput(); StabilityStoneCoverWaveConditionsCalculation calculation = CreateValidCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First()); CalculatableActivity activity = StabilityStoneCoverWaveConditionsCalculationActivityFactory.CreateCalculationActivity( calculation, new StabilityStoneCoverFailureMechanism(), assessmentSection); var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>(); calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null)) .IgnoreArguments() .Return(new TestWaveConditionsCosineCalculator { EndInFailure = endInFailure, LastErrorFileContent = lastErrorFileContent }) .Repeat .Times(GetWaterLevels(calculation, assessmentSection).Count()); mockRepository.ReplayAll(); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call activity.Run(); // Assert Assert.IsNull(calculation.Output); } mockRepository.VerifyAll(); }
public void Run_Always_InputPropertiesCorrectlySentToService(BreakWaterType breakWaterType) { // Setup IAssessmentSection assessmentSection = CreateAssessmentSectionWithHydraulicBoundaryOutput(); StabilityStoneCoverWaveConditionsCalculation calculation = CreateValidCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First()); calculation.InputParameters.BreakWater.Type = breakWaterType; var stabilityStoneCoverFailureMechanism = new StabilityStoneCoverFailureMechanism(); CalculatableActivity activity = StabilityStoneCoverWaveConditionsCalculationActivityFactory.CreateCalculationActivity(calculation, stabilityStoneCoverFailureMechanism, assessmentSection); var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>(); var calculator = new TestWaveConditionsCosineCalculator(); RoundedDouble[] waterLevels = GetWaterLevels(calculation, assessmentSection).ToArray(); int nrOfCalculators = waterLevels.Length * 2; calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null)) .IgnoreArguments() .Return(calculator) .Repeat .Times(nrOfCalculators); mockRepository.ReplayAll(); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call activity.Run(); // Assert WaveConditionsCosineCalculationInput[] waveConditionsInputs = calculator.ReceivedInputs.ToArray(); Assert.AreEqual(nrOfCalculators, waveConditionsInputs.Length); GeneralStabilityStoneCoverWaveConditionsInput generalInput = stabilityStoneCoverFailureMechanism.GeneralInput; WaveConditionsInput input = calculation.InputParameters; double targetProbability = assessmentSection.FailureMechanismContribution.MaximumAllowableFloodingProbability; var waterLevelIndex = 0; for (var i = 0; i < waveConditionsInputs.Length / 2; i++) { var expectedInput = new WaveConditionsCosineCalculationInput(1, input.Orientation, input.HydraulicBoundaryLocation.Id, targetProbability, input.ForeshoreProfile.Geometry.Select(c => new HydraRingForelandPoint(c.X, c.Y)), new HydraRingBreakWater(BreakWaterTypeHelper.GetHydraRingBreakWaterType(breakWaterType), input.BreakWater.Height), waterLevels[waterLevelIndex++], generalInput.GeneralBlocksWaveConditionsInput.A, generalInput.GeneralBlocksWaveConditionsInput.B, generalInput.GeneralBlocksWaveConditionsInput.C); HydraRingDataEqualityHelper.AreEqual(expectedInput, waveConditionsInputs[i]); } waterLevelIndex = 0; for (int i = waveConditionsInputs.Length / 2; i < waveConditionsInputs.Length; i++) { var expectedInput = new WaveConditionsCosineCalculationInput(1, input.Orientation, input.HydraulicBoundaryLocation.Id, targetProbability, input.ForeshoreProfile.Geometry.Select(c => new HydraRingForelandPoint(c.X, c.Y)), new HydraRingBreakWater(BreakWaterTypeHelper.GetHydraRingBreakWaterType(breakWaterType), input.BreakWater.Height), waterLevels[waterLevelIndex++], generalInput.GeneralColumnsWaveConditionsInput.A, generalInput.GeneralColumnsWaveConditionsInput.B, generalInput.GeneralColumnsWaveConditionsInput.C); HydraRingDataEqualityHelper.AreEqual(expectedInput, waveConditionsInputs[i]); } } mockRepository.VerifyAll(); }