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 ValidateExtreme_NoMessagesInValidation_ReturnEmptyCollection()
        {
            // Setup
            using (new MacroStabilityInwardsCalculatorFactoryConfig())
            {
                // Call
                IEnumerable <MacroStabilityInwardsKernelMessage> messages = WaternetCalculationService.ValidateExtreme(testCalculation.InputParameters, new GeneralMacroStabilityInwardsInput(), RoundedDouble.NaN);

                // 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 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 ValidateExtreme_ErrorInValidation_ThrowsWaternetCalculationException()
        {
            // Setup
            using (new MacroStabilityInwardsCalculatorFactoryConfig())
            {
                var calculatorFactory = (TestMacroStabilityInwardsCalculatorFactory)MacroStabilityInwardsCalculatorFactory.Instance;
                calculatorFactory.LastCreatedWaternetExtremeCalculator.ThrowExceptionOnValidate = true;

                // Call
                void Call() => WaternetCalculationService.ValidateExtreme(testCalculation.InputParameters, new GeneralMacroStabilityInwardsInput(), RoundedDouble.NaN);

                // 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);
            }
        }
Beispiel #7
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));
        }