using System; using System.IO; using Deltares.Dam.Data; using NUnit.Framework; namespace Deltares.Dam.Tests { [TestFixture] public class StabilityServiceFileParserTests { private const string TestFile = @"..\..\..\data\dam\mstabfiles\zuivering Gendt.std"; private const string TestFileWithZonePlot = @"..\..\..\data\dam\mstabfiles\damWithZonePlotEnabled.std"; [TestFixtureSetUp] public void FixtureSetup() { } [Test] [ExpectedException(typeof(ArgumentException))] public void ThrowsExceptionWhenFileHasNoContent() { StabilityServiceFileParser.GetMStabResults(""); } [Test] [ExpectedException(typeof(ArgumentException))] public void ThrowsExceptionWhenFileHasContentIsNull() { StabilityServiceFileParser.GetMStabResults(null); } [Test] [ExpectedException(typeof(ArgumentException))] public void ThrowsExceptionWhenFileContainsOnlySpaces() { StabilityServiceFileParser.GetMStabResults(" "); } [Test] [ExpectedException(typeof(StabilityFileParseException))] public void ThrowIfDumpsHeaderNotFoundInContent() { var contents = " 8.30 " + Environment.NewLine; contents += " [Dumps] " + Environment.NewLine; contents += " test "; contents += "[Data]" + Environment.NewLine; contents += " 1.276 35 18.216 21.971 12.907 Design level"; StabilityServiceFileParser.GetMStabResults(contents); } [Test] [ExpectedException(typeof(StabilityFileParseException))] public void ThrowIfDumpHeaderNotFoundInContent() { var contents = " 8.30 " + Environment.NewLine; contents += " test "; contents += "[Data]" + Environment.NewLine; contents += " 1.276 35 18.216 21.971 12.907 Design level"; StabilityServiceFileParser.GetMStabResults(contents); } [Test] [ExpectedException(typeof(StabilityFileParseException))] public void ThrowIfDataHeaderNotFoundInContent() { var contents = " 8.30 " + Environment.NewLine; contents += "[Dump]" + Environment.NewLine; contents += " test "; contents += "[iets]" + Environment.NewLine; contents += " 1.276 35 18.216 21.971 12.907 Design level"; StabilityServiceFileParser.GetMStabResults(contents); } [Test] [ExpectedException(typeof(StabilityFileParseException))] public void ThrowIfStabilityColumnNotFound() { var contents = @" 28.237 28.850 23.786 2.324 " + Environment.NewLine + @"[End of CircleResults]" + Environment.NewLine + Environment.NewLine + @"[Dumps]" + Environment.NewLine + @" 1 : number of dumps in file" + Environment.NewLine + Environment.NewLine + @"[Dump]" + Environment.NewLine + @"[Dump Header]" + Environment.NewLine + @"[Column Indication]" + Environment.NewLine + //@"Stability factor" + Environment.NewLine + @"Number of slices" + Environment.NewLine + @"X-Centrepoint" + Environment.NewLine + @"Y-Centrepoint" + Environment.NewLine + @"Radius" + Environment.NewLine + @"X coordinate left surface" + Environment.NewLine + @"X coordinate right surface" + Environment.NewLine + @"Dump name" + Environment.NewLine + @"[End of Column Indication]" + Environment.NewLine + @"[Data]" + Environment.NewLine + @" 1.276 35 18.216 21.971 12.907 12.907 17.810 Design level" + Environment.NewLine + @"[End of Data]" + Environment.NewLine + @"[End Of Dump Header]" + Environment.NewLine + @"[SliceGeometry]" + Environment.NewLine + @"[Column Indication]"; StabilityServiceFileParser.GetMStabResults(contents); } [Test] [ExpectedException(typeof(StabilityFileParseException))] public void ThrowIfExitPointXCoordinateColumnNotFound() { var contents = @" 28.237 28.850 23.786 2.324 " + Environment.NewLine + @"[End of CircleResults]" + Environment.NewLine + Environment.NewLine + @"[Dumps]" + Environment.NewLine + @" 1 : number of dumps in file" + Environment.NewLine + Environment.NewLine + @"[Dump]" + Environment.NewLine + @"[Dump Header]" + Environment.NewLine + @"[Column Indication]" + Environment.NewLine + @"Stability factor" + Environment.NewLine + @"Number of slices" + Environment.NewLine + @"X-Centrepoint" + Environment.NewLine + @"Y-Centrepoint" + Environment.NewLine + @"Radius" + Environment.NewLine + // @"X coordinate right surface" + Environment.NewLine + @"Dump name" + Environment.NewLine + @"[End of Column Indication]" + Environment.NewLine + @"[Data]" + Environment.NewLine + @" 1.276 35 18.216 21.971 12.907 17.810 Design level" + Environment.NewLine + @"[End of Data]" + Environment.NewLine + @"[End Of Dump Header]" + Environment.NewLine + @"[SliceGeometry]" + Environment.NewLine + @"[Column Indication]"; StabilityServiceFileParser.GetMStabResults(contents); } [Test] [ExpectedException(typeof(StabilityFileParseException))] public void ThrowIfStabilityColumnCouldntBeParsed() { var contents = @" 28.237 28.850 23.786 2.324 " + Environment.NewLine + @"[End of CircleResults]" + Environment.NewLine + Environment.NewLine + @"[Dumps]" + Environment.NewLine + @" 1 : number of dumps in file" + Environment.NewLine + Environment.NewLine + @"[Dump]" + Environment.NewLine + @"[Dump Header]" + Environment.NewLine + @"[Column Indication]" + Environment.NewLine + @"Stability factor " + @"Number of slices " + @"X-Centrepoint " + @"Y-Centrepoint " + @"Radius " + @"X coordinate left surface" + Environment.NewLine + @"X coordinate right surface" + Environment.NewLine + @"Dump name " + @"[End of Column Indication]" + Environment.NewLine + @"[Data]" + Environment.NewLine + @" 1.276 35 18.216 21.971 12.907 12.907 17.810 Design level" + Environment.NewLine + @"[End of Data]" + Environment.NewLine + @"[End Of Dump Header]" + Environment.NewLine + @"[SliceGeometry]" + Environment.NewLine + @"[Column Indication]"; StabilityServiceFileParser.GetMStabResults(contents); } [Test] [ExpectedException(typeof(StabilityFileParseException))] public void ThrowIfExitPointXCoordinateColumnCouldntBeParsed() { var contents = @" 28.237 28.850 23.786 2.324 " + Environment.NewLine + @"[End of CircleResults]" + Environment.NewLine + Environment.NewLine + @"[Dumps]" + Environment.NewLine + @" 1 : number of dumps in file" + Environment.NewLine + Environment.NewLine + @"[Dump]" + Environment.NewLine + @"[Dump Header]" + Environment.NewLine + @"[Column Indication]" + Environment.NewLine + @"Stability factor " + @"Number of slices " + @"X-Centrepoint " + @"Y-Centrepoint " + @"Radius " + @"X coordinate right surface" + Environment.NewLine + @"Dump name " + @"[End of Column Indication]" + Environment.NewLine + @"[Data]" + Environment.NewLine + @" 1.276 35 18.216 21.971 12.907 17.810 Design level" + Environment.NewLine + @"[End of Data]" + Environment.NewLine + @"[End Of Dump Header]" + Environment.NewLine + @"[SliceGeometry]" + Environment.NewLine + @"[Column Indication]"; StabilityServiceFileParser.GetMStabResults(contents); } [Test] [ExpectedException(typeof(ArgumentException))] public void ThrowIfOuputFileNameEmpty() { StabilityServiceFileParser.GetFileContents(""); } [Test] [ExpectedException(typeof(ArgumentException))] public void ThrowIfOuputFileNameIsNull() { StabilityServiceFileParser.GetFileContents(null); } [Test] [ExpectedException(typeof(ArgumentException))] public void ThrowIfOuputFileNameContainsSpaces() { StabilityServiceFileParser.GetFileContents(""); } [Test] [ExpectedException(typeof(FileNotFoundException))] public void ThrowIfOuputFileNotFound() { StabilityServiceFileParser.GetFileContents("test.std"); } [Test] public void CanParseStringContentWhenSafetyFactorIsInFirstColumn() { var contents = @" 28.237 28.850 23.786 2.324 " + Environment.NewLine + @"[End of CircleResults]" + Environment.NewLine + Environment.NewLine + @"[Dumps]" + Environment.NewLine + @" 1 : number of dumps in file" + Environment.NewLine + Environment.NewLine + @"[Dump]" + Environment.NewLine + @"[Dump Header]" + Environment.NewLine + @"[Column Indication]" + Environment.NewLine + @"Stability factor" + Environment.NewLine + @"Number of slices" + Environment.NewLine + @"X-Centrepoint" + Environment.NewLine + @"Y-Centrepoint" + Environment.NewLine + @"Radius" + Environment.NewLine + @"X coordinate left surface" + Environment.NewLine + @"X coordinate right surface" + Environment.NewLine + @"Dump name" + Environment.NewLine + @"[End of Column Indication]" + Environment.NewLine + @"[Data]" + Environment.NewLine + @" 1.276 35 18.216 21.971 12.907 12.907 17.810 Design level" + Environment.NewLine + @"[End of Data]" + Environment.NewLine + @"[End Of Dump Header]" + Environment.NewLine + @"[SliceGeometry]" + Environment.NewLine + @"[Column Indication]" + @"[MODEL]" + Environment.NewLine + @" 1 : Bishop" + Environment.NewLine; var result = StabilityServiceFileParser.GetMStabResults(contents); Assert.AreEqual(1.276, result.zone1.safetyFactor, 0.001); } [Test] public void CanParseStringContentWhenSafetyFactorIsInOtherColumn() { var contents = @" 28.237 28.850 23.786 2.324 " + Environment.NewLine + @"[End of CircleResults]" + Environment.NewLine + Environment.NewLine + @"[Dumps]" + Environment.NewLine + @" 1 : number of dumps in file" + Environment.NewLine + Environment.NewLine + @"[Dump]" + Environment.NewLine + @"[Dump Header]" + Environment.NewLine + @"[Column Indication]" + Environment.NewLine + @"Number of slices" + Environment.NewLine + @"X-Centrepoint" + Environment.NewLine + @"Y-Centrepoint" + Environment.NewLine + @"Stability factor" + Environment.NewLine + @"Radius" + Environment.NewLine + @"X coordinate left surface" + Environment.NewLine + @"X coordinate right surface" + Environment.NewLine + @"Dump name" + Environment.NewLine + @"[End of Column Indication]" + Environment.NewLine + @"[Data]" + Environment.NewLine + @" 1.276 35 18.216 21.971 12.907 12.907 17.810 Design level" + Environment.NewLine + @"[End of Data]" + Environment.NewLine + @"[End Of Dump Header]" + Environment.NewLine + @"[SliceGeometry]" + Environment.NewLine + @"[Column Indication]" + @"[MODEL]" + Environment.NewLine + @" 1 : Bishop" + Environment.NewLine; var result = StabilityServiceFileParser.GetMStabResults(contents); Assert.AreEqual(21.971, result.zone1.safetyFactor, 0.001); } [Test] public void CanParseFileContentsStability() { var contents = StabilityServiceFileParser.GetFileContents(TestFile); var result = StabilityServiceFileParser.GetMStabResults(contents); Assert.AreEqual(1.276, result.zone1.safetyFactor, 0.001); Assert.AreEqual(26.091, result.zone1.circleSurfacePointRightXCoordinate, 0.001); } [Test] public void ValidateIfFileContentsHasZonePlotEnabled() { var contents = StabilityServiceFileParser.GetFileContents(TestFileWithZonePlot); var result = StabilityServiceFileParser.ParseHasZonePlotEnabled(contents); Assert.IsTrue(result); } [Test] public void FileContentsHasZonePlotZone1a() { var contents = StabilityServiceFileParser.GetFileContents(TestFileWithZonePlot); MStabResultsSingleZone? actualStabilityZone1a = StabilityServiceFileParser.GetZoneStability1a(contents); MStabResultsSingleZone expectedStabilityZone1a = new MStabResultsSingleZone(); expectedStabilityZone1a.safetyFactor = 1.104; expectedStabilityZone1a.circleSurfacePointLeftXCoordinate = 35.401; expectedStabilityZone1a.circleSurfacePointRightXCoordinate = 54.764; Assert.IsNotNull(actualStabilityZone1a); Assert.AreEqual(expectedStabilityZone1a.safetyFactor, actualStabilityZone1a.Value.safetyFactor); Assert.AreEqual(expectedStabilityZone1a.circleSurfacePointRightXCoordinate, actualStabilityZone1a.Value.circleSurfacePointRightXCoordinate); } [Test] public void FileContentsHasZonePlotDisabled() { string zonePlotOff = @"[MODEL]" + Environment.NewLine + @" 1 : Bishop" + Environment.NewLine + @" 1 : C phi" + Environment.NewLine + @" 0 : Probabilistic off" + Environment.NewLine + @" 1 : Mean" + Environment.NewLine + @" 0 : Geotextiles off" + Environment.NewLine + @" 0 : Nails off" + Environment.NewLine + @" 0 : Zone plot on" + Environment.NewLine + @" 0 : Local measurements" + Environment.NewLine + @"[END OF MODEL]" + Environment.NewLine; bool actualZonePlot = StabilityServiceFileParser.ParseHasZonePlotEnabled(zonePlotOff); bool expectedZonePlot = false; Assert.AreEqual(actualZonePlot, expectedZonePlot); } [Test] public void FileContentsHasZonePlotZone1b() { string testWithZonePlot1b = @"[Dump]" + Environment.NewLine + @"[Dump Header]" + Environment.NewLine + @"[Column Indication]" + Environment.NewLine + @"Stability factor" + Environment.NewLine + @"Number of slices" + Environment.NewLine + @"X-Centrepoint" + Environment.NewLine + @"Y-Centrepoint" + Environment.NewLine + @"Radius" + Environment.NewLine + @"X coordinate left surface" + Environment.NewLine + @"X coordinate right surface" + Environment.NewLine + @"Zone number" + Environment.NewLine + @"Dump name" + Environment.NewLine + @"[End of Column Indication]" + Environment.NewLine + @"[Data]" + Environment.NewLine + @" 1.234 35 46.429 7.714 11.357 17.810 24.310 2 Design level" + Environment.NewLine + @"[End of Data]" + Environment.NewLine + @"[End Of Dump Header]" + Environment.NewLine + @"[MODEL]" + Environment.NewLine + @" 1 : Bishop" + Environment.NewLine; MStabResultsSingleZone? actualStabilityZone1b = StabilityServiceFileParser.GetZoneStability1b(testWithZonePlot1b); MStabResultsSingleZone expectedStabilityZone1b = new MStabResultsSingleZone(); expectedStabilityZone1b.safetyFactor = 1.234; expectedStabilityZone1b.circleSurfacePointLeftXCoordinate = 17.810; expectedStabilityZone1b.circleSurfacePointRightXCoordinate = 24.310; Assert.IsNotNull(actualStabilityZone1b); Assert.AreEqual(expectedStabilityZone1b.safetyFactor, actualStabilityZone1b.Value.safetyFactor); Assert.AreEqual(expectedStabilityZone1b.circleSurfacePointRightXCoordinate, actualStabilityZone1b.Value.circleSurfacePointRightXCoordinate); } [Test] public void FileContentsHasNoZonePlotZone1b() { var contents = StabilityServiceFileParser.GetFileContents(TestFileWithZonePlot); MStabResultsSingleZone? actualStabilityZone1b = StabilityServiceFileParser.GetZoneStability1b(TestFileWithZonePlot); MStabResultsSingleZone? expectedStabilityZone1b = null; Assert.AreEqual(actualStabilityZone1b, expectedStabilityZone1b); } [Test] public void FileContentsHasZonePlotZone1bAndZone2b() { string testWithZonePlot1bAnd2b = @"[MODEL]" + Environment.NewLine + @" 1 : Bishop" + Environment.NewLine + @" 1 : C phi" + Environment.NewLine + @" 0 : Probabilistic off" + Environment.NewLine + @" 1 : Mean" + Environment.NewLine + @" 0 : Geotextiles off" + Environment.NewLine + @" 0 : Nails off" + Environment.NewLine + @" 1 : Zone plot on" + Environment.NewLine + @" 0 : Local measurements" + Environment.NewLine + @"[END OF MODEL]" + Environment.NewLine + @"[Dump]" + Environment.NewLine + @"[Dump Header]" + Environment.NewLine + @"[Column Indication]" + Environment.NewLine + @"Stability factor" + Environment.NewLine + @"Number of slices" + Environment.NewLine + @"X-Centrepoint" + Environment.NewLine + @"Y-Centrepoint" + Environment.NewLine + @"Radius" + Environment.NewLine + @"X coordinate left surface" + Environment.NewLine + @"X coordinate right surface" + Environment.NewLine + @"Zone number" + Environment.NewLine + @"Dump name" + Environment.NewLine + @"[End of Column Indication]" + Environment.NewLine + @"[Data]" + Environment.NewLine + @" 1.234 35 46.429 7.714 11.357 17.810 24.310 2 Design level" + Environment.NewLine + @"[End of Data]" + Environment.NewLine + @"[End Of Dump Header]" + Environment.NewLine + @"[Dump]" + Environment.NewLine + @"[Dump Header]" + Environment.NewLine + @"[Column Indication]" + Environment.NewLine + @"Stability factor" + Environment.NewLine + @"Number of slices" + Environment.NewLine + @"X-Centrepoint" + Environment.NewLine + @"Y-Centrepoint" + Environment.NewLine + @"Radius" + Environment.NewLine + @"X coordinate left surface" + Environment.NewLine + @"X coordinate right surface" + Environment.NewLine + @"Zone number" + Environment.NewLine + @"Dump name" + Environment.NewLine + @"[End of Column Indication]" + Environment.NewLine + @"[Data]" + Environment.NewLine + @" 1.345 35 46.429 7.714 11.357 19.810 26.310 4 Design level" + Environment.NewLine + @"[End of Data]" + Environment.NewLine + @"[End Of Dump Header]" + Environment.NewLine; MStabResults actualMStabResults = StabilityServiceFileParser.GetMStabResults(testWithZonePlot1bAnd2b); MStabResultsSingleZone expectedStabilityZone1 = new MStabResultsSingleZone(); MStabResultsSingleZone expectedStabilityZone2 = new MStabResultsSingleZone(); expectedStabilityZone1.safetyFactor = 1.234; expectedStabilityZone1.circleSurfacePointLeftXCoordinate = 17.810; expectedStabilityZone1.circleSurfacePointRightXCoordinate = 24.310; expectedStabilityZone2.safetyFactor = 1.345; expectedStabilityZone2.circleSurfacePointLeftXCoordinate = 19.810; expectedStabilityZone2.circleSurfacePointRightXCoordinate = 26.310; Assert.IsNotNull(actualMStabResults); Assert.AreEqual(expectedStabilityZone1.safetyFactor, actualMStabResults.zone1.safetyFactor); Assert.AreEqual(expectedStabilityZone1.circleSurfacePointRightXCoordinate, actualMStabResults.zone1.circleSurfacePointRightXCoordinate); Assert.IsNotNull(actualMStabResults.zone2); Assert.AreEqual(expectedStabilityZone2.safetyFactor, actualMStabResults.zone2.Value.safetyFactor); Assert.AreEqual(expectedStabilityZone2.circleSurfacePointRightXCoordinate, actualMStabResults.zone2.Value.circleSurfacePointRightXCoordinate); } [Test] public void CanParseFileHasStabilityFactorZone() { var contents = StabilityServiceFileParser.GetFileContents(TestFileWithZonePlot); var result = StabilityServiceFileParser.GetMStabResults(contents); Assert.AreEqual(1.104, result.zone1.safetyFactor, 0.001); } [Test] [ExpectedException(typeof(StabilityFileParseException))] public void ThrowIfBetaColumnNotFound() { var contents = @" 28.237 28.850 23.786 2.324 " + Environment.NewLine + @"[End of CircleResults]" + Environment.NewLine + Environment.NewLine + @"[Dumps]" + Environment.NewLine + @" 1 : number of dumps in file" + Environment.NewLine + Environment.NewLine + @"[Dump]" + Environment.NewLine + @"[Dump Header]" + Environment.NewLine + @"[Column Indication]" + Environment.NewLine + @"Stability factor" + Environment.NewLine + @"Number of slices" + Environment.NewLine + @"X-Centrepoint" + Environment.NewLine + @"Y-Centrepoint" + Environment.NewLine + @"Radius" + Environment.NewLine + @"X coordinate right surface" + Environment.NewLine + @"Dump name" + Environment.NewLine + @"[End of Column Indication]" + Environment.NewLine + @"[Data]" + Environment.NewLine + @" 1.276 35 18.216 21.971 12.907 17.810 Design level" + Environment.NewLine + @"[End of Data]" + Environment.NewLine + @"[End Of Dump Header]" + Environment.NewLine + @"[SliceGeometry]" + Environment.NewLine + @"[Column Indication]"; StabilityServiceFileParser.GetBeta(contents); } [Test] public void CanParseStringContentForPositiveBeta() { var contents = @" 28.237 28.850 23.786 2.324 " + Environment.NewLine + @"[End of CircleResults]" + Environment.NewLine + Environment.NewLine + @"[Dumps]" + Environment.NewLine + @" 1 : number of dumps in file" + Environment.NewLine + Environment.NewLine + @"[Dump]" + Environment.NewLine + @"[Dump Header]" + Environment.NewLine + @"[Column Indication]" + Environment.NewLine + @"Number of slices" + Environment.NewLine + @"X-Centrepoint" + Environment.NewLine + @"Y-Centrepoint" + Environment.NewLine + @"Stability factor" + Environment.NewLine + @"Radius" + Environment.NewLine + @"X coordinate right surface" + Environment.NewLine + @"Beta" + Environment.NewLine + @"Dump name" + Environment.NewLine + @"[End of Column Indication]" + Environment.NewLine + @"[Data]" + Environment.NewLine + @" 1.276 35 18.216 21.971 12.907 17.810 1.1 Design level" + Environment.NewLine + @"[End of Data]" + Environment.NewLine + @"[End Of Dump Header]" + Environment.NewLine + @"[SliceGeometry]" + Environment.NewLine + @"[Column Indication]"; var beta = StabilityServiceFileParser.GetBeta(contents); Assert.AreEqual(1.1, beta, 0.001); } [Test] public void CanParseStringContentForNegativeBeta() { var contents = @" 28.237 28.850 23.786 2.324 " + Environment.NewLine + @"[End of CircleResults]" + Environment.NewLine + Environment.NewLine + @"[Dumps]" + Environment.NewLine + @" 1 : number of dumps in file" + Environment.NewLine + Environment.NewLine + @"[Dump]" + Environment.NewLine + @"[Dump Header]" + Environment.NewLine + @"[Column Indication]" + Environment.NewLine + @"Number of slices" + Environment.NewLine + @"X-Centrepoint" + Environment.NewLine + @"Y-Centrepoint" + Environment.NewLine + @"Stability factor" + Environment.NewLine + @"Radius" + Environment.NewLine + @"X coordinate right surface" + Environment.NewLine + @"Beta" + Environment.NewLine + @"Dump name" + Environment.NewLine + @"[End of Column Indication]" + Environment.NewLine + @"[Data]" + Environment.NewLine + @" 1.276 35 18.216 21.971 12.907 17.810 -1.1 Design level" + Environment.NewLine + @"[End of Data]" + Environment.NewLine + @"[End Of Dump Header]" + Environment.NewLine + @"[SliceGeometry]" + Environment.NewLine + @"[Column Indication]"; var beta = StabilityServiceFileParser.GetBeta(contents); Assert.AreEqual(-1.1, beta, 0.001); } [TestFixtureTearDown] public void FixtureTearDown() { } } }