public void Calculate_KernelReturnsLogMessages_ReturnsExpectedLogMessages() { // Setup UpliftVanCalculatorInput input = UpliftVanCalculatorInputTestFactory.Create(); using (new MacroStabilityInwardsKernelFactoryConfig()) { var factory = (TestMacroStabilityInwardsKernelFactory)MacroStabilityInwardsKernelWrapperFactory.Instance; UpliftVanKernelStub upliftVanKernel = factory.LastCreatedUpliftVanKernel; upliftVanKernel.ReturnLogMessages = true; SetCompleteKernelOutput(upliftVanKernel); SetValidKernelOutput(factory.LastCreatedWaternetDailyKernel); SetValidKernelOutput(factory.LastCreatedWaternetExtremeKernel); // Call new UpliftVanCalculator(input, factory).Calculate(); // Assert Assert.AreEqual(3, upliftVanKernel.CalculationMessages.Count()); MessageHelper.AssertMessage(MessageType.Warning, "Calculation Warning", upliftVanKernel.CalculationMessages.ElementAt(0)); MessageHelper.AssertMessage(MessageType.Error, "Calculation Error", upliftVanKernel.CalculationMessages.ElementAt(1)); MessageHelper.AssertMessage(MessageType.Info, "Calculation Info", upliftVanKernel.CalculationMessages.ElementAt(2)); } }
public void Validate_KernelReturnsValidationResults_ReturnsEnumerableWithOnlyErrorsAndWarnings() { // Setup using (new MacroStabilityInwardsKernelFactoryConfig()) { var factory = (TestMacroStabilityInwardsKernelFactory)MacroStabilityInwardsKernelWrapperFactory.Instance; UpliftVanKernelStub upliftVanKernel = factory.LastCreatedUpliftVanKernel; upliftVanKernel.ReturnValidationResults = true; SetValidKernelOutput(factory.LastCreatedWaternetDailyKernel); SetValidKernelOutput(factory.LastCreatedWaternetExtremeKernel); // Call IEnumerable <MacroStabilityInwardsKernelMessage> kernelMessages = new UpliftVanCalculator( UpliftVanCalculatorInputTestFactory.Create(), factory).Validate().ToList(); // 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); } }
public void Calculate_KernelWithCompleteOutput_OutputCorrectlyReturnedByCalculator() { // Setup UpliftVanCalculatorInput input = UpliftVanCalculatorInputTestFactory.Create(); using (new MacroStabilityInwardsKernelFactoryConfig()) { var factory = (TestMacroStabilityInwardsKernelFactory)MacroStabilityInwardsKernelWrapperFactory.Instance; UpliftVanKernelStub upliftVanKernel = factory.LastCreatedUpliftVanKernel; SetCompleteKernelOutput(upliftVanKernel); SetValidKernelOutput(factory.LastCreatedWaternetDailyKernel); SetValidKernelOutput(factory.LastCreatedWaternetExtremeKernel); // Call UpliftVanCalculatorResult result = new UpliftVanCalculator(input, factory).Calculate(); // Assert Assert.IsNotNull(result); Assert.AreEqual(upliftVanKernel.FactorOfStability, result.FactorOfStability); Assert.AreEqual(upliftVanKernel.ForbiddenZonesXEntryMax, result.ForbiddenZonesXEntryMax); Assert.AreEqual(upliftVanKernel.ForbiddenZonesXEntryMin, result.ForbiddenZonesXEntryMin); UpliftVanCalculatorOutputAssert.AssertUpliftVanSlidingCurveResult(UpliftVanSlidingCurveResultCreator.Create(upliftVanKernel.SlidingCurveResult), result.SlidingCurveResult); UpliftVanCalculatorOutputAssert.AssertUpliftVanCalculationGridResult(UpliftVanCalculationGridResultCreator.Create(upliftVanKernel.UpliftVanCalculationGridResult), result.CalculationGridResult); } }
private static void SetCompleteKernelOutput(UpliftVanKernelStub upliftVanKernel) { var random = new Random(11); upliftVanKernel.FactorOfStability = random.NextDouble(); upliftVanKernel.ForbiddenZonesXEntryMax = random.NextDouble(); upliftVanKernel.ForbiddenZonesXEntryMin = random.NextDouble(); SetValidKernelOutput(upliftVanKernel); }
public void Validate_KernelThrowsUpliftVanKernelWrapperException_ThrowUpliftVanCalculatorException() { // Setup using (new MacroStabilityInwardsKernelFactoryConfig()) { var factory = (TestMacroStabilityInwardsKernelFactory)MacroStabilityInwardsKernelWrapperFactory.Instance; UpliftVanKernelStub upliftVanKernel = factory.LastCreatedUpliftVanKernel; upliftVanKernel.ThrowExceptionOnValidate = true; SetValidKernelOutput(factory.LastCreatedWaternetDailyKernel); SetValidKernelOutput(factory.LastCreatedWaternetExtremeKernel); // Call void Call() => new UpliftVanCalculator(UpliftVanCalculatorInputTestFactory.Create(), factory).Validate(); // Assert var exception = Assert.Throws <UpliftVanCalculatorException>(Call); Assert.IsInstanceOf <UpliftVanKernelWrapperException>(exception.InnerException); Assert.AreEqual(exception.InnerException.Message, exception.Message); } }
public void Calculate_CalculatorWithValidInputAndKernelWithValidOutput_KernelCalculateMethodCalled() { // Setup UpliftVanCalculatorInput input = UpliftVanCalculatorInputTestFactory.Create(); using (new MacroStabilityInwardsKernelFactoryConfig()) { var factory = (TestMacroStabilityInwardsKernelFactory)MacroStabilityInwardsKernelWrapperFactory.Instance; UpliftVanKernelStub upliftVanKernel = factory.LastCreatedUpliftVanKernel; SetValidKernelOutput(upliftVanKernel); SetValidKernelOutput(factory.LastCreatedWaternetDailyKernel); SetValidKernelOutput(factory.LastCreatedWaternetExtremeKernel); // Call new UpliftVanCalculator(input, factory).Calculate(); // Assert Assert.IsTrue(upliftVanKernel.Calculated); } }
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); } }
public void Calculate_KernelThrowsUpliftVanKernelWrapperExceptionWithLogMessages_ThrowUpliftVanCalculatorException() { // Setup UpliftVanCalculatorInput input = UpliftVanCalculatorInputTestFactory.Create(); using (new MacroStabilityInwardsKernelFactoryConfig()) { var factory = (TestMacroStabilityInwardsKernelFactory)MacroStabilityInwardsKernelWrapperFactory.Instance; UpliftVanKernelStub upliftVanKernel = factory.LastCreatedUpliftVanKernel; upliftVanKernel.ThrowExceptionOnCalculate = true; upliftVanKernel.ReturnLogMessages = true; SetValidKernelOutput(factory.LastCreatedWaternetDailyKernel); SetValidKernelOutput(factory.LastCreatedWaternetExtremeKernel); // Call void Call() => new UpliftVanCalculator(input, factory).Calculate(); // Assert var exception = Assert.Throws <UpliftVanCalculatorException>(Call); Assert.IsInstanceOf <UpliftVanKernelWrapperException>(exception.InnerException); Assert.AreEqual(exception.InnerException.Message, exception.Message); IEnumerable <Message> expectedMessages = GetSupportMessages(upliftVanKernel.CalculationMessages); Assert.AreEqual(expectedMessages.Count(), exception.KernelMessages.Count()); for (var i = 0; i < expectedMessages.Count(); i++) { Message upliftVanKernelCalculationMessage = expectedMessages.ElementAt(i); MacroStabilityInwardsKernelMessage exceptionKernelMessage = exception.KernelMessages.ElementAt(i); Assert.AreEqual(upliftVanKernelCalculationMessage.Content, exceptionKernelMessage.Message); Assert.AreEqual(GetMessageType(upliftVanKernelCalculationMessage.MessageType), exceptionKernelMessage.Type); } } }
private static void SetValidKernelOutput(UpliftVanKernelStub upliftVanKernel) { upliftVanKernel.SlidingCurveResult = CreateSlidingDualCircle(); upliftVanKernel.UpliftVanCalculationGridResult = CreateUpliftVanCalculationGrid(); }
/// <summary> /// Creates a new instance of <see cref="TestMacroStabilityInwardsKernelFactory"/>. /// </summary> public TestMacroStabilityInwardsKernelFactory() { LastCreatedUpliftVanKernel = new UpliftVanKernelStub(); LastCreatedWaternetExtremeKernel = new WaternetKernelStub(); LastCreatedWaternetDailyKernel = new WaternetKernelStub(); }