Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Calculators/MacroStabilityInwardsCalculatorFactoryTest.cs =================================================================== diff -u -r24c1404b1f8e7a8ae1f13bc2990062caa13b9aa3 -rfc8bf1b38d4b3f9bb6f6d9dab951543b92901c8d --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Calculators/MacroStabilityInwardsCalculatorFactoryTest.cs (.../MacroStabilityInwardsCalculatorFactoryTest.cs) (revision 24c1404b1f8e7a8ae1f13bc2990062caa13b9aa3) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Calculators/MacroStabilityInwardsCalculatorFactoryTest.cs (.../MacroStabilityInwardsCalculatorFactoryTest.cs) (revision fc8bf1b38d4b3f9bb6f6d9dab951543b92901c8d) @@ -26,6 +26,7 @@ using Ringtoets.MacroStabilityInwards.KernelWrapper.Calculators.UpliftVan.Input; using Ringtoets.MacroStabilityInwards.KernelWrapper.Calculators.Waternet; using Ringtoets.MacroStabilityInwards.KernelWrapper.Calculators.Waternet.Input; +using Ringtoets.MacroStabilityInwards.KernelWrapper.Kernels; using Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Calculators; using Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Calculators.Input; using Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Kernels; @@ -80,21 +81,24 @@ // Setup IMacroStabilityInwardsCalculatorFactory factory = MacroStabilityInwardsCalculatorFactory.Instance; - // Call - IUpliftVanCalculator upliftVanCalculator = factory.CreateUpliftVanCalculator( - new UpliftVanCalculatorInput(new UpliftVanCalculatorInput.ConstructionProperties - { - SurfaceLine = new MacroStabilityInwardsSurfaceLine("test"), - SoilProfile = new TestSoilProfile(), - PhreaticLineOffsetsExtreme = new PhreaticLineOffsets(), - PhreaticLineOffsetsDaily = new PhreaticLineOffsets(), - DrainageConstruction = new DrainageConstruction(), - SlipPlane = new UpliftVanSlipPlane() - }), - new TestMacroStabilityInwardsKernelFactory()); + using (new MacroStabilityInwardsKernelFactoryConfig()) + { + // Call + IUpliftVanCalculator upliftVanCalculator = factory.CreateUpliftVanCalculator( + new UpliftVanCalculatorInput(new UpliftVanCalculatorInput.ConstructionProperties + { + SurfaceLine = new MacroStabilityInwardsSurfaceLine("test"), + SoilProfile = new TestSoilProfile(), + PhreaticLineOffsetsExtreme = new PhreaticLineOffsets(), + PhreaticLineOffsetsDaily = new PhreaticLineOffsets(), + DrainageConstruction = new DrainageConstruction(), + SlipPlane = new UpliftVanSlipPlane() + }), + MacroStabilityInwardsKernelWrapperFactory.Instance); - // Assert - Assert.IsInstanceOf(upliftVanCalculator); + // Assert + Assert.IsInstanceOf(upliftVanCalculator); + } } [Test] @@ -103,18 +107,21 @@ // Setup IMacroStabilityInwardsCalculatorFactory factory = MacroStabilityInwardsCalculatorFactory.Instance; - // Call - IWaternetCalculator waternetCalculator = factory.CreateWaternetExtremeCalculator( - new WaternetCalculatorInput(new WaternetCalculatorInput.ConstructionProperties - { - SurfaceLine = new MacroStabilityInwardsSurfaceLine("test"), - SoilProfile = new TestSoilProfile(), - PhreaticLineOffsets = new PhreaticLineOffsets(), - DrainageConstruction = new DrainageConstruction() - }), new TestMacroStabilityInwardsKernelFactory()); + using (new MacroStabilityInwardsKernelFactoryConfig()) + { + // Call + IWaternetCalculator waternetCalculator = factory.CreateWaternetExtremeCalculator( + new WaternetCalculatorInput(new WaternetCalculatorInput.ConstructionProperties + { + SurfaceLine = new MacroStabilityInwardsSurfaceLine("test"), + SoilProfile = new TestSoilProfile(), + PhreaticLineOffsets = new PhreaticLineOffsets(), + DrainageConstruction = new DrainageConstruction() + }), MacroStabilityInwardsKernelWrapperFactory.Instance); - // Assert - Assert.IsInstanceOf(waternetCalculator); + // Assert + Assert.IsInstanceOf(waternetCalculator); + } } [Test] @@ -123,18 +130,21 @@ // Setup IMacroStabilityInwardsCalculatorFactory factory = MacroStabilityInwardsCalculatorFactory.Instance; - // Call - IWaternetCalculator waternetCalculator = factory.CreateWaternetDailyCalculator( - new WaternetCalculatorInput(new WaternetCalculatorInput.ConstructionProperties - { - SurfaceLine = new MacroStabilityInwardsSurfaceLine("test"), - SoilProfile = new TestSoilProfile(), - PhreaticLineOffsets = new PhreaticLineOffsets(), - DrainageConstruction = new DrainageConstruction() - }), new TestMacroStabilityInwardsKernelFactory()); + using (new MacroStabilityInwardsKernelFactoryConfig()) + { + // Call + IWaternetCalculator waternetCalculator = factory.CreateWaternetDailyCalculator( + new WaternetCalculatorInput(new WaternetCalculatorInput.ConstructionProperties + { + SurfaceLine = new MacroStabilityInwardsSurfaceLine("test"), + SoilProfile = new TestSoilProfile(), + PhreaticLineOffsets = new PhreaticLineOffsets(), + DrainageConstruction = new DrainageConstruction() + }), MacroStabilityInwardsKernelWrapperFactory.Instance); - // Assert - Assert.IsInstanceOf(waternetCalculator); + // Assert + Assert.IsInstanceOf(waternetCalculator); + } } } } \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Calculators/UpliftVan/UpliftVanCalculatorTest.cs =================================================================== diff -u -r8d246ac6328e6e649ff6e78dfe3fac210d789ba0 -rfc8bf1b38d4b3f9bb6f6d9dab951543b92901c8d --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Calculators/UpliftVan/UpliftVanCalculatorTest.cs (.../UpliftVanCalculatorTest.cs) (revision 8d246ac6328e6e649ff6e78dfe3fac210d789ba0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Calculators/UpliftVan/UpliftVanCalculatorTest.cs (.../UpliftVanCalculatorTest.cs) (revision fc8bf1b38d4b3f9bb6f6d9dab951543b92901c8d) @@ -105,198 +105,225 @@ { // Setup UpliftVanCalculatorInput input = CreateValidCalculatorInput(); - var testMacroStabilityInwardsKernelFactory = new TestMacroStabilityInwardsKernelFactory(); - UpliftVanKernelStub upliftVanKernel = testMacroStabilityInwardsKernelFactory.LastCreatedUpliftVanKernel; - SetValidKernelOutput(upliftVanKernel); + using (new MacroStabilityInwardsKernelFactoryConfig()) + { + var factory = (TestMacroStabilityInwardsKernelFactory) MacroStabilityInwardsKernelWrapperFactory.Instance; + UpliftVanKernelStub upliftVanKernel = factory.LastCreatedUpliftVanKernel; + SetValidKernelOutput(upliftVanKernel); - // Call - new UpliftVanCalculator(input, testMacroStabilityInwardsKernelFactory).Calculate(); + // Call + new UpliftVanCalculator(input, factory).Calculate(); - // Assert - Assert.IsTrue(upliftVanKernel.Calculated); + // Assert + Assert.IsTrue(upliftVanKernel.Calculated); + } } [Test] public void Calculate_CalculatorWithCompleteInput_InputCorrectlySetToKernel() { // Setup UpliftVanCalculatorInput input = CreateCompleteCalculatorInput(); - var testMacroStabilityInwardsKernelFactory = new TestMacroStabilityInwardsKernelFactory(); - UpliftVanKernelStub upliftVanKernel = testMacroStabilityInwardsKernelFactory.LastCreatedUpliftVanKernel; - SetValidKernelOutput(upliftVanKernel); + using (new MacroStabilityInwardsKernelFactoryConfig()) + { + var factory = (TestMacroStabilityInwardsKernelFactory) MacroStabilityInwardsKernelWrapperFactory.Instance; + UpliftVanKernelStub upliftVanKernel = factory.LastCreatedUpliftVanKernel; + SetValidKernelOutput(upliftVanKernel); - // Call - new UpliftVanCalculator(input, testMacroStabilityInwardsKernelFactory).Calculate(); + // Call + new UpliftVanCalculator(input, factory).Calculate(); - // Assert - Assert.AreEqual(input.MoveGrid, upliftVanKernel.MoveGrid); - Assert.AreEqual(input.MaximumSliceWidth, upliftVanKernel.MaximumSliceWidth); + // Assert + Assert.AreEqual(input.MoveGrid, upliftVanKernel.MoveGrid); + Assert.AreEqual(input.MaximumSliceWidth, upliftVanKernel.MaximumSliceWidth); - LayerWithSoil[] layersWithSoil = LayerWithSoilCreator.Create(input.SoilProfile); + LayerWithSoil[] layersWithSoil = LayerWithSoilCreator.Create(input.SoilProfile); - KernelInputAssert.AssertSoilModels(SoilModelCreator.Create(layersWithSoil.Select(lws => lws.Soil).ToArray()), upliftVanKernel.SoilModel); - KernelInputAssert.AssertSoilProfiles(SoilProfileCreator.Create(input.SoilProfile.PreconsolidationStresses, layersWithSoil), upliftVanKernel.SoilProfile); - KernelInputAssert.AssertStabilityLocations(UpliftVanStabilityLocationCreator.CreateExtreme(input), upliftVanKernel.LocationExtreme); - KernelInputAssert.AssertStabilityLocations(UpliftVanStabilityLocationCreator.CreateDaily(input), upliftVanKernel.LocationDaily); - KernelInputAssert.AssertSurfaceLines(SurfaceLineCreator.Create(input.SurfaceLine, input.LandwardDirection), upliftVanKernel.SurfaceLine); - UpliftVanKernelInputAssert.AssertSlipPlanesUpliftVan(SlipPlaneUpliftVanCreator.Create(input.SlipPlane), upliftVanKernel.SlipPlaneUpliftVan); - UpliftVanKernelInputAssert.AssertSlipPlaneConstraints(SlipPlaneConstraintsCreator.Create(input.SlipPlaneConstraints), upliftVanKernel.SlipPlaneConstraints); - Assert.AreEqual(input.SlipPlane.GridAutomaticDetermined, upliftVanKernel.GridAutomaticDetermined); - CollectionAssert.IsEmpty(upliftVanKernel.CalculationMessages); + KernelInputAssert.AssertSoilModels(SoilModelCreator.Create(layersWithSoil.Select(lws => lws.Soil).ToArray()), upliftVanKernel.SoilModel); + KernelInputAssert.AssertSoilProfiles(SoilProfileCreator.Create(input.SoilProfile.PreconsolidationStresses, layersWithSoil), upliftVanKernel.SoilProfile); + KernelInputAssert.AssertStabilityLocations(UpliftVanStabilityLocationCreator.CreateExtreme(input), upliftVanKernel.LocationExtreme); + KernelInputAssert.AssertStabilityLocations(UpliftVanStabilityLocationCreator.CreateDaily(input), upliftVanKernel.LocationDaily); + KernelInputAssert.AssertSurfaceLines(SurfaceLineCreator.Create(input.SurfaceLine, input.LandwardDirection), upliftVanKernel.SurfaceLine); + UpliftVanKernelInputAssert.AssertSlipPlanesUpliftVan(SlipPlaneUpliftVanCreator.Create(input.SlipPlane), upliftVanKernel.SlipPlaneUpliftVan); + UpliftVanKernelInputAssert.AssertSlipPlaneConstraints(SlipPlaneConstraintsCreator.Create(input.SlipPlaneConstraints), upliftVanKernel.SlipPlaneConstraints); + Assert.AreEqual(input.SlipPlane.GridAutomaticDetermined, upliftVanKernel.GridAutomaticDetermined); + CollectionAssert.IsEmpty(upliftVanKernel.CalculationMessages); + } } [Test] public void Calculate_KernelWithCompleteOutput_OutputCorrectlyReturnedByCalculator() { // Setup UpliftVanCalculatorInput input = CreateValidCalculatorInput(); - var testMacroStabilityInwardsKernelFactory = new TestMacroStabilityInwardsKernelFactory(); - UpliftVanKernelStub upliftVanKernel = testMacroStabilityInwardsKernelFactory.LastCreatedUpliftVanKernel; - SetCompleteKernelOutput(upliftVanKernel); + using (new MacroStabilityInwardsKernelFactoryConfig()) + { + var factory = (TestMacroStabilityInwardsKernelFactory) MacroStabilityInwardsKernelWrapperFactory.Instance; + UpliftVanKernelStub upliftVanKernel = factory.LastCreatedUpliftVanKernel; + SetCompleteKernelOutput(upliftVanKernel); - // Call - UpliftVanCalculatorResult result = new UpliftVanCalculator(input, testMacroStabilityInwardsKernelFactory).Calculate(); + // Call + UpliftVanCalculatorResult result = new UpliftVanCalculator(input, factory).Calculate(); - // Assert - Assert.IsNotNull(result); - Assert.AreEqual(upliftVanKernel.FactorOfStability, result.FactorOfStability); - Assert.AreEqual(upliftVanKernel.ZValue, result.ZValue); - Assert.AreEqual(upliftVanKernel.ForbiddenZonesXEntryMax, result.ForbiddenZonesXEntryMax); - Assert.AreEqual(upliftVanKernel.ForbiddenZonesXEntryMin, result.ForbiddenZonesXEntryMin); - UpliftVanCalculatorOutputAssert.AssertSlidingCurve(UpliftVanSlidingCurveResultCreator.Create(upliftVanKernel.SlidingCurveResult), - result.SlidingCurveResult); - UpliftVanCalculatorOutputAssert.AssertSlipPlaneGrid(UpliftVanCalculationGridResultCreator.Create(upliftVanKernel.SlipPlaneResult), - result.CalculationGridResult); + // Assert + Assert.IsNotNull(result); + Assert.AreEqual(upliftVanKernel.FactorOfStability, result.FactorOfStability); + Assert.AreEqual(upliftVanKernel.ZValue, result.ZValue); + Assert.AreEqual(upliftVanKernel.ForbiddenZonesXEntryMax, result.ForbiddenZonesXEntryMax); + Assert.AreEqual(upliftVanKernel.ForbiddenZonesXEntryMin, result.ForbiddenZonesXEntryMin); + UpliftVanCalculatorOutputAssert.AssertSlidingCurve(UpliftVanSlidingCurveResultCreator.Create(upliftVanKernel.SlidingCurveResult), + result.SlidingCurveResult); + UpliftVanCalculatorOutputAssert.AssertSlipPlaneGrid(UpliftVanCalculationGridResultCreator.Create(upliftVanKernel.SlipPlaneResult), + result.CalculationGridResult); + } } [Test] public void Calculate_KernelReturnsLogMessages_ReturnsExpectedLogMessages() { // Setup UpliftVanCalculatorInput input = CreateValidCalculatorInput(); - var testMacroStabilityInwardsKernelFactory = new TestMacroStabilityInwardsKernelFactory(); - UpliftVanKernelStub upliftVanKernel = testMacroStabilityInwardsKernelFactory.LastCreatedUpliftVanKernel; - upliftVanKernel.ReturnLogMessages = true; - SetCompleteKernelOutput(upliftVanKernel); + using (new MacroStabilityInwardsKernelFactoryConfig()) + { + var factory = (TestMacroStabilityInwardsKernelFactory) MacroStabilityInwardsKernelWrapperFactory.Instance; + UpliftVanKernelStub upliftVanKernel = factory.LastCreatedUpliftVanKernel; + upliftVanKernel.ReturnLogMessages = true; + SetCompleteKernelOutput(upliftVanKernel); - // Call - new UpliftVanCalculator(input, testMacroStabilityInwardsKernelFactory).Calculate(); + // Call + new UpliftVanCalculator(input, factory).Calculate(); - // Assert - Assert.AreEqual(6, upliftVanKernel.CalculationMessages.Count()); - LogMessage firstMessage = upliftVanKernel.CalculationMessages.ElementAt(0); - Assert.AreEqual("Calculation Trace", firstMessage.Message); - Assert.AreEqual(LogMessageType.Trace, firstMessage.MessageType); + // Assert + Assert.AreEqual(6, upliftVanKernel.CalculationMessages.Count()); + LogMessage firstMessage = upliftVanKernel.CalculationMessages.ElementAt(0); + Assert.AreEqual("Calculation Trace", firstMessage.Message); + Assert.AreEqual(LogMessageType.Trace, firstMessage.MessageType); - LogMessage secondMessage = upliftVanKernel.CalculationMessages.ElementAt(1); - Assert.AreEqual("Calculation Debug", secondMessage.Message); - Assert.AreEqual(LogMessageType.Debug, secondMessage.MessageType); + LogMessage secondMessage = upliftVanKernel.CalculationMessages.ElementAt(1); + Assert.AreEqual("Calculation Debug", secondMessage.Message); + Assert.AreEqual(LogMessageType.Debug, secondMessage.MessageType); - LogMessage thirdMessage = upliftVanKernel.CalculationMessages.ElementAt(2); - Assert.AreEqual("Calculation Info", thirdMessage.Message); - Assert.AreEqual(LogMessageType.Info, thirdMessage.MessageType); + LogMessage thirdMessage = upliftVanKernel.CalculationMessages.ElementAt(2); + Assert.AreEqual("Calculation Info", thirdMessage.Message); + Assert.AreEqual(LogMessageType.Info, thirdMessage.MessageType); - LogMessage fourthMessage = upliftVanKernel.CalculationMessages.ElementAt(3); - Assert.AreEqual("Calculation Warning", fourthMessage.Message); - Assert.AreEqual(LogMessageType.Warning, fourthMessage.MessageType); + LogMessage fourthMessage = upliftVanKernel.CalculationMessages.ElementAt(3); + Assert.AreEqual("Calculation Warning", fourthMessage.Message); + Assert.AreEqual(LogMessageType.Warning, fourthMessage.MessageType); - LogMessage fifthMessage = upliftVanKernel.CalculationMessages.ElementAt(4); - Assert.AreEqual("Calculation Error", fifthMessage.Message); - Assert.AreEqual(LogMessageType.Error, fifthMessage.MessageType); + LogMessage fifthMessage = upliftVanKernel.CalculationMessages.ElementAt(4); + Assert.AreEqual("Calculation Error", fifthMessage.Message); + Assert.AreEqual(LogMessageType.Error, fifthMessage.MessageType); - LogMessage sixthMessage = upliftVanKernel.CalculationMessages.ElementAt(5); - Assert.AreEqual("Calculation Fatal Error", sixthMessage.Message); - Assert.AreEqual(LogMessageType.FatalError, sixthMessage.MessageType); + LogMessage sixthMessage = upliftVanKernel.CalculationMessages.ElementAt(5); + Assert.AreEqual("Calculation Fatal Error", sixthMessage.Message); + Assert.AreEqual(LogMessageType.FatalError, sixthMessage.MessageType); + } } [Test] public void Calculate_KernelThrowsUpliftVanKernelWrapperException_ThrowUpliftVanCalculatorException() { // Setup UpliftVanCalculatorInput input = CreateValidCalculatorInput(); - var testMacroStabilityInwardsKernelFactory = new TestMacroStabilityInwardsKernelFactory(); - UpliftVanKernelStub upliftVanKernel = testMacroStabilityInwardsKernelFactory.LastCreatedUpliftVanKernel; - upliftVanKernel.ThrowExceptionOnCalculate = true; + using (new MacroStabilityInwardsKernelFactoryConfig()) + { + var factory = (TestMacroStabilityInwardsKernelFactory) MacroStabilityInwardsKernelWrapperFactory.Instance; + UpliftVanKernelStub upliftVanKernel = factory.LastCreatedUpliftVanKernel; + upliftVanKernel.ThrowExceptionOnCalculate = true; - // Call - TestDelegate test = () => new UpliftVanCalculator(input, testMacroStabilityInwardsKernelFactory).Calculate(); + // Call + TestDelegate test = () => new UpliftVanCalculator(input, factory).Calculate(); - // Assert - var exception = Assert.Throws(test); - Assert.IsInstanceOf(exception.InnerException); - Assert.AreEqual(exception.InnerException.Message, exception.Message); + // Assert + var exception = Assert.Throws(test); + Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual(exception.InnerException.Message, exception.Message); + } } [Test] public void Validate_CalculatorWithValidInput_KernelValidateMethodCalled() { // Setup UpliftVanCalculatorInput input = CreateValidCalculatorInput(); - var testMacroStabilityInwardsKernelFactory = new TestMacroStabilityInwardsKernelFactory(); + using (new MacroStabilityInwardsKernelFactoryConfig()) + { + var factory = (TestMacroStabilityInwardsKernelFactory) MacroStabilityInwardsKernelWrapperFactory.Instance; - // Call - new UpliftVanCalculator(input, testMacroStabilityInwardsKernelFactory).Validate(); + // Call + new UpliftVanCalculator(input, factory).Validate(); - // Assert - Assert.IsTrue(testMacroStabilityInwardsKernelFactory.LastCreatedUpliftVanKernel.Validated); + // Assert + Assert.IsTrue(factory.LastCreatedUpliftVanKernel.Validated); + } } [Test] public void Validate_CalculatorWithValidInput_ReturnEmptyEnumerable() { // Setup UpliftVanCalculatorInput input = CreateValidCalculatorInput(); - var testMacroStabilityInwardsKernelFactory = new TestMacroStabilityInwardsKernelFactory(); + using (new MacroStabilityInwardsKernelFactoryConfig()) + { + var factory = (TestMacroStabilityInwardsKernelFactory) MacroStabilityInwardsKernelWrapperFactory.Instance; - // Call - IEnumerable kernelMessages = new UpliftVanCalculator(input, testMacroStabilityInwardsKernelFactory).Validate(); + // Call + IEnumerable kernelMessages = new UpliftVanCalculator(input, factory).Validate(); - // Assert - CollectionAssert.IsEmpty(kernelMessages); + // Assert + CollectionAssert.IsEmpty(kernelMessages); + } } [Test] public void Validate_KernelReturnsValidationResults_ReturnsEnumerableWithOnlyErrorsAndWarnings() { // Setup - var testMacroStabilityInwardsKernelFactory = new TestMacroStabilityInwardsKernelFactory(); - UpliftVanKernelStub upliftVanKernel = testMacroStabilityInwardsKernelFactory.LastCreatedUpliftVanKernel; - upliftVanKernel.ReturnValidationResults = true; + using (new MacroStabilityInwardsKernelFactoryConfig()) + { + var factory = (TestMacroStabilityInwardsKernelFactory) MacroStabilityInwardsKernelWrapperFactory.Instance; + UpliftVanKernelStub upliftVanKernel = factory.LastCreatedUpliftVanKernel; + upliftVanKernel.ReturnValidationResults = true; - // Call - IEnumerable kernelMessages = new UpliftVanCalculator(CreateValidCalculatorInput(), - testMacroStabilityInwardsKernelFactory).Validate().ToList(); + // Call + IEnumerable kernelMessages = new UpliftVanCalculator(CreateValidCalculatorInput(), + factory).Validate().ToList(); - // Assert - Assert.AreEqual(2, kernelMessages.Count()); - UpliftVanKernelMessage firstMessage = kernelMessages.ElementAt(0); - Assert.AreEqual("Validation Warning", firstMessage.Message); - Assert.AreEqual(UpliftVanKernelMessageType.Warning, firstMessage.ResultType); - UpliftVanKernelMessage secondMessage = kernelMessages.ElementAt(1); - Assert.AreEqual("Validation Error", secondMessage.Message); - Assert.AreEqual(UpliftVanKernelMessageType.Error, secondMessage.ResultType); + // Assert + Assert.AreEqual(2, kernelMessages.Count()); + UpliftVanKernelMessage firstMessage = kernelMessages.ElementAt(0); + Assert.AreEqual("Validation Warning", firstMessage.Message); + Assert.AreEqual(UpliftVanKernelMessageType.Warning, firstMessage.ResultType); + UpliftVanKernelMessage secondMessage = kernelMessages.ElementAt(1); + Assert.AreEqual("Validation Error", secondMessage.Message); + Assert.AreEqual(UpliftVanKernelMessageType.Error, secondMessage.ResultType); + } } [Test] public void Validate_KernelThrowsUpliftVanKernelWrapperException_ThrowUpliftVanCalculatorException() { // Setup - var testMacroStabilityInwardsKernelFactory = new TestMacroStabilityInwardsKernelFactory(); - UpliftVanKernelStub upliftVanKernel = testMacroStabilityInwardsKernelFactory.LastCreatedUpliftVanKernel; - upliftVanKernel.ThrowExceptionOnValidate = true; + using (new MacroStabilityInwardsKernelFactoryConfig()) + { + var factory = (TestMacroStabilityInwardsKernelFactory) MacroStabilityInwardsKernelWrapperFactory.Instance; + UpliftVanKernelStub upliftVanKernel = factory.LastCreatedUpliftVanKernel; + upliftVanKernel.ThrowExceptionOnValidate = true; - // Call - TestDelegate test = () => new UpliftVanCalculator(CreateValidCalculatorInput(), testMacroStabilityInwardsKernelFactory).Validate(); + // Call + TestDelegate test = () => new UpliftVanCalculator(CreateValidCalculatorInput(), factory).Validate(); - // Assert - var exception = Assert.Throws(test); - Assert.IsInstanceOf(exception.InnerException); - Assert.AreEqual(exception.InnerException.Message, exception.Message); + // Assert + var exception = Assert.Throws(test); + Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual(exception.InnerException.Message, exception.Message); + } } private static UpliftVanCalculatorInput CreateValidCalculatorInput() Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Calculators/Waternet/WaternetCalculatorTest.cs =================================================================== diff -u -rc4392a12110e2bb3549c5fee1ec319c229b67198 -rfc8bf1b38d4b3f9bb6f6d9dab951543b92901c8d --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Calculators/Waternet/WaternetCalculatorTest.cs (.../WaternetCalculatorTest.cs) (revision c4392a12110e2bb3549c5fee1ec319c229b67198) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Calculators/Waternet/WaternetCalculatorTest.cs (.../WaternetCalculatorTest.cs) (revision fc8bf1b38d4b3f9bb6f6d9dab951543b92901c8d) @@ -95,59 +95,68 @@ { // Setup WaternetCalculatorInput input = WaternetCalculatorInputTestFactory.CreateValidCalculatorInput(); - var testMacroStabilityInwardsKernelFactory = new TestMacroStabilityInwardsKernelFactory(); - WaternetKernelStub waternetKernel = testMacroStabilityInwardsKernelFactory.LastCreatedWaternetKernel; - SetCompleteKernelOutput(waternetKernel); + using (new MacroStabilityInwardsKernelFactoryConfig()) + { + var factory = (TestMacroStabilityInwardsKernelFactory) MacroStabilityInwardsKernelWrapperFactory.Instance; + WaternetKernelStub waternetKernel = factory.LastCreatedWaternetKernel; + SetCompleteKernelOutput(waternetKernel); - // Call - new TestWaternetCalculator(input, testMacroStabilityInwardsKernelFactory).Calculate(); + // Call + new TestWaternetCalculator(input, factory).Calculate(); - // Assert - Assert.IsTrue(waternetKernel.Calculated); + // Assert + Assert.IsTrue(waternetKernel.Calculated); + } } [Test] public void Calculate_KernelThrowsWaternetKernelWrapperException_ThrowWaternetCalculatorException() { // Setup WaternetCalculatorInput input = WaternetCalculatorInputTestFactory.CreateValidCalculatorInput(); - var testMacroStabilityInwardsKernelFactory = new TestMacroStabilityInwardsKernelFactory(); - WaternetKernelStub waternetKernel = testMacroStabilityInwardsKernelFactory.LastCreatedWaternetKernel; - waternetKernel.ThrowExceptionOnCalculate = true; + using (new MacroStabilityInwardsKernelFactoryConfig()) + { + var factory = (TestMacroStabilityInwardsKernelFactory) MacroStabilityInwardsKernelWrapperFactory.Instance; + WaternetKernelStub waternetKernel = factory.LastCreatedWaternetKernel; + waternetKernel.ThrowExceptionOnCalculate = true; - // Call - TestDelegate test = () => new TestWaternetCalculator(input, testMacroStabilityInwardsKernelFactory).Calculate(); + // Call + TestDelegate test = () => new TestWaternetCalculator(input, factory).Calculate(); - // Assert - var exception = Assert.Throws(test); - Assert.IsInstanceOf(exception.InnerException); - Assert.AreEqual(exception.InnerException.Message, exception.Message); + // Assert + var exception = Assert.Throws(test); + Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual(exception.InnerException.Message, exception.Message); + } } [Test] public void Calculate_KernelWithCompleteOutput_OutputCorrectlyReturnedByCalculator() { WaternetCalculatorInput input = WaternetCalculatorInputTestFactory.CreateValidCalculatorInput(); - var testMacroStabilityInwardsKernelFactory = new TestMacroStabilityInwardsKernelFactory(); - WaternetKernelStub kernel = testMacroStabilityInwardsKernelFactory.LastCreatedWaternetKernel; - SetCompleteKernelOutput(kernel); + using (new MacroStabilityInwardsKernelFactoryConfig()) + { + var factory = (TestMacroStabilityInwardsKernelFactory) MacroStabilityInwardsKernelWrapperFactory.Instance; + WaternetKernelStub kernel = factory.LastCreatedWaternetKernel; + SetCompleteKernelOutput(kernel); - // Call - WaternetCalculatorResult result = new TestWaternetCalculator(input, testMacroStabilityInwardsKernelFactory).Calculate(); + // Call + WaternetCalculatorResult result = new TestWaternetCalculator(input, factory).Calculate(); - // Assert - Assert.IsNotNull(result); - var expectedPhreaticLines = new List - { - kernel.Waternet.PhreaticLine - }; - expectedPhreaticLines.AddRange(kernel.Waternet.HeadLineList); + // Assert + Assert.IsNotNull(result); + var expectedPhreaticLines = new List + { + kernel.Waternet.PhreaticLine + }; + expectedPhreaticLines.AddRange(kernel.Waternet.HeadLineList); - WaternetCalculatorOutputAssert.AssertPhreaticLines(expectedPhreaticLines.ToArray(), result.PhreaticLines.ToArray()); - WaternetCalculatorOutputAssert.AssertWaternetLines(kernel.Waternet.WaternetLineList.ToArray(), result.WaternetLines.ToArray()); + WaternetCalculatorOutputAssert.AssertPhreaticLines(expectedPhreaticLines.ToArray(), result.PhreaticLines.ToArray()); + WaternetCalculatorOutputAssert.AssertWaternetLines(kernel.Waternet.WaternetLineList.ToArray(), result.WaternetLines.ToArray()); + } } private static void SetCompleteKernelOutput(WaternetKernelStub kernel) Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Calculators/Waternet/WaternetDailyCalculatorTest.cs =================================================================== diff -u -rff37b79ad9133423d04e991ac6152cd6ed552274 -rfc8bf1b38d4b3f9bb6f6d9dab951543b92901c8d --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Calculators/Waternet/WaternetDailyCalculatorTest.cs (.../WaternetDailyCalculatorTest.cs) (revision ff37b79ad9133423d04e991ac6152cd6ed552274) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Calculators/Waternet/WaternetDailyCalculatorTest.cs (.../WaternetDailyCalculatorTest.cs) (revision fc8bf1b38d4b3f9bb6f6d9dab951543b92901c8d) @@ -61,21 +61,24 @@ { // Setup WaternetCalculatorInput input = WaternetCalculatorInputTestFactory.CreateCompleteCalculatorInput(); - var testMacroStabilityInwardsKernelFactory = new TestMacroStabilityInwardsKernelFactory(); - WaternetKernelStub waternetKernel = testMacroStabilityInwardsKernelFactory.LastCreatedWaternetKernel; - SetKernelOutput(waternetKernel); + using (new MacroStabilityInwardsKernelFactoryConfig()) + { + var factory = (TestMacroStabilityInwardsKernelFactory) MacroStabilityInwardsKernelWrapperFactory.Instance; + WaternetKernelStub waternetKernel = factory.LastCreatedWaternetKernel; + SetKernelOutput(waternetKernel); - // Call - new WaternetDailyCalculator(input, testMacroStabilityInwardsKernelFactory).Calculate(); + // Call + new WaternetDailyCalculator(input, factory).Calculate(); - // Assert - LayerWithSoil[] layersWithSoil = LayerWithSoilCreator.Create(input.SoilProfile); + // Assert + LayerWithSoil[] layersWithSoil = LayerWithSoilCreator.Create(input.SoilProfile); - KernelInputAssert.AssertSoilModels(SoilModelCreator.Create(layersWithSoil.Select(lws => lws.Soil).ToArray()), waternetKernel.SoilModel); - KernelInputAssert.AssertSoilProfiles(SoilProfileCreator.Create(input.SoilProfile.PreconsolidationStresses, layersWithSoil), waternetKernel.SoilProfile); - KernelInputAssert.AssertStabilityLocations(WaternetStabilityLocationCreator.Create(input), waternetKernel.Location); - KernelInputAssert.AssertSurfaceLines(SurfaceLineCreator.Create(input.SurfaceLine, input.LandwardDirection), waternetKernel.SurfaceLine); + KernelInputAssert.AssertSoilModels(SoilModelCreator.Create(layersWithSoil.Select(lws => lws.Soil).ToArray()), waternetKernel.SoilModel); + KernelInputAssert.AssertSoilProfiles(SoilProfileCreator.Create(input.SoilProfile.PreconsolidationStresses, layersWithSoil), waternetKernel.SoilProfile); + KernelInputAssert.AssertStabilityLocations(WaternetStabilityLocationCreator.Create(input), waternetKernel.Location); + KernelInputAssert.AssertSurfaceLines(SurfaceLineCreator.Create(input.SurfaceLine, input.LandwardDirection), waternetKernel.SurfaceLine); + } } private static void SetKernelOutput(WaternetKernelStub waternetKernel) Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Calculators/Waternet/WaternetExtremeCalculatorTest.cs =================================================================== diff -u -rc4392a12110e2bb3549c5fee1ec319c229b67198 -rfc8bf1b38d4b3f9bb6f6d9dab951543b92901c8d --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Calculators/Waternet/WaternetExtremeCalculatorTest.cs (.../WaternetExtremeCalculatorTest.cs) (revision c4392a12110e2bb3549c5fee1ec319c229b67198) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Calculators/Waternet/WaternetExtremeCalculatorTest.cs (.../WaternetExtremeCalculatorTest.cs) (revision fc8bf1b38d4b3f9bb6f6d9dab951543b92901c8d) @@ -61,21 +61,24 @@ { // Setup WaternetCalculatorInput input = WaternetCalculatorInputTestFactory.CreateCompleteCalculatorInput(); - var testMacroStabilityInwardsKernelFactory = new TestMacroStabilityInwardsKernelFactory(); - WaternetKernelStub waternetKernel = testMacroStabilityInwardsKernelFactory.LastCreatedWaternetKernel; - SetKernelOutput(waternetKernel); + using (new MacroStabilityInwardsKernelFactoryConfig()) + { + var factory = (TestMacroStabilityInwardsKernelFactory) MacroStabilityInwardsKernelWrapperFactory.Instance; + WaternetKernelStub waternetKernel = factory.LastCreatedWaternetKernel; + SetKernelOutput(waternetKernel); - // Call - new WaternetExtremeCalculator(input, testMacroStabilityInwardsKernelFactory).Calculate(); + // Call + new WaternetExtremeCalculator(input, factory).Calculate(); - // Assert - LayerWithSoil[] layersWithSoil = LayerWithSoilCreator.Create(input.SoilProfile); + // Assert + LayerWithSoil[] layersWithSoil = LayerWithSoilCreator.Create(input.SoilProfile); - KernelInputAssert.AssertSoilModels(SoilModelCreator.Create(layersWithSoil.Select(lws => lws.Soil).ToArray()), waternetKernel.SoilModel); - KernelInputAssert.AssertSoilProfiles(SoilProfileCreator.Create(input.SoilProfile.PreconsolidationStresses, layersWithSoil), waternetKernel.SoilProfile); - KernelInputAssert.AssertStabilityLocations(WaternetStabilityLocationCreator.Create(input), waternetKernel.Location); - KernelInputAssert.AssertSurfaceLines(SurfaceLineCreator.Create(input.SurfaceLine, input.LandwardDirection), waternetKernel.SurfaceLine); + KernelInputAssert.AssertSoilModels(SoilModelCreator.Create(layersWithSoil.Select(lws => lws.Soil).ToArray()), waternetKernel.SoilModel); + KernelInputAssert.AssertSoilProfiles(SoilProfileCreator.Create(input.SoilProfile.PreconsolidationStresses, layersWithSoil), waternetKernel.SoilProfile); + KernelInputAssert.AssertStabilityLocations(WaternetStabilityLocationCreator.Create(input), waternetKernel.Location); + KernelInputAssert.AssertSurfaceLines(SurfaceLineCreator.Create(input.SurfaceLine, input.LandwardDirection), waternetKernel.SurfaceLine); + } } private static void SetKernelOutput(WaternetKernelStub waternetKernel) Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test/Calculators/TestMacroStabilityInwardsCalculatorFactoryTest.cs =================================================================== diff -u -r7869115120e7341826283ec22afdf03634d13775 -rfc8bf1b38d4b3f9bb6f6d9dab951543b92901c8d --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test/Calculators/TestMacroStabilityInwardsCalculatorFactoryTest.cs (.../TestMacroStabilityInwardsCalculatorFactoryTest.cs) (revision 7869115120e7341826283ec22afdf03634d13775) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test/Calculators/TestMacroStabilityInwardsCalculatorFactoryTest.cs (.../TestMacroStabilityInwardsCalculatorFactoryTest.cs) (revision fc8bf1b38d4b3f9bb6f6d9dab951543b92901c8d) @@ -28,7 +28,6 @@ using Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Calculators.Input; using Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Calculators.UpliftVan; using Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Calculators.Waternet; -using Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Kernels; using Ringtoets.MacroStabilityInwards.Primitives; namespace Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test.Calculators @@ -66,7 +65,7 @@ }); // Call - var calculator = (UpliftVanCalculatorStub) factory.CreateUpliftVanCalculator(input, new TestMacroStabilityInwardsKernelFactory()); + var calculator = (UpliftVanCalculatorStub) factory.CreateUpliftVanCalculator(input, null); // Assert Assert.AreSame(input, calculator.Input);