Ejemplo n.º 1
0
        public void Calculate_ExceptionDuringCalculation_OutputPropertiesNotSet()
        {
            // Setup
            var mocks      = new MockRepository();
            var calculator = mocks.Stub <ICalculator>();

            calculator.Stub(c => c.Calculate()).Throw(new Exception());
            var validator = mocks.Stub <IValidator>();

            mocks.ReplayAll();

            var kernel = new UpliftVanKernelWrapper(calculator, validator);

            // Call
            void Call() => kernel.Calculate();

            // Assert
            Assert.Throws <UpliftVanKernelWrapperException>(Call);
            Assert.IsNaN(kernel.FactorOfStability);
            Assert.IsNaN(kernel.ForbiddenZonesXEntryMax);
            Assert.IsNaN(kernel.ForbiddenZonesXEntryMin);
            Assert.IsNull(kernel.SlidingCurveResult);
            Assert.IsNull(kernel.UpliftVanCalculationGridResult);
            mocks.VerifyAll();
        }
Ejemplo n.º 2
0
        public void Calculate_CalculatorHasMessages_CalculationMessagesSet()
        {
            // Setup
            var calculatorOutput = new MacroStabilityOutput
            {
                StabilityOutput = new StabilityOutput
                {
                    Messages  = new Message[0],
                    Succeeded = true
                },
                PreprocessingOutputBase = new UpliftVanPreprocessingOutput
                {
                    ForbiddenZone = new ForbiddenZones()
                }
            };

            var mocks      = new MockRepository();
            var calculator = mocks.Stub <ICalculator>();

            calculator.Stub(c => c.Calculate()).Return(calculatorOutput);
            var validator = mocks.Stub <IValidator>();

            mocks.ReplayAll();

            var kernel = new UpliftVanKernelWrapper(calculator, validator);

            // Call
            kernel.Calculate();

            // Assert
            Assert.AreSame(calculatorOutput.StabilityOutput.Messages, kernel.CalculationMessages);
            mocks.VerifyAll();
        }
Ejemplo n.º 3
0
        public void Calculate_ExceptionInWrappedKernel_ThrowsUpliftVanKernelWrapperException()
        {
            // Setup
            var exceptionToThrow = new Exception();

            var mocks      = new MockRepository();
            var calculator = mocks.Stub <ICalculator>();

            calculator.Stub(c => c.Calculate()).Throw(exceptionToThrow);
            var validator = mocks.Stub <IValidator>();

            mocks.ReplayAll();

            var kernel = new UpliftVanKernelWrapper(calculator, validator);

            // Call
            void Call() => kernel.Calculate();

            // Assert
            var exception = Assert.Throws <UpliftVanKernelWrapperException>(Call);

            Assert.AreSame(exceptionToThrow, exception.InnerException);
            Assert.AreEqual(exception.InnerException.Message, exception.Message);
            mocks.VerifyAll();
        }
Ejemplo n.º 4
0
        public void Calculate_SuccessfulCalculation_OutputSet()
        {
            // Setup
            var random           = new Random(21);
            var calculatorOutput = new MacroStabilityOutput
            {
                StabilityOutput = new StabilityOutput
                {
                    Succeeded    = true,
                    SafetyFactor = random.NextDouble()
                },
                PreprocessingOutputBase = new UpliftVanPreprocessingOutput
                {
                    ForbiddenZone = new ForbiddenZones
                    {
                        XEntryMin = random.NextDouble(),
                        XEntryMax = random.NextDouble()
                    }
                }
            };

            var mocks      = new MockRepository();
            var calculator = mocks.Stub <ICalculator>();

            calculator.Stub(c => c.Calculate()).Return(calculatorOutput);
            var validator = mocks.Stub <IValidator>();

            mocks.ReplayAll();

            var kernel = new UpliftVanKernelWrapper(calculator, validator);

            // Call
            kernel.Calculate();

            // Assert
            Assert.AreEqual(calculatorOutput.StabilityOutput.SafetyFactor, kernel.FactorOfStability);
            Assert.AreEqual(calculatorOutput.PreprocessingOutputBase.ForbiddenZone.XEntryMin, kernel.ForbiddenZonesXEntryMin);
            Assert.AreEqual(calculatorOutput.PreprocessingOutputBase.ForbiddenZone.XEntryMax, kernel.ForbiddenZonesXEntryMax);

            Assert.AreSame((DualSlidingCircleMinimumSafetyCurve)calculatorOutput.StabilityOutput.MinimumSafetyCurve, kernel.SlidingCurveResult);
            Assert.AreSame(((UpliftVanPreprocessingOutput)calculatorOutput.PreprocessingOutputBase).UpliftVanCalculationGrid, kernel.UpliftVanCalculationGridResult);
            mocks.VerifyAll();
        }
Ejemplo n.º 5
0
        public void Calculate_CalculationNotSuccessful_ThrowsUpliftVanKernelWrapperException()
        {
            // Setup
            var calculatorOutput = new MacroStabilityOutput
            {
                StabilityOutput = new StabilityOutput
                {
                    Succeeded = false,
                    Messages  = new[]
                    {
                        MessageHelper.CreateMessage(MessageType.Error, "Message 1"),
                        MessageHelper.CreateMessage(MessageType.Error, "Message 2")
                    }
                }
            };

            var mocks      = new MockRepository();
            var calculator = mocks.Stub <ICalculator>();

            calculator.Stub(c => c.Calculate()).Return(calculatorOutput);
            var validator = mocks.Stub <IValidator>();

            mocks.ReplayAll();

            var kernel = new UpliftVanKernelWrapper(calculator, validator);

            // Call
            void Call() => kernel.Calculate();

            // Assert
            var exception = Assert.Throws <UpliftVanKernelWrapperException>(Call);

            Assert.IsNull(exception.InnerException);
            Assert.AreEqual($"Exception of type '{typeof(UpliftVanKernelWrapperException)}' was thrown.", exception.Message);
            CollectionAssert.AreEqual(calculatorOutput.StabilityOutput.Messages, exception.Messages);

            mocks.VerifyAll();
        }