public void CalculateDaily_InputNull_ThrowsArgumentNullException() { // Call void Call() => WaternetCalculationService.CalculateDaily(null, new GeneralMacroStabilityInwardsInput()); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("input", exception.ParamName); }
public void ValidateExtreme_InputNull_ThrowsArgumentNullException() { // Call void Call() => WaternetCalculationService.ValidateExtreme(null, new GeneralMacroStabilityInwardsInput(), RoundedDouble.NaN); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("input", exception.ParamName); }
public void ValidateDaily_NoMessagesInValidation_ReturnEmptyCollection() { // Setup using (new MacroStabilityInwardsCalculatorFactoryConfig()) { // Call IEnumerable <MacroStabilityInwardsKernelMessage> messages = WaternetCalculationService.ValidateDaily(testCalculation.InputParameters, new GeneralMacroStabilityInwardsInput()); // Assert CollectionAssert.IsEmpty(messages); } }
public void ValidateExtreme_GeneralInputNull_ThrowsArgumentNullException() { // Setup MacroStabilityInwardsInput input = testCalculation.InputParameters; // Call void Call() => WaternetCalculationService.ValidateExtreme(input, null, RoundedDouble.NaN); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("generalInput", exception.ParamName); }
public void CalculateDaily_CalculationRan_ReturnMacroStabilityInwardsWaternet() { // Setup using (new MacroStabilityInwardsCalculatorFactoryConfig()) { var calculatorFactory = (TestMacroStabilityInwardsCalculatorFactory)MacroStabilityInwardsCalculatorFactory.Instance; // Call MacroStabilityInwardsWaternet output = WaternetCalculationService.CalculateDaily(testCalculation.InputParameters, new GeneralMacroStabilityInwardsInput()); // Assert CalculatorOutputAssert.AssertWaternet(calculatorFactory.LastCreatedWaternetDailyCalculator.Output, output); } }
public void ValidateExtreme_MessagesInValidation_ReturnValidationMessages() { // Setup using (new MacroStabilityInwardsCalculatorFactoryConfig()) { var calculatorFactory = (TestMacroStabilityInwardsCalculatorFactory)MacroStabilityInwardsCalculatorFactory.Instance; WaternetCalculatorStub calculator = calculatorFactory.LastCreatedWaternetExtremeCalculator; calculator.ReturnValidationError = true; calculator.ReturnValidationWarning = true; // Call IEnumerable <MacroStabilityInwardsKernelMessage> messages = WaternetCalculationService.ValidateExtreme(testCalculation.InputParameters, new GeneralMacroStabilityInwardsInput(), RoundedDouble.NaN); // Assert CollectionAssert.AreEqual(calculator.Validate(), messages, new MacroStabilityInwardsKernelMessageComparer()); } }
public void CalculateDaily_ErrorInCalculation_ReturnMacroStabilityInwardsWaternet() { // Setup using (new MacroStabilityInwardsCalculatorFactoryConfig()) { var calculatorFactory = (TestMacroStabilityInwardsCalculatorFactory)MacroStabilityInwardsCalculatorFactory.Instance; calculatorFactory.LastCreatedWaternetDailyCalculator.ThrowExceptionOnCalculate = true; // Call MacroStabilityInwardsWaternet output = WaternetCalculationService.CalculateDaily(testCalculation.InputParameters, new GeneralMacroStabilityInwardsInput()); // Assert Assert.IsNotNull(output); CollectionAssert.IsEmpty(output.PhreaticLines); CollectionAssert.IsEmpty(output.WaternetLines); } }
public void CalculateDaily_WithInput_SetsInputOnCalculator() { // Setup MacroStabilityInwardsInput input = testCalculation.InputParameters; using (new MacroStabilityInwardsCalculatorFactoryConfig()) { // Call WaternetCalculationService.CalculateDaily(input, new GeneralMacroStabilityInwardsInput()); // Assert var factory = (TestMacroStabilityInwardsCalculatorFactory)MacroStabilityInwardsCalculatorFactory.Instance; WaternetCalculatorInput actualInput = factory.LastCreatedWaternetDailyCalculator.Input; CalculatorInputAssert.AssertDailyInput(input, actualInput); } }
public void ValidateDaily_ErrorInValidation_ThrowsWaternetCalculationException() { // Setup using (new MacroStabilityInwardsCalculatorFactoryConfig()) { var calculatorFactory = (TestMacroStabilityInwardsCalculatorFactory)MacroStabilityInwardsCalculatorFactory.Instance; calculatorFactory.LastCreatedWaternetDailyCalculator.ThrowExceptionOnValidate = true; // Call void Call() => WaternetCalculationService.ValidateDaily(testCalculation.InputParameters, new GeneralMacroStabilityInwardsInput()); // Assert var exception = Assert.Throws <WaternetCalculationException>(Call); Assert.IsInstanceOf <WaternetCalculatorException>(exception.InnerException); Assert.AreEqual(exception.InnerException.Message, exception.Message); } }
public void ValidateExtreme_WithInput_SetsInputOnCalculator() { // Setup RoundedDouble assessmentLevel = new Random(21).NextRoundedDouble(); MacroStabilityInwardsInput input = testCalculation.InputParameters; using (new MacroStabilityInwardsCalculatorFactoryConfig()) { // Call WaternetCalculationService.ValidateExtreme(input, new GeneralMacroStabilityInwardsInput(), assessmentLevel); // Assert var factory = (TestMacroStabilityInwardsCalculatorFactory)MacroStabilityInwardsCalculatorFactory.Instance; WaternetCalculatorInput actualInput = factory.LastCreatedWaternetExtremeCalculator.Input; CalculatorInputAssert.AssertExtremeInput(input, actualInput, assessmentLevel); } }
/// <summary> /// Gets the calculated Waternet for daily circumstances. /// </summary> /// <param name="input">The input to calculate the Waternet for.</param> /// <param name="generalInput">General calculation parameters that are the same across all calculations.</param> /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception> /// <returns>Returns the corresponding derived Waternet value.</returns> public static MacroStabilityInwardsWaternet GetWaternetDaily(MacroStabilityInwardsInput input, GeneralMacroStabilityInwardsInput generalInput) { if (input == null) { throw new ArgumentNullException(nameof(input)); } if (generalInput == null) { throw new ArgumentNullException(nameof(generalInput)); } return(input.SoilProfileUnderSurfaceLine != null ? WaternetCalculationService.CalculateDaily(input, generalInput) : new MacroStabilityInwardsWaternet(new MacroStabilityInwardsPhreaticLine[0], new MacroStabilityInwardsWaternetLine[0])); }
/// <summary> /// Performs validation over the values on the given <paramref name="calculation"/>. Error and status information is logged during /// the execution of the operation. /// </summary> /// <param name="calculation">The <see cref="MacroStabilityInwardsCalculation"/> for which to validate the values.</param> /// <param name="generalInput">General calculation parameters that are the same across all calculations.</param> /// <param name="normativeAssessmentLevel">The normative assessment level to use in case the manual assessment level is not applicable.</param> /// <returns><c>false</c> if <paramref name="calculation"/> contains validation errors; <c>true</c> otherwise.</returns> /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception> public static bool Validate(MacroStabilityInwardsCalculation calculation, GeneralMacroStabilityInwardsInput generalInput, RoundedDouble normativeAssessmentLevel) { if (calculation == null) { throw new ArgumentNullException(nameof(calculation)); } if (generalInput == null) { throw new ArgumentNullException(nameof(generalInput)); } CalculationServiceHelper.LogValidationBegin(); string[] inputValidationResults = MacroStabilityInwardsInputValidator.Validate(calculation.InputParameters, normativeAssessmentLevel).ToArray(); if (inputValidationResults.Length > 0) { CalculationServiceHelper.LogMessagesAsError(inputValidationResults); CalculationServiceHelper.LogValidationEnd(); return(false); } IEnumerable <MacroStabilityInwardsKernelMessage> waternetExtremeKernelMessages; IEnumerable <MacroStabilityInwardsKernelMessage> waternetDailyKernelMessages; try { waternetExtremeKernelMessages = ValidateWaternet(() => WaternetCalculationService.ValidateExtreme( calculation.InputParameters, generalInput, GetEffectiveAssessmentLevel(calculation.InputParameters, normativeAssessmentLevel)), Resources.MacroStabilityInwardsCalculationService_Validate_Waternet_extreme_validation_started); waternetDailyKernelMessages = ValidateWaternet(() => WaternetCalculationService.ValidateDaily(calculation.InputParameters, generalInput), Resources.MacroStabilityInwardsCalculationService_Validate_Waternet_daily_validation_started); } catch (WaternetCalculationException e) { HandleExceptionOnValidation(e); return(false); } IEnumerable <MacroStabilityInwardsKernelMessage> kernelMessages = Enumerable.Empty <MacroStabilityInwardsKernelMessage>(); if (!waternetExtremeKernelMessages.Any() && !waternetDailyKernelMessages.Any()) { IUpliftVanCalculator calculator = GetCalculator(calculation, generalInput, normativeAssessmentLevel); try { kernelMessages = calculator.Validate().ToArray(); } catch (UpliftVanCalculatorException e) { HandleExceptionOnValidation(e); return(false); } LogKernelMessages(kernelMessages); } CalculationServiceHelper.LogValidationEnd(); return(kernelMessages.Concat(waternetDailyKernelMessages) .Concat(waternetExtremeKernelMessages) .All(r => r.Type != MacroStabilityInwardsKernelMessageType.Error)); }