Index: DamEngine/trunk/src/Deltares.DamEngine.TestHelpers/GeneralHelper.cs =================================================================== diff -u -r4518 -r4519 --- DamEngine/trunk/src/Deltares.DamEngine.TestHelpers/GeneralHelper.cs (.../GeneralHelper.cs) (revision 4518) +++ DamEngine/trunk/src/Deltares.DamEngine.TestHelpers/GeneralHelper.cs (.../GeneralHelper.cs) (revision 4519) @@ -39,10 +39,10 @@ { public static int DetermineNumberOfCalculationErrors(List calculationMessages) { - int errorCount = 0; - foreach (var logMessage in calculationMessages) + var errorCount = 0; + foreach (LogMessage logMessage in calculationMessages) { - if ((logMessage.MessageType == LogMessageType.Error) || (logMessage.MessageType == LogMessageType.FatalError)) + if (logMessage.MessageType is LogMessageType.Error or LogMessageType.FatalError) { errorCount++; } @@ -62,7 +62,7 @@ // Validate input Assert.IsNotNull(engineInterface.DamProjectData); string validationMessages = engineInterface.Validate(); - string extraValidationMessage = ""; + var extraValidationMessage = ""; if (outputXml != "") { extraValidationMessage = ", see output xml in debugger"; @@ -105,8 +105,8 @@ return output; } - string assertMessage = "No results available."; - foreach (var calcMessage in output.Results.CalculationMessages) + var assertMessage = "No results available."; + foreach (Message calcMessage in output.Results.CalculationMessages) { assertMessage = assertMessage + Environment.NewLine + calcMessage.Message1; } @@ -117,13 +117,13 @@ private static void CheckDependencyOnStiFiles(Output output) { - foreach (var calcMessage in output.Results.CalculationMessages) + foreach (Message calcMessage in output.Results.CalculationMessages) { if ((calcMessage.MessageType == MessageMessageType.Error) & calcMessage.Message1.Contains("The preparation for this " + "calculation failed")) { - var assertMessage = "No results available due to dependency on 2D geometries (sti files) and the old " + - "MacroStability kernel wrapper implementation"; + string assertMessage = "No results available due to dependency on 2D geometries (sti files) and the old " + + "MacroStability kernel wrapper implementation"; Assert.IsNotNull(output.Results.CalculationResults, assertMessage); } } @@ -133,53 +133,49 @@ { if (engineInterface.DamProjectData.DamProjectCalculationSpecification.AnalysisTypeForSerializationPurposeOnly == AnalysisType.AdaptGeometry) { - bool isGeometryAdapted = false; + var isIteratedFilePresent = false; + foreach (DesignResult calculationResult in outputResults.CalculationResults) { bool isDesignSuccessful = IsAdaptGeometrySuccessful(outputResults.CalculationMessages, calculationResult); double fosRequired = FetchRequiredFactor(engineInterface, calculationResult.ScenarioName, calculationResult.LocationName); double fosCalculated = FetchCalculatedFactor(engineInterface, calculationResult); + if (isDesignSuccessful) + { + const string message = "After adapting the geometry, the calculated safety factor is less than the" + + " required safety factor; this is unexpected."; + Assert.IsTrue(fosCalculated >= fosRequired, message); + } + else + { + const string message = "As the design was not successful and had to stop, the calculated safety " + + "factor should be less than the required safety factor but this is not the case."; + Assert.IsTrue(fosRequired >= fosCalculated, message); + } string fileName = calculationResult.BaseFileName; - bool isGeometryAdaptedInThisLocation = fileName.Contains("Ite(") && !fileName.Contains("Ite(1)"); - isGeometryAdapted = isGeometryAdapted || isGeometryAdaptedInThisLocation; + isIteratedFilePresent = isIteratedFilePresent || + (!fileName.IsNullOrEmpty() && fileName.Contains("Ite(") && !fileName.Contains("Ite(1)")); + } - if (isGeometryAdaptedInThisLocation) - { - if (isDesignSuccessful) - { - const string message = "After adapting the geometry, the calculated safety factor is less than the" + - " required safety factor; this is unexpected."; - Assert.IsTrue(fosCalculated >= fosRequired, message); - } - else - { - const string message = "As the design was not successful and had to stop, the calculated safety " + - "factor should be less than the required safety factor but this is not the case."; - Assert.IsTrue(fosRequired >= fosCalculated, message); - } - } + // The iterated file is created only for the stability mechanism (not for piping) to be opened in D-Stability + if (engineInterface.DamProjectData.DamProjectCalculationSpecification.CurrentSpecification.FailureMechanismSystemType != FailureMechanismSystemType.Piping) + { + Assert.IsTrue(isIteratedFilePresent, "The AnalyseType is set to AdaptGeometry in the input, however the geometry was " + + "not adapted in any location. Either set the AnalysisType to NoAdaptation or " + + "increase the required safety factor."); } - // Assert.IsTrue(isGeometryAdapted, "The AnalyseType is set to AdaptGeometry in the input, however the geometry was " + - // "not adapted in any location. Either set the AnalysisType to NoAdaptation or " + - // "increase the required safety factor."); } } private static bool IsAdaptGeometrySuccessful(Message[] messages, DesignResult results) { - foreach (var message in messages) - { - string location = "Location '" + results.LocationName + "'"; - string profile = "subsoil scenario '" + results.ProfileName + "'"; - string scenario = "design scenario '" + results.ScenarioName + "'"; - if (message.Message1.Contains("The design was not successful.") && message.Message1.Contains(location) && - message.Message1.Contains(profile) && message.Message1.Contains(scenario)) - { - return false; - } - } - return true; + return !(from message in messages let location = "Location '" + results.LocationName + "'" + let profile = "subsoil scenario '" + results.ProfileName + "'" + let scenario = "design scenario '" + results.ScenarioName + "'" + where message.Message1.Contains("The design was not successful.") && + message.Message1.Contains(location) && message.Message1.Contains(profile) && + message.Message1.Contains(scenario) select message).Any(); } private static double FetchRequiredFactor(EngineInterface engineInterface, string scenarioName, string locationName) @@ -190,22 +186,17 @@ { if (location.Name == locationName && scenario.LocationScenarioID == scenarioName) { - switch (engineInterface.DamProjectData.DamProjectCalculationSpecification.CurrentSpecification.FailureMechanismSystemType) + return engineInterface.DamProjectData.DamProjectCalculationSpecification.CurrentSpecification.FailureMechanismSystemType switch { - case FailureMechanismSystemType.StabilityInside: - return scenario.RequiredSafetyFactorStabilityInnerSlope; - - case FailureMechanismSystemType.StabilityOutside: - return scenario.RequiredSafetyFactorStabilityOuterSlope; - - case FailureMechanismSystemType.Piping: - return scenario.RequiredSafetyFactorPiping; - default: - throw new ArgumentOutOfRangeException(); - } + FailureMechanismSystemType.StabilityInside => scenario.RequiredSafetyFactorStabilityInnerSlope, + FailureMechanismSystemType.StabilityOutside => scenario.RequiredSafetyFactorStabilityOuterSlope, + FailureMechanismSystemType.Piping => scenario.RequiredSafetyFactorPiping, + _ => throw new ArgumentOutOfRangeException() + }; } } } + return 999; } @@ -217,9 +208,19 @@ case FailureMechanismSystemType.StabilityOutside: return results.StabilityDesignResults.SafetyFactor; case FailureMechanismSystemType.Piping: - return results.PipingDesignResults.Wti2017BackwardErosionFactor; + switch (engineInterface.DamProjectData.DamProjectCalculationSpecification.CurrentSpecification.PipingModelType) + { + case PipingModelType.Wti2017: + return results.PipingDesignResults.Wti2017BackwardErosionFactor; + case PipingModelType.Bligh: + return results.PipingDesignResults.BlighFactor; + } + + break; default: throw new ArgumentOutOfRangeException(); } + + return 0; } } \ No newline at end of file