Index: DamClients/DamUI/trunk/src/Dam/Tests/DamEngineIo/FillXmlInputFromDamUiTests.cs =================================================================== diff -u -r2527 -r2612 --- DamClients/DamUI/trunk/src/Dam/Tests/DamEngineIo/FillXmlInputFromDamUiTests.cs (.../FillXmlInputFromDamUiTests.cs) (revision 2527) +++ DamClients/DamUI/trunk/src/Dam/Tests/DamEngineIo/FillXmlInputFromDamUiTests.cs (.../FillXmlInputFromDamUiTests.cs) (revision 2612) @@ -85,6 +85,8 @@ CompareDamProjectData(actualDamProjectData, expectedDamProjectData); } + #region CreateTestData + private DamProjectData CreateExampleDamProjectData() { var damProjectData = new DamProjectData(); @@ -415,6 +417,7 @@ designScenario.RequiredSafetyFactorPiping = 1.0 * factor + 0.66; return designScenario; } + private List CreateSurfaceLines() { var surfaceLines = new List(); @@ -441,6 +444,7 @@ AddPointToSurfaceLine(surfaceLine, 18.0, 1.0, CharacteristicPointType.DikeToeAtPolder); AddPointToSurfaceLine(surfaceLine, 24.0, 1.0, CharacteristicPointType.SurfaceLevelInside); } + private void AddPointToSurfaceLine(SurfaceLine2 surfaceLine, double xCoordinate, double zCoordinate, CharacteristicPointType characteristicPointType) { var geometryPoint = new GeometryPoint() @@ -485,6 +489,7 @@ dike.SoilProfiles.Add(profile); } } + private static void FillSegments(DamProjectData damProjectData) { var segmentCount = 2; @@ -513,6 +518,9 @@ damProjectData.WaterBoard.Segments.Add(segment); } } + + #endregion CreateTestData + [Test] [TestCase("location_12_2_1D1")] // Between "location_12" and "_2_1D1" there are 2 illegal characters (1F hex) [ExpectedException(typeof(IdValidatorException), ExpectedMessage = "Location has an invalid name location_12_2_1D1")] @@ -601,21 +609,98 @@ [ExpectedException(typeof(NullReferenceException), ExpectedMessage = "Location 'Location 1', scenario '1' has no river level")] public void RaiseExceptionWhenRiverLevelIsMissing() { - // Given DataSet with undefined riverlevel + // Given DataSet with undefined RiverLevel DamProjectData expectedDamProjectData = CreateExampleDamProjectData(); var scenario = expectedDamProjectData.WaterBoard.Dikes[0].Locations[0].Scenarios[0]; scenario.RiverLevel = null; // When Writing Xml - string xmlString; Input input = FillXmlInputFromDamUi.CreateInput(expectedDamProjectData); - xmlString = DamXmlSerialization.SaveInputAsXmlString(input); + string xmlString = DamXmlSerialization.SaveInputAsXmlString(input); // Then Raise Exception With Clear Message() input = DamXmlSerialization.LoadInputFromXmlString(xmlString); DamProjectData actualDamProjectData = FillDamUiFromXmlInput.CreateDamProjectData(input); CompareDamProjectData(actualDamProjectData, expectedDamProjectData); } + + [Test] + [TestCase(FailureMechanismSystemType.StabilityOutside)] + [ExpectedException(typeof(NullReferenceException), ExpectedMessage = "Location 'Location 1', scenario '1' has no river level low")] + public void RaiseExceptionWhenRiverLevelLowIsMissingForStabilityOutside(FailureMechanismSystemType failureMechanismSystemType) + { + // Given DataSet with undefined RiverLevelLow, for stability outside + DamProjectData expectedDamProjectData = CreateExampleDamProjectData(); + var scenario = expectedDamProjectData.WaterBoard.Dikes[0].Locations[0].Scenarios[0]; + scenario.RiverLevelLow = null; + var currentSpecification = expectedDamProjectData.DamProjectCalculationSpecification.CurrentSpecification; + currentSpecification.FailureMechanismSystemType = failureMechanismSystemType; + // First set PipingModelType to default because it will be set to default when reading the xml back when FailureMechanismSystemType is not Piping + currentSpecification.PipingModelType = PipingModelType.Sellmeijer4Forces; + // Next line sets the CalculationType to Bishop as well + currentSpecification.StabilityModelType = MStabModelType.Bishop; + + // When Writing Xml + Input input = FillXmlInputFromDamUi.CreateInput(expectedDamProjectData); + string xmlString = DamXmlSerialization.SaveInputAsXmlString(input); + + // Then Raise Exception With Clear Message() + input = DamXmlSerialization.LoadInputFromXmlString(xmlString); + DamProjectData actualDamProjectData = FillDamUiFromXmlInput.CreateDamProjectData(input); + CompareDamProjectData(actualDamProjectData, expectedDamProjectData); + } + + [Test] + [TestCase(FailureMechanismSystemType.StabilityInside)] + [TestCase(FailureMechanismSystemType.HorizontalBalance)] + [TestCase(FailureMechanismSystemType.FlowSlide)] + public void DoNotRaiseExceptionWhenRiverLevelLowIsMissingForOtherTypeThanStabilityOutsideOrPiping(FailureMechanismSystemType failureMechanismSystemType) + { + // Given DataSet with undefined RiverLevelLow, for stability inside / horizontal balance / flow slide + DamProjectData expectedDamProjectData = CreateExampleDamProjectData(); + var scenario = expectedDamProjectData.WaterBoard.Dikes[0].Locations[0].Scenarios[0]; + scenario.RiverLevelLow = null; + var currentSpecification = expectedDamProjectData.DamProjectCalculationSpecification.CurrentSpecification; + currentSpecification.FailureMechanismSystemType = failureMechanismSystemType; + // First set PipingModelType to default because it will be set to default when reading the xml back when FailureMechanismSystemType is not Piping + currentSpecification.PipingModelType = PipingModelType.Sellmeijer4Forces; + // Next line sets the CalculationType to Bishop as well + currentSpecification.StabilityModelType = MStabModelType.Bishop; + + // When Writing Xml + Input input = FillXmlInputFromDamUi.CreateInput(expectedDamProjectData); + string xmlString = DamXmlSerialization.SaveInputAsXmlString(input); + + // Then Raise Exception With Clear Message() + input = DamXmlSerialization.LoadInputFromXmlString(xmlString); + DamProjectData actualDamProjectData = FillDamUiFromXmlInput.CreateDamProjectData(input); + CompareDamProjectData(actualDamProjectData, expectedDamProjectData); + } + + [Test] + [TestCase(FailureMechanismSystemType.Piping)] + public void DoNotRaiseExceptionWhenRiverLevelLowIsMissingForPiping(FailureMechanismSystemType failureMechanismSystemType) + { + // Given DataSet with undefined RiverLevelLow, for piping + DamProjectData expectedDamProjectData = CreateExampleDamProjectData(); + var scenario = expectedDamProjectData.WaterBoard.Dikes[0].Locations[0].Scenarios[0]; + scenario.RiverLevelLow = null; + var currentSpecification = expectedDamProjectData.DamProjectCalculationSpecification.CurrentSpecification; + currentSpecification.FailureMechanismSystemType = failureMechanismSystemType; + // First set StabilityModelType to default because it will be set to default when reading the xml back when FailureMechanismSystemType is not Stability + currentSpecification.StabilityModelType = MStabModelType.Bishop; + // Next line sets the CalculationType to Bligh as well + currentSpecification.PipingModelType = PipingModelType.Bligh; + + // When Writing Xml + Input input = FillXmlInputFromDamUi.CreateInput(expectedDamProjectData); + string xmlString = DamXmlSerialization.SaveInputAsXmlString(input); + + // Then Raise Exception With Clear Message() + input = DamXmlSerialization.LoadInputFromXmlString(xmlString); + DamProjectData actualDamProjectData = FillDamUiFromXmlInput.CreateDamProjectData(input); + CompareDamProjectData(actualDamProjectData, expectedDamProjectData); + } } } Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/DamEngineIo/FillXmlInputFromDamUi.cs =================================================================== diff -u -r2578 -r2612 --- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/DamEngineIo/FillXmlInputFromDamUi.cs (.../FillXmlInputFromDamUi.cs) (revision 2578) +++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/DamEngineIo/FillXmlInputFromDamUi.cs (.../FillXmlInputFromDamUi.cs) (revision 2612) @@ -403,6 +403,11 @@ { throw new NullReferenceException("No locations defined in this project"); } + if (damProjectData.DamProjectCalculationSpecification.CurrentSpecification == null) + { + // This situation should never occur in the UI. Tested because of the check on RiverLevelLow in the code below + throw new NullReferenceException("No calculation type specified"); + } foreach (Location location in dike.Locations) { if (location.Scenarios == null) @@ -418,6 +423,16 @@ throw new NullReferenceException(string.Format("Location '{0}', scenario '{1}' has no river level", location.Name, scenario.LocationScenarioID)); } + // In code above is tested that CurrentSpecification exists + if (damProjectData.DamProjectCalculationSpecification.CurrentSpecification.FailureMechanismSystemType == + FailureMechanismSystemType.StabilityOutside) + { + if (scenario.RiverLevelLow == null) + { + throw new NullReferenceException(string.Format("Location '{0}', scenario '{1}' has no river level low", + location.Name, scenario.LocationScenarioID)); + } + } } } }