public void Calculate_CalculatorWithCompleteInput_InputCorrectlySetToKernel()
        {
            // Setup
            WaternetCalculatorInput input = WaternetCalculatorInputTestFactory.CreateCompleteCalculatorInput();

            using (new MacroStabilityInwardsKernelFactoryConfig())
            {
                var factory = (TestMacroStabilityInwardsKernelFactory)MacroStabilityInwardsKernelWrapperFactory.Instance;
                WaternetKernelStub waternetKernel = factory.LastCreatedWaternetExtremeKernel;
                waternetKernel.Waternet = new CSharpWrapperWaternet
                {
                    HeadLines      = new List <HeadLine>(),
                    ReferenceLines = new List <ReferenceLine>(),
                    PhreaticLine   = new HeadLine
                    {
                        Name = string.Empty
                    }
                };

                // Call
                new WaternetExtremeCalculator(input, factory).Calculate();

                // Assert
                WaternetKernelInputAssert.AssertMacroStabilityInput(MacroStabilityInputCreator.CreateWaternet(input), waternetKernel.KernelInput);
            }
        }
Ejemplo n.º 2
0
        public void Validate_KernelReturnsValidationResults_ReturnsEnumerableWithOnlyErrorsAndWarnings()
        {
            // Setup
            using (new MacroStabilityInwardsKernelFactoryConfig())
            {
                var factory = (TestMacroStabilityInwardsKernelFactory)MacroStabilityInwardsKernelWrapperFactory.Instance;
                WaternetKernelStub waternetKernel = factory.LastCreatedWaternetExtremeKernel;
                waternetKernel.ReturnValidationResults = true;

                WaternetCalculatorInput input = WaternetCalculatorInputTestFactory.CreateValidCalculatorInput();
                var calculator = new TestWaternetCalculator(input, factory);

                // Call
                IEnumerable <MacroStabilityInwardsKernelMessage> kernelMessages = calculator.Validate();

                // Assert
                Assert.AreEqual(2, kernelMessages.Count());
                MacroStabilityInwardsKernelMessage firstMessage = kernelMessages.ElementAt(0);
                Assert.AreEqual("Validation Warning", firstMessage.Message);
                Assert.AreEqual(MacroStabilityInwardsKernelMessageType.Warning, firstMessage.Type);
                MacroStabilityInwardsKernelMessage secondMessage = kernelMessages.ElementAt(1);
                Assert.AreEqual("Validation Error", secondMessage.Message);
                Assert.AreEqual(MacroStabilityInwardsKernelMessageType.Error, secondMessage.Type);
            }
        }
Ejemplo n.º 3
0
        public void Calculate_KernelWithCompleteOutput_OutputCorrectlyReturnedByCalculator()
        {
            // Setup
            WaternetCalculatorInput input = WaternetCalculatorInputTestFactory.CreateValidCalculatorInput();

            using (new MacroStabilityInwardsKernelFactoryConfig())
            {
                var factory = (TestMacroStabilityInwardsKernelFactory)MacroStabilityInwardsKernelWrapperFactory.Instance;
                WaternetKernelStub kernel = factory.LastCreatedWaternetExtremeKernel;
                SetCompleteKernelOutput(kernel);

                // Call
                WaternetCalculatorResult result = new TestWaternetCalculator(input, factory).Calculate();

                // Assert
                Assert.IsNotNull(result);
                var expectedPhreaticLines = new List <HeadLine>
                {
                    kernel.Waternet.PhreaticLine
                };
                expectedPhreaticLines.AddRange(kernel.Waternet.HeadLines);

                WaternetCalculatorOutputAssert.AssertPhreaticLines(expectedPhreaticLines.ToArray(), result.PhreaticLines.ToArray());
                WaternetCalculatorOutputAssert.AssertReferenceLines(kernel.Waternet.ReferenceLines.ToArray(), result.WaternetLines.ToArray());
            }
        }
Ejemplo n.º 4
0
 private static void SetValidKernelOutput(WaternetKernelStub waternetKernel)
 {
     waternetKernel.Waternet = new CSharpWrapperWaternet
     {
         HeadLines      = new List <HeadLine>(),
         ReferenceLines = new List <ReferenceLine>(),
         PhreaticLine   = new HeadLine
         {
             Name = string.Empty
         }
     };
 }
Ejemplo n.º 5
0
        public void Calculate_CalculatorWithValidInput_KernelCalculateMethodCalled()
        {
            // Setup
            WaternetCalculatorInput input = WaternetCalculatorInputTestFactory.CreateValidCalculatorInput();

            using (new MacroStabilityInwardsKernelFactoryConfig())
            {
                var factory = (TestMacroStabilityInwardsKernelFactory)MacroStabilityInwardsKernelWrapperFactory.Instance;
                WaternetKernelStub waternetKernel = factory.LastCreatedWaternetExtremeKernel;
                SetCompleteKernelOutput(waternetKernel);

                // Call
                new TestWaternetCalculator(input, factory).Calculate();

                // Assert
                Assert.IsTrue(waternetKernel.Calculated);
            }
        }
