public void Cancel_WhenPerformingCalculation_CurrentCalculationForWaterLevelCompletesAndSubsequentCalculationsDidNotRun() { // Setup AssessmentSectionStub assessmentSection = CreateAssessmentSection(); ConfigureAssessmentSectionWithHydraulicBoundaryOutput(assessmentSection); GrassCoverErosionOutwardsWaveConditionsCalculation calculation = CreateValidCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First()); var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); CalculatableActivity activity = GrassCoverErosionOutwardsCalculationActivityFactory.CreateWaveConditionsCalculationActivity(calculation, failureMechanism, 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) { // 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 golfoploop 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 golfoploop is beëindigd.", msgs[8]); CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[9]); }); Assert.AreEqual(ActivityState.Canceled, activity.State); Assert.IsNull(calculation.Output); } mockRepository.VerifyAll(); }
public void Run_WhenCanceled_OutputNull() { // Setup AssessmentSectionStub assessmentSection = CreateAssessmentSection(); ConfigureAssessmentSectionWithHydraulicBoundaryOutput(assessmentSection); GrassCoverErosionOutwardsWaveConditionsCalculation calculation = CreateValidCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First()); var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); CalculatableActivity activity = GrassCoverErosionOutwardsCalculationActivityFactory.CreateWaveConditionsCalculationActivity(calculation, failureMechanism, 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 Cancel_WhenPerformingCalculationForColumns_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>(); calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null)) .IgnoreArguments() .Return(new TestWaveConditionsCosineCalculator()) .Repeat .Times(4); mockRepository.ReplayAll(); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { activity.ProgressChanged += (sender, args) => { if (activity.State != ActivityState.Canceled && activity.ProgressText.Contains("Stap 4 van 6")) { // Call activity.Cancel(); } }; // Assert TestHelper.AssertLogMessages(() => activity.Run(), messages => { string[] msgs = messages.ToArray(); RoundedDouble[] waterLevels = GetWaterLevels(calculation, assessmentSection).ToArray(); Assert.AreEqual(21, 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 '{waterLevels[0]}' is gestart.", msgs[5]); StringAssert.StartsWith("Golfcondities berekening is uitgevoerd op de tijdelijke locatie", msgs[6]); Assert.AreEqual($"Berekening voor waterstand '{waterLevels[0]}' is beëindigd.", msgs[7]); Assert.AreEqual($"Berekening voor waterstand '{waterLevels[1]}' is gestart.", msgs[8]); StringAssert.StartsWith("Golfcondities berekening is uitgevoerd op de tijdelijke locatie", msgs[9]); Assert.AreEqual($"Berekening voor waterstand '{waterLevels[1]}' is beëindigd.", msgs[10]); Assert.AreEqual($"Berekening voor waterstand '{waterLevels[2]}' is gestart.", msgs[11]); StringAssert.StartsWith("Golfcondities berekening is uitgevoerd op de tijdelijke locatie", msgs[12]); Assert.AreEqual($"Berekening voor waterstand '{waterLevels[2]}' is beëindigd.", msgs[13]); Assert.AreEqual("Berekening voor blokken is beëindigd.", msgs[14]); Assert.AreEqual("Berekening voor zuilen is gestart.", msgs[15]); Assert.AreEqual($"Berekening voor waterstand '{waterLevels[0]}' is gestart.", msgs[16]); StringAssert.StartsWith("Golfcondities berekening is uitgevoerd op de tijdelijke locatie", msgs[17]); Assert.AreEqual($"Berekening voor waterstand '{waterLevels[0]}' is beëindigd.", msgs[18]); Assert.AreEqual("Berekening voor zuilen is beëindigd.", msgs[19]); CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[20]); }); Assert.AreEqual(ActivityState.Canceled, activity.State); } mockRepository.VerifyAll(); }