public void GivenInvalidAircraftDataCausingException_WhenCallingValidate_ReturnsErrorMessages()
        {
            // Setup
            var calculation = new BalancedFieldLengthCalculation();

            SetValidAircraftData(calculation.AircraftData);
            SetEngineData(calculation.EngineData);

            calculation.AircraftData.AspectRatio = double.NaN;

            var kernel      = Substitute.For <IAggregatedDistanceCalculatorKernel>();
            var testFactory = new TestKernelFactory(kernel);

            using (new BalancedFieldLengthKernelFactoryConfig(testFactory))
            {
                var module = new BalancedFieldLengthCalculationModule();

                // Call
                IEnumerable <string> messages = module.Validate(calculation);

                // Assert
                CollectionAssert.AreEqual(new[]
                {
                    "aspectRatio must be a concrete number and cannot be NaN or Infinity."
                }, messages);
            }
        }
        public void Validate_InvalidEndFailureSpeed_ReturnsValidationMessage(int invalidEndFailureSpeed)
        {
            // Setup
            var calculation = new BalancedFieldLengthCalculation();

            SetValidAircraftData(calculation.AircraftData);
            SetEngineData(calculation.EngineData);
            SetSimulationSettingsData(calculation.SimulationSettings);

            calculation.SimulationSettings.EndFailureVelocity = invalidEndFailureSpeed;

            var kernel = Substitute.For <IAggregatedDistanceCalculatorKernel>();

            kernel.Validate(Arg.Any <KernelAircraftData>(),
                            Arg.Any <double>(),
                            Arg.Any <double>(),
                            Arg.Any <int>())
            .ReturnsForAnyArgs(KernelValidationError.None);

            var testFactory = new TestKernelFactory(kernel);

            using (new BalancedFieldLengthKernelFactoryConfig(testFactory))
            {
                var module = new BalancedFieldLengthCalculationModule();

                // Call
                IEnumerable <string> messages = module.Validate(calculation);

                // Assert
                CollectionAssert.AreEqual(new[]
                {
                    "End failure velocity must be larger than 0."
                }, messages);
            }
        }
        public void Validate_WithArgumentAndKernelValidationErrorOccurs_ReturnsErrorMessages(KernelValidationError error,
                                                                                             string expectedMessage)
        {
            // Setup
            var calculation = new BalancedFieldLengthCalculation();

            SetValidAircraftData(calculation.AircraftData);
            SetEngineData(calculation.EngineData);
            SetSimulationSettingsData(calculation.SimulationSettings);

            var kernel = Substitute.For <IAggregatedDistanceCalculatorKernel>();

            kernel.Validate(Arg.Any <KernelAircraftData>(),
                            Arg.Any <double>(),
                            Arg.Any <double>(),
                            Arg.Any <int>())
            .ReturnsForAnyArgs(error);

            var testFactory = new TestKernelFactory(kernel);

            using (new BalancedFieldLengthKernelFactoryConfig(testFactory))
            {
                var module = new BalancedFieldLengthCalculationModule();

                // Call
                IEnumerable <string> messages = module.Validate(calculation);

                // Assert
                CollectionAssert.AreEqual(new[]
                {
                    expectedMessage
                }, messages);
            }
        }
        public void Validate_WithArgumentAndNoErrorOccurs_ReturnsNoErrorMessages()
        {
            // Setup
            var random            = new Random(21);
            int nrOfFailedEngines = random.Next();

            var calculation = new BalancedFieldLengthCalculation();

            SetValidAircraftData(calculation.AircraftData);
            SetEngineData(calculation.EngineData);
            SetSimulationSettingsData(calculation.SimulationSettings);

            calculation.EngineData.NrOfFailedEngines = nrOfFailedEngines;

            var kernel = Substitute.For <IAggregatedDistanceCalculatorKernel>();

            kernel.Validate(Arg.Any <KernelAircraftData>(),
                            Arg.Any <double>(),
                            Arg.Any <double>(),
                            Arg.Any <int>())
            .ReturnsForAnyArgs(KernelValidationError.None);

            var testFactory = new TestKernelFactory(kernel);

            using (new BalancedFieldLengthKernelFactoryConfig(testFactory))
            {
                var module = new BalancedFieldLengthCalculationModule();

                // Call
                IEnumerable <string> messages = module.Validate(calculation);

                // Assert
                CollectionAssert.IsEmpty(messages);
            }
        }
        public void Validate_CalculationNull_ThrowsArgumentNullException()
        {
            // Setup
            var module = new BalancedFieldLengthCalculationModule();

            // Call
            TestDelegate call = () => module.Validate(null);

            Assert.That(call, Throws.ArgumentNullException
                        .With.Property(nameof(ArgumentNullException.ParamName))
                        .EqualTo("calculation"));
        }
        public void Validate_Always_FactoryReceiveCorrectData()
        {
            // Setup
            var calculation = new BalancedFieldLengthCalculation();

            SetValidAircraftData(calculation.AircraftData);
            SetEngineData(calculation.EngineData);
            SetSimulationSettingsData(calculation.SimulationSettings);

            var kernel = Substitute.For <IAggregatedDistanceCalculatorKernel>();

            kernel.Validate(Arg.Any <KernelAircraftData>(),
                            Arg.Any <double>(),
                            Arg.Any <double>(),
                            Arg.Any <int>())
            .ReturnsForAnyArgs(KernelValidationError.None);

            var testFactory = new TestKernelFactory(kernel);

            using (new BalancedFieldLengthKernelFactoryConfig(testFactory))
            {
                var module = new BalancedFieldLengthCalculationModule();

                // Call
                module.Validate(calculation);

                // Assert
                ICall    calls     = kernel.ReceivedCalls().Single();
                object[] arguments = calls.GetArguments();
                AircraftDataTestHelper.AssertAircraftData(calculation.AircraftData,
                                                          calculation.EngineData,
                                                          (KernelAircraftData)arguments[0]);

                GeneralSimulationSettingsData simulationSettings = calculation.SimulationSettings;
                Assert.That(arguments[1], Is.EqualTo(simulationSettings.Density));
                Assert.That(arguments[2], Is.EqualTo(simulationSettings.GravitationalAcceleration));
                Assert.That(arguments[3], Is.EqualTo(calculation.EngineData.NrOfFailedEngines));
            }
        }