Ejemplo n.º 6
0
        private static void SetCompleteKernelOutput(WaternetKernelStub kernel)
        {
            var headLine = new HeadLine
            {
                Name   = "line 1",
                Points =
                {
                    new CSharpWrapperPoint2D(0, 0),
                    new CSharpWrapperPoint2D(1, 1)
                }
            };

            kernel.Waternet = new CSharpWrapperWaternet
            {
                HeadLines =
                {
                    headLine
                },
                PhreaticLine = new HeadLine
                {
                    Name   = "line 2",
                    Points =
                    {
                        new CSharpWrapperPoint2D(2, 2),
                        new CSharpWrapperPoint2D(3, 3)
                    }
                },
                ReferenceLines =
                {
                    new ReferenceLine
                    {
                        Name   = "line 3",
                        Points =
                        {
                            new CSharpWrapperPoint2D(4, 4),
                            new CSharpWrapperPoint2D(5, 5)
                        },
                        AssociatedHeadLine = headLine
                    }
                }
            };
        }
Ejemplo n.º 7
0
        public void Calculate_KernelThrowsWaternetKernelWrapperException_ThrowWaternetCalculatorException()
        {
            // Setup
            WaternetCalculatorInput input = WaternetCalculatorInputTestFactory.CreateValidCalculatorInput();

            using (new MacroStabilityInwardsKernelFactoryConfig())
            {
                var factory = (TestMacroStabilityInwardsKernelFactory)MacroStabilityInwardsKernelWrapperFactory.Instance;
                WaternetKernelStub waternetKernel = factory.LastCreatedWaternetExtremeKernel;
                waternetKernel.ThrowExceptionOnCalculate = true;

                // Call
                void Call() => new TestWaternetCalculator(input, factory).Calculate();

                // Assert
                var exception = Assert.Throws <WaternetCalculatorException>(Call);
                Assert.IsInstanceOf <WaternetKernelWrapperException>(exception.InnerException);
                Assert.AreEqual(exception.InnerException.Message, exception.Message);
            }
        }
Ejemplo n.º 8
0
        public void Calculate_CalculatorWithCompleteInput_InputCorrectlySetToKernel()
        {
            // Setup
            UpliftVanCalculatorInput input = UpliftVanCalculatorInputTestFactory.Create();

            using (new MacroStabilityInwardsKernelFactoryConfig())
            {
                var factory = (TestMacroStabilityInwardsKernelFactory)MacroStabilityInwardsKernelWrapperFactory.Instance;
                UpliftVanKernelStub upliftVanKernel       = factory.LastCreatedUpliftVanKernel;
                WaternetKernelStub  waternetDailyKernel   = factory.LastCreatedWaternetDailyKernel;
                WaternetKernelStub  waternetExtremeKernel = factory.LastCreatedWaternetExtremeKernel;

                SetValidKernelOutput(waternetDailyKernel);
                SetValidKernelOutput(waternetExtremeKernel);

                SetValidKernelOutput(upliftVanKernel);

                LayerWithSoil[]          layersWithSoil = LayerWithSoilCreator.Create(input.SoilProfile, out IDictionary <SoilLayer, LayerWithSoil> layerLookup);
                List <Soil>              soils          = layersWithSoil.Select(lws => lws.Soil).ToList();
                SurfaceLine              surfaceLine    = SurfaceLineCreator.Create(input.SurfaceLine);
                CSharpWrapperSoilProfile soilProfile    = SoilProfileCreator.Create(layersWithSoil);

                // Call
                new UpliftVanCalculator(input, factory).Calculate();

                // Assert
                WaternetKernelInputAssert.AssertMacroStabilityInput(
                    MacroStabilityInputCreator.CreateDailyWaternetForUpliftVan(input, soils, surfaceLine, soilProfile),
                    waternetDailyKernel.KernelInput);
                WaternetKernelInputAssert.AssertMacroStabilityInput(
                    MacroStabilityInputCreator.CreateExtremeWaternetForUpliftVan(input, soils, surfaceLine, soilProfile),
                    waternetExtremeKernel.KernelInput);
                UpliftVanKernelInputAssert.AssertMacroStabilityInput(
                    MacroStabilityInputCreator.CreateUpliftVan(
                        input, soils, layerLookup, surfaceLine, soilProfile,
                        waternetDailyKernel.Waternet, waternetExtremeKernel.Waternet),
                    upliftVanKernel.KernelInput);
            }
        }
 private static IWaternetKernel CreateWaternetKernel(MacroStabilityInput kernelInput, WaternetKernelStub waternetKernel)
 {
     waternetKernel.SetInput(kernelInput);
     return(waternetKernel);
 }
 /// <summary>
 /// Creates a new instance of <see cref="TestMacroStabilityInwardsKernelFactory"/>.
 /// </summary>
 public TestMacroStabilityInwardsKernelFactory()
 {
     LastCreatedUpliftVanKernel       = new UpliftVanKernelStub();
     LastCreatedWaternetExtremeKernel = new WaternetKernelStub();
     LastCreatedWaternetDailyKernel   = new WaternetKernelStub();
 }