public void Calculate_CalculationRanErrorInSettingIllustrationPoints_IllustrationPointsNotSetAndLogsWarning() { // Setup const string locationName = "locationName"; var calculator = new TestDesignWaterLevelCalculator { IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultWithDuplicateStochasts(), Converged = true }; var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>(); calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(null)) .IgnoreArguments() .Return(calculator); var calculationMessageProvider = mockRepository.StrictMock <ICalculationMessageProvider>(); mockRepository.ReplayAll(); var hydraulicBoundaryLocationCalculation = new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation(locationName)) { InputParameters = { ShouldIllustrationPointsBeCalculated = true } }; using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call Action call = () => new DesignWaterLevelCalculationService().Calculate(hydraulicBoundaryLocationCalculation, CreateCalculationSettings(), 1.0 / 30, calculationMessageProvider); // Assert TestHelper.AssertLogMessagesWithLevelAndLoggedExceptions(call, messages => { Tuple <string, Level, Exception>[] tupleArray = messages.ToArray(); string[] msgs = tupleArray.Select(tuple => tuple.Item1).ToArray(); Assert.AreEqual(4, msgs.Length); CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[0]); Assert.AreEqual($"Fout bij het uitlezen van de illustratiepunten voor berekening {locationName}: " + "Een of meerdere stochasten hebben dezelfde naam. " + "Het uitlezen van illustratiepunten wordt overgeslagen.", msgs[1]); Assert.AreEqual($"Waterstand berekening is uitgevoerd op de tijdelijke locatie '{calculator.OutputDirectory}'. " + "Gedetailleerde invoer en uitvoer kan in de bestanden op deze locatie worden gevonden.", msgs[2]); CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[3]); }); Assert.IsNotNull(hydraulicBoundaryLocationCalculation.Output); Assert.IsFalse(hydraulicBoundaryLocationCalculation.Output.HasGeneralResult); } mockRepository.VerifyAll(); }
public void Calculate_CalculationRanErrorInSettingIllustrationPoints_IllustrationPointsNotSetAndLogsWarning() { // Setup var mocks = new MockRepository(); var calculator = new TestStructuresCalculator <ExceedanceProbabilityCalculationInput> { OutputDirectory = validHydraulicBoundaryDatabaseFilePath, IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultWithDuplicateStochasts() }; var calculatorFactory = mocks.StrictMock <IHydraRingCalculatorFactory>(); calculatorFactory.Expect(cf => cf.CreateStructuresCalculator <ExceedanceProbabilityCalculationInput>(null)) .IgnoreArguments() .Return(calculator); const string performedCalculationMessage = "Calculation successful"; var messageProvider = mocks.StrictMock <IStructuresCalculationMessageProvider>(); messageProvider.Expect(mp => mp.GetCalculationPerformedMessage(validHydraulicBoundaryDatabaseFilePath)).Return(performedCalculationMessage); mocks.ReplayAll(); var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); var calculation = new TestStructuresCalculation { InputParameters = { HydraulicBoundaryLocation = hydraulicBoundaryLocation, ShouldIllustrationPointsBeCalculated = true } }; using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { var service = new TestStructuresCalculationService(messageProvider); // Call void Call() => service.Calculate(calculation, new GeneralTestInput(), CreateCalculationSettings()); // Assert TestHelper.AssertLogMessagesWithLevelAndLoggedExceptions(Call, messages => { Tuple <string, Level, Exception>[] tupleArray = messages.ToArray(); string[] msgs = tupleArray.Select(tuple => tuple.Item1).ToArray(); Assert.AreEqual(4, msgs.Length); CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[0]); Assert.AreEqual("Fout bij het uitlezen van de illustratiepunten voor berekening Nieuwe berekening: " + "Een of meerdere stochasten hebben dezelfde naam. Het uitlezen van illustratiepunten wordt overgeslagen.", msgs[1]); Assert.AreEqual(performedCalculationMessage, msgs[2]); CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[3]); }); Assert.IsNotNull(calculation.Output); Assert.IsFalse(calculation.Output.HasGeneralResult); } mocks.VerifyAll(); }