コード例 #1
0
        public static void Calculate_ContinuedTakeOffDistanceCalculatorThrowsCalculatorException_ThrowsCalculatorException()
        {
            // Setup
            var random = new Random(21);

            AircraftData        aircraftData              = AircraftDataTestFactory.CreateRandomAircraftData();
            var                 integrator                = Substitute.For <IIntegrator>();
            int                 nrOfFailedEngines         = random.Next();
            double              density                   = random.NextDouble();
            double              gravitationalAcceleration = random.NextDouble();
            CalculationSettings calculationSettings       = CalculationSettingsTestFactory.CreateDistanceCalculatorSettings();

            var calculatorException = new CalculatorException();

            var continuedTakeOffDistanceCalculator = Substitute.For <IDistanceCalculator>();

            continuedTakeOffDistanceCalculator.Calculate().Throws(calculatorException);

            var distanceCalculatorFactory = Substitute.For <IDistanceCalculatorFactory>();

            distanceCalculatorFactory.CreateAbortedTakeOffDistanceCalculator(null, null, 0, 0, null).ReturnsForAnyArgs(continuedTakeOffDistanceCalculator);

            var aggregatedCalculator = new Calculator.AggregatedDistanceCalculator.AggregatedDistanceCalculator(distanceCalculatorFactory);

            // Call
            TestDelegate call = () => aggregatedCalculator.Calculate(aircraftData, integrator, nrOfFailedEngines, density, gravitationalAcceleration, calculationSettings);

            // Assert
            var exception = Assert.Throws <CalculatorException>(call);

            Assert.AreSame(calculatorException, exception);
        }
コード例 #2
0
        public static void Calculate_WithArguments_ExecutesDistanceCalculatorsAndReturnsExpectedOutput()
        {
            // Setup
            var random = new Random(21);

            AircraftData        aircraftData              = AircraftDataTestFactory.CreateRandomAircraftData();
            var                 integrator                = Substitute.For <IIntegrator>();
            int                 nrOfFailedEngines         = random.Next();
            double              density                   = random.NextDouble();
            double              gravitationalAcceleration = random.NextDouble();
            CalculationSettings calculationSettings       = CalculationSettingsTestFactory.CreateDistanceCalculatorSettings();

            var abortedTakeOffDistanceCalculator = Substitute.For <IDistanceCalculator>();
            var abortedTakeOffDistanceOutput     = new DistanceCalculatorOutput(calculationSettings.FailureSpeed, random.NextDouble());

            abortedTakeOffDistanceCalculator.Calculate().Returns(abortedTakeOffDistanceOutput);

            var continuedTakeOffDistanceCalculator = Substitute.For <IDistanceCalculator>();
            var continuedTakeOffDistanceOutput     = new DistanceCalculatorOutput(calculationSettings.FailureSpeed, random.NextDouble());

            continuedTakeOffDistanceCalculator.Calculate().Returns(continuedTakeOffDistanceOutput);

            var distanceCalculatorFactory = Substitute.For <IDistanceCalculatorFactory>();

            distanceCalculatorFactory.CreateAbortedTakeOffDistanceCalculator(Arg.Is(aircraftData),
                                                                             Arg.Is(integrator),
                                                                             Arg.Is(density),
                                                                             Arg.Is(gravitationalAcceleration),
                                                                             Arg.Is(calculationSettings))
            .Returns(abortedTakeOffDistanceCalculator);
            distanceCalculatorFactory.CreateContinuedTakeOffDistanceCalculator(Arg.Is(aircraftData),
                                                                               Arg.Is(integrator),
                                                                               Arg.Is(nrOfFailedEngines),
                                                                               Arg.Is(density),
                                                                               Arg.Is(gravitationalAcceleration),
                                                                               Arg.Is(calculationSettings))
            .Returns(continuedTakeOffDistanceCalculator);

            var aggregatedCalculator = new Calculator.AggregatedDistanceCalculator.AggregatedDistanceCalculator(distanceCalculatorFactory);

            // Call
            AggregatedDistanceOutput output = aggregatedCalculator.Calculate(aircraftData, integrator, nrOfFailedEngines, density, gravitationalAcceleration, calculationSettings);

            // Assert
            Assert.AreEqual(calculationSettings.FailureSpeed, output.FailureSpeed);
            Assert.AreEqual(abortedTakeOffDistanceOutput.Distance, output.AbortedTakeOffDistance);
            Assert.AreEqual(continuedTakeOffDistanceOutput.Distance, output.ContinuedTakeOffDistance);
        }
コード例 #3
0
        public void Calculate_CalculationSettingsNull_ThrowsArgumentNullException()
        {
            // Setup
            var random = new Random(21);

            AircraftData aircraftData              = AircraftDataTestFactory.CreateRandomAircraftData();
            var          integrator                = Substitute.For <IIntegrator>();
            int          nrOfFailedEngines         = random.Next();
            double       density                   = random.NextDouble();
            double       gravitationalAcceleration = random.NextDouble();

            var distanceCalculatorFactory = Substitute.For <IDistanceCalculatorFactory>();

            var aggregatedCalculator = new Calculator.AggregatedDistanceCalculator.AggregatedDistanceCalculator(distanceCalculatorFactory);

            // Call
            TestDelegate call = () => aggregatedCalculator.Calculate(aircraftData, integrator, nrOfFailedEngines, density, gravitationalAcceleration, null);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(call);

            Assert.AreEqual("calculationSettings", exception.ParamName);
        }