Index: src/Plugins/Wti/Wti.IO/Exceptions/LineParseException.cs
===================================================================
diff -u
--- src/Plugins/Wti/Wti.IO/Exceptions/LineParseException.cs (revision 0)
+++ src/Plugins/Wti/Wti.IO/Exceptions/LineParseException.cs (revision 91ec76d4b8a0fcf5962f442021c43f1ffa70743e)
@@ -0,0 +1,33 @@
+using System;
+
+namespace Wti.IO.Exceptions
+{
+ ///
+ /// The exception that is thrown when a file reader class encounters an error while
+ /// parsing a row/line during the read.
+ ///
+ public class LineParseException : Exception
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public LineParseException() { }
+
+ ///
+ /// Initializes a new instance of the class
+ /// with a specified error message.
+ ///
+ /// The error message that explains the reason for the exception.
+ public LineParseException(string message) : base(message) { }
+
+ ///
+ /// Initializes a new instance of the class
+ /// with a specified error message and a reference to the inner exception that is
+ /// the cause of this exception.
+ ///
+ /// The error message that explains the reason for the exception.
+ /// The exception that is the cause of the current exception,
+ /// or a null reference (Nothing in Visual Basic) if no inner exception is specified.
+ public LineParseException(string message, Exception inner) : base(message, inner) { }
+ }
+}
\ No newline at end of file
Index: src/Plugins/Wti/Wti.IO/PipingSurfaceLinesCsvReader.cs
===================================================================
diff -u -ra24255dee45ce3bbeb2f140903969a2cd9f1fa67 -r91ec76d4b8a0fcf5962f442021c43f1ffa70743e
--- src/Plugins/Wti/Wti.IO/PipingSurfaceLinesCsvReader.cs (.../PipingSurfaceLinesCsvReader.cs) (revision a24255dee45ce3bbeb2f140903969a2cd9f1fa67)
+++ src/Plugins/Wti/Wti.IO/PipingSurfaceLinesCsvReader.cs (.../PipingSurfaceLinesCsvReader.cs) (revision 91ec76d4b8a0fcf5962f442021c43f1ffa70743e)
@@ -92,8 +92,12 @@
/// File incompatible for importing surface lines.
///
///
- /// A coordinate value does not represent a number in a valid format or the line is incorrectly formatted.
- /// A coordinate value represents a number that is less than or greater than .
+ /// A parse error has occurred for the current row, which may be caused by:
+ ///
+ /// The row contains a coordinate value that cannot be parsed as a double.
+ /// The row contains a number that is too big or too small to be represented with a double.
+ ///
+ ///
public PipingSurfaceLine ReadLine()
{
if (fileReader == null)
@@ -104,13 +108,13 @@
lineNumber = 2;
}
- var readText = ReadLineAndHandleIOExceptions(fileReader, lineNumber);
+ var readText = ReadLineAndHandleIOExceptions(fileReader);
if (readText != null)
{
var tokenizedString = readText.Split(separator);
- var worldCoordinateValues = tokenizedString.Skip(1)
- .Select(ts => Double.Parse(ts, CultureInfo.InvariantCulture))
- .ToArray();
+ var worldCoordinateValues = ParseWorldCoordinateValuesAndHandleParseErrors(tokenizedString);
+
+ // TODO: Format Error: missing values to complete coordinate triplet
int coordinateCount = worldCoordinateValues.Length / 3;
var points = new Point3D[coordinateCount];
for (int i = 0; i < coordinateCount; i++)
@@ -127,6 +131,7 @@
var surfaceLine = new PipingSurfaceLine
{
+ // TODO: Format Error: Row identifier null, empty or whitespace
Name = tokenizedString.First()
};
surfaceLine.SetGeometry(points);
@@ -136,6 +141,39 @@
return null;
}
+ ///
+ /// Parses the world coordinate values and handles parse errors.
+ ///
+ /// The tokenized string.
+ ///
+ /// A parse error has occurred for the current row, which may be caused by:
+ ///
+ /// The row contains a coordinate value that cannot be parsed as a double.
+ /// The row contains a number that is too big or too small to be represented with a double.
+ ///
+ ///
+ private double[] ParseWorldCoordinateValuesAndHandleParseErrors(string[] tokenizedString)
+ {
+ try
+ {
+ return tokenizedString.Skip(1)
+ .Select(ts => Double.Parse(ts, CultureInfo.InvariantCulture))
+ .ToArray();
+ }
+ catch (FormatException e)
+ {
+ var message = string.Format(Resources.Error_File_0_has_not_double_Line_1_,
+ filePath, lineNumber);
+ throw new LineParseException(message, e);
+ }
+ catch (OverflowException e)
+ {
+ var message = string.Format(Resources.Error_File_0_Parsing_causes_overflow_Line_1_,
+ filePath, lineNumber);
+ throw new LineParseException(message, e);
+ }
+ }
+
public void Dispose()
{
if (fileReader != null)
@@ -182,7 +220,7 @@
/// The header is not in the required format.
private void ValidateHeader(TextReader reader)
{
- var header = ReadLineAndHandleIOExceptions(reader, 1);
+ var header = ReadLineAndHandleIOExceptions(reader);
if (header != null)
{
if (!IsHeaderValid(header))
@@ -209,7 +247,7 @@
{
var count = 0;
string line;
- while ((line = ReadLineAndHandleIOExceptions(reader, currentLine)) != null)
+ while ((line = ReadLineAndHandleIOExceptions(reader)) != null)
{
if (!String.IsNullOrWhiteSpace(line))
{
@@ -227,15 +265,15 @@
/// Row number for error messaging.
/// The read line, or null when at the end of the file.
/// An critical I/O exception occurred.
- private string ReadLineAndHandleIOExceptions(TextReader reader, int currentLine)
+ private string ReadLineAndHandleIOExceptions(TextReader reader)
{
try
{
return reader.ReadLine();
}
catch (OutOfMemoryException e)
{
- var message = string.Format(Resources.Error_File_0_contains_Line_1_too_big, filePath, currentLine);
+ var message = string.Format(Resources.Error_File_0_contains_Line_1_too_big, filePath, lineNumber);
throw new CriticalFileReadException(message, e);
}
catch (IOException e)
Index: src/Plugins/Wti/Wti.IO/Properties/Resources.Designer.cs
===================================================================
diff -u -r356ac6ef31864aa207c8af9470df3349f8e4d1f1 -r91ec76d4b8a0fcf5962f442021c43f1ffa70743e
--- src/Plugins/Wti/Wti.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 356ac6ef31864aa207c8af9470df3349f8e4d1f1)
+++ src/Plugins/Wti/Wti.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 91ec76d4b8a0fcf5962f442021c43f1ffa70743e)
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
//
// This code was generated by a tool.
-// Runtime Version:4.0.30319.34209
+// Runtime Version:4.0.30319.18444
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@@ -97,6 +97,24 @@
}
///
+ /// Looks up a localized string similar to Het bestand '{0}' heeft op regel {1} een waarde dat geen getal is..
+ ///
+ public static string Error_File_0_has_not_double_Line_1_ {
+ get {
+ return ResourceManager.GetString("Error_File_0_has_not_double_Line_1_", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Het bestand '{0}' heeft op regel {1} een waarde dat te groot/klein is om ingelezen te worden..
+ ///
+ public static string Error_File_0_Parsing_causes_overflow_Line_1_ {
+ get {
+ return ResourceManager.GetString("Error_File_0_Parsing_causes_overflow_Line_1_", resourceCulture);
+ }
+ }
+
+ ///
/// Looks up a localized string similar to Er is een onverwachte inleesfout opgetreden tijdens het lezen van het bestand '{0}': {1}.
///
public static string Error_General_IO_File_0_ErrorMessage_1_ {
Index: src/Plugins/Wti/Wti.IO/Properties/Resources.resx
===================================================================
diff -u -r356ac6ef31864aa207c8af9470df3349f8e4d1f1 -r91ec76d4b8a0fcf5962f442021c43f1ffa70743e
--- src/Plugins/Wti/Wti.IO/Properties/Resources.resx (.../Resources.resx) (revision 356ac6ef31864aa207c8af9470df3349f8e4d1f1)
+++ src/Plugins/Wti/Wti.IO/Properties/Resources.resx (.../Resources.resx) (revision 91ec76d4b8a0fcf5962f442021c43f1ffa70743e)
@@ -150,4 +150,10 @@
Kon geen ondergrond profielen verkrijgen van de database '{0}'.
+
+ Het bestand '{0}' heeft op regel {1} een waarde dat geen getal is.
+
+
+ Het bestand '{0}' heeft op regel {1} een waarde dat te groot/klein is om ingelezen te worden.
+
\ No newline at end of file
Index: src/Plugins/Wti/Wti.IO/Wti.IO.csproj
===================================================================
diff -u -r356ac6ef31864aa207c8af9470df3349f8e4d1f1 -r91ec76d4b8a0fcf5962f442021c43f1ffa70743e
--- src/Plugins/Wti/Wti.IO/Wti.IO.csproj (.../Wti.IO.csproj) (revision 356ac6ef31864aa207c8af9470df3349f8e4d1f1)
+++ src/Plugins/Wti/Wti.IO/Wti.IO.csproj (.../Wti.IO.csproj) (revision 91ec76d4b8a0fcf5962f442021c43f1ffa70743e)
@@ -51,6 +51,7 @@
Properties\GlobalAssembly.cs
+
Index: src/Plugins/Wti/Wti.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs
===================================================================
diff -u -ra24255dee45ce3bbeb2f140903969a2cd9f1fa67 -r91ec76d4b8a0fcf5962f442021c43f1ffa70743e
--- src/Plugins/Wti/Wti.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs (.../PipingSurfaceLinesCsvImporter.cs) (revision a24255dee45ce3bbeb2f140903969a2cd9f1fa67)
+++ src/Plugins/Wti/Wti.Plugin/FileImporter/PipingSurfaceLinesCsvImporter.cs (.../PipingSurfaceLinesCsvImporter.cs) (revision 91ec76d4b8a0fcf5962f442021c43f1ffa70743e)
@@ -158,12 +158,18 @@
try
{
readSurfaceLines.Add(reader.ReadLine());
- NotifyProgress(stepName, i + 1, itemCount);
}
catch (CriticalFileReadException e)
{
return HandleCriticalError(path, e);
}
+ catch (LineParseException e)
+ {
+ var message = string.Format(ApplicationResources.PipingSurfaceLinesCsvImporter_ReadPipingSurfaceLines_ParseError_File_0_SurfaceLinesNumber_1_Message_2_,
+ path, i+1, e.Message);
+ log.Error(message);
+ }
+ NotifyProgress(stepName, i + 1, itemCount);
}
return new SurfaceLinesFileReadResult(false)
Index: src/Plugins/Wti/Wti.Plugin/Properties/Resources.Designer.cs
===================================================================
diff -u -r8fe3ae6f129251f98795abd491315924ca707a76 -r91ec76d4b8a0fcf5962f442021c43f1ffa70743e
--- src/Plugins/Wti/Wti.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 8fe3ae6f129251f98795abd491315924ca707a76)
+++ src/Plugins/Wti/Wti.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 91ec76d4b8a0fcf5962f442021c43f1ffa70743e)
@@ -106,6 +106,16 @@
}
///
+ /// Looks up a localized string similar to Er is een leesfout opgetreden bij dwarsdoorsnede {1} van bestand '{0}' en is overgeslagen: {2}.
+ ///
+ public static string PipingSurfaceLinesCsvImporter_ReadPipingSurfaceLines_ParseError_File_0_SurfaceLinesNumber_1_Message_2_ {
+ get {
+ return ResourceManager.GetString("PipingSurfaceLinesCsvImporter_ReadPipingSurfaceLines_ParseError_File_0_SurfaceLin" +
+ "esNumber_1_Message_2_", resourceCulture);
+ }
+ }
+
+ ///
/// Looks up a localized string similar to DSoilModel bestand.
///
public static string SoilFileName {
Index: src/Plugins/Wti/Wti.Plugin/Properties/Resources.resx
===================================================================
diff -u -r8fe3ae6f129251f98795abd491315924ca707a76 -r91ec76d4b8a0fcf5962f442021c43f1ffa70743e
--- src/Plugins/Wti/Wti.Plugin/Properties/Resources.resx (.../Resources.resx) (revision 8fe3ae6f129251f98795abd491315924ca707a76)
+++ src/Plugins/Wti/Wti.Plugin/Properties/Resources.resx (.../Resources.resx) (revision 91ec76d4b8a0fcf5962f442021c43f1ffa70743e)
@@ -153,4 +153,7 @@
Er is een fout opgetreden tijdens het inlezen van '{0}' waardoor import niet uitgevoerd kan worden: {1}
+
+ Er is een leesfout opgetreden bij dwarsdoorsnede {1} van bestand '{0}' en is overgeslagen: {2}
+
\ No newline at end of file
Index: test-data/Plugins/Wti/IO/PipingSurfaceLinesCsvReader/InvalidRow_XNotAValidNumber.csv
===================================================================
diff -u
--- test-data/Plugins/Wti/IO/PipingSurfaceLinesCsvReader/InvalidRow_XNotAValidNumber.csv (revision 0)
+++ test-data/Plugins/Wti/IO/PipingSurfaceLinesCsvReader/InvalidRow_XNotAValidNumber.csv (revision 91ec76d4b8a0fcf5962f442021c43f1ffa70743e)
@@ -0,0 +1,2 @@
+Profielnaam;X1;Y1;Z1;...;Xn;Yn;Zn
+InvalidSurfaceLine;This is not a number;2.2;3.3;4.4;5.5;6.6
\ No newline at end of file
Index: test-data/Plugins/Wti/IO/PipingSurfaceLinesCsvReader/InvalidRow_XOverflowingNumber.csv
===================================================================
diff -u
--- test-data/Plugins/Wti/IO/PipingSurfaceLinesCsvReader/InvalidRow_XOverflowingNumber.csv (revision 0)
+++ test-data/Plugins/Wti/IO/PipingSurfaceLinesCsvReader/InvalidRow_XOverflowingNumber.csv (revision 91ec76d4b8a0fcf5962f442021c43f1ffa70743e)
@@ -0,0 +1,2 @@
+Profielnaam;X1;Y1;Z1;...;Xn;Yn;Zn
+InvalidSurfaceLine;999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999;2.2;3.3;4.4;5.5;6.6
\ No newline at end of file
Index: test-data/Plugins/Wti/IO/PipingSurfaceLinesCsvReader/InvalidRow_XUnderflowingNumber.csv
===================================================================
diff -u
--- test-data/Plugins/Wti/IO/PipingSurfaceLinesCsvReader/InvalidRow_XUnderflowingNumber.csv (revision 0)
+++ test-data/Plugins/Wti/IO/PipingSurfaceLinesCsvReader/InvalidRow_XUnderflowingNumber.csv (revision 91ec76d4b8a0fcf5962f442021c43f1ffa70743e)
@@ -0,0 +1,2 @@
+Profielnaam;X1;Y1;Z1;...;Xn;Yn;Zn
+InvalidSurfaceLine;1.1;2.2;3.3;-999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999;5.5;6.6
\ No newline at end of file
Index: test-data/Plugins/Wti/IO/PipingSurfaceLinesCsvReader/InvalidRow_YNotAValidNumber.csv
===================================================================
diff -u
--- test-data/Plugins/Wti/IO/PipingSurfaceLinesCsvReader/InvalidRow_YNotAValidNumber.csv (revision 0)
+++ test-data/Plugins/Wti/IO/PipingSurfaceLinesCsvReader/InvalidRow_YNotAValidNumber.csv (revision 91ec76d4b8a0fcf5962f442021c43f1ffa70743e)
@@ -0,0 +1,2 @@
+Profielnaam;X1;Y1;Z1;...;Xn;Yn;Zn
+InvalidSurfaceLine;1.1;definitely not a number;3.3;4.4;5.5;6.6
\ No newline at end of file
Index: test-data/Plugins/Wti/IO/PipingSurfaceLinesCsvReader/InvalidRow_YOverflowingNumber.csv
===================================================================
diff -u
--- test-data/Plugins/Wti/IO/PipingSurfaceLinesCsvReader/InvalidRow_YOverflowingNumber.csv (revision 0)
+++ test-data/Plugins/Wti/IO/PipingSurfaceLinesCsvReader/InvalidRow_YOverflowingNumber.csv (revision 91ec76d4b8a0fcf5962f442021c43f1ffa70743e)
@@ -0,0 +1,2 @@
+Profielnaam;X1;Y1;Z1;...;Xn;Yn;Zn
+InvalidSurfaceLine;1.1;2.2;3.3;4.4;999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999;6.6
\ No newline at end of file
Index: test-data/Plugins/Wti/IO/PipingSurfaceLinesCsvReader/InvalidRow_YUnderflowingNumber.csv
===================================================================
diff -u
--- test-data/Plugins/Wti/IO/PipingSurfaceLinesCsvReader/InvalidRow_YUnderflowingNumber.csv (revision 0)
+++ test-data/Plugins/Wti/IO/PipingSurfaceLinesCsvReader/InvalidRow_YUnderflowingNumber.csv (revision 91ec76d4b8a0fcf5962f442021c43f1ffa70743e)
@@ -0,0 +1,2 @@
+Profielnaam;X1;Y1;Z1;...;Xn;Yn;Zn
+InvalidSurfaceLine;1.1;-999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999;3.3;4.4;5.5;6.6
\ No newline at end of file
Index: test-data/Plugins/Wti/IO/PipingSurfaceLinesCsvReader/InvalidRow_ZNotAValidNumber.csv
===================================================================
diff -u
--- test-data/Plugins/Wti/IO/PipingSurfaceLinesCsvReader/InvalidRow_ZNotAValidNumber.csv (revision 0)
+++ test-data/Plugins/Wti/IO/PipingSurfaceLinesCsvReader/InvalidRow_ZNotAValidNumber.csv (revision 91ec76d4b8a0fcf5962f442021c43f1ffa70743e)
@@ -0,0 +1,2 @@
+Profielnaam;X1;Y1;Z1;...;Xn;Yn;Zn
+InvalidSurfaceLine;1.1;2.2;three point three;4.4;5.5;6.6
\ No newline at end of file
Index: test-data/Plugins/Wti/IO/PipingSurfaceLinesCsvReader/InvalidRow_ZOverflowingNumber.csv
===================================================================
diff -u
--- test-data/Plugins/Wti/IO/PipingSurfaceLinesCsvReader/InvalidRow_ZOverflowingNumber.csv (revision 0)
+++ test-data/Plugins/Wti/IO/PipingSurfaceLinesCsvReader/InvalidRow_ZOverflowingNumber.csv (revision 91ec76d4b8a0fcf5962f442021c43f1ffa70743e)
@@ -0,0 +1,2 @@
+Profielnaam;X1;Y1;Z1;...;Xn;Yn;Zn
+InvalidSurfaceLine;1.1;2.2;3.3;4.4;5.5;999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
\ No newline at end of file
Index: test-data/Plugins/Wti/IO/PipingSurfaceLinesCsvReader/InvalidRow_ZUnderflowingNumber.csv
===================================================================
diff -u
--- test-data/Plugins/Wti/IO/PipingSurfaceLinesCsvReader/InvalidRow_ZUnderflowingNumber.csv (revision 0)
+++ test-data/Plugins/Wti/IO/PipingSurfaceLinesCsvReader/InvalidRow_ZUnderflowingNumber.csv (revision 91ec76d4b8a0fcf5962f442021c43f1ffa70743e)
@@ -0,0 +1,2 @@
+Profielnaam;X1;Y1;Z1;...;Xn;Yn;Zn
+InvalidSurfaceLine;1.1;2.2;-999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999;4.4;5.5;6.6
\ No newline at end of file
Index: test-data/Plugins/Wti/IO/PipingSurfaceLinesCsvReader/TwoValidAndOneInvalidNumberRowSurfaceLines.csv
===================================================================
diff -u
--- test-data/Plugins/Wti/IO/PipingSurfaceLinesCsvReader/TwoValidAndOneInvalidNumberRowSurfaceLines.csv (revision 0)
+++ test-data/Plugins/Wti/IO/PipingSurfaceLinesCsvReader/TwoValidAndOneInvalidNumberRowSurfaceLines.csv (revision 91ec76d4b8a0fcf5962f442021c43f1ffa70743e)
@@ -0,0 +1,4 @@
+Profielnaam;X1;Y1;Z1;...;Xn;Yn;Zn
+Rotterdam1;94263.0026213;427776.654093;-1.02;94275.9126686;427811.080886;-1.04;94284.0663827;427831.918156;1.25;94294.9380015;427858.191234;1.45;94305.3566362;427889.900123;1.65;94315.0957947;427913.908281;1.66;94325.0614453;427941.766804;1.55;94331.1767309;427960.112661;1.44
+InvalidRow;1.1;Really not a number;3.3;4.4;5.5;6.6
+ArtificalLocal;2.3;0;1.0;5.7;0;2.0;4.4;0;1.1
\ No newline at end of file
Index: test/Plugins/Wti/Wti.IO.Test/Exceptions/LineParseExceptionTest.cs
===================================================================
diff -u
--- test/Plugins/Wti/Wti.IO.Test/Exceptions/LineParseExceptionTest.cs (revision 0)
+++ test/Plugins/Wti/Wti.IO.Test/Exceptions/LineParseExceptionTest.cs (revision 91ec76d4b8a0fcf5962f442021c43f1ffa70743e)
@@ -0,0 +1,72 @@
+using System;
+
+using NUnit.Framework;
+
+using Wti.IO.Exceptions;
+
+namespace Wti.IO.Test.Exceptions
+{
+ [TestFixture]
+ public class LineParseExceptionTest
+ {
+ [Test]
+ [SetCulture("en-US")]
+ public void DefaultConstructor_ExpectedValues()
+ {
+ // Call
+ var exception = new LineParseException();
+
+ // Assert
+ Assert.IsInstanceOf(exception);
+ var expectedMessage = string.Format("Exception of type '{0}' was thrown.", exception.GetType());
+ Assert.AreEqual(expectedMessage, exception.Message);
+ CollectionAssert.IsEmpty(exception.Data);
+ Assert.IsNull(exception.HelpLink);
+ Assert.IsNull(exception.InnerException);
+ Assert.IsNull(exception.Source);
+ Assert.IsNull(exception.StackTrace);
+ Assert.IsNull(exception.TargetSite);
+ }
+
+ [Test]
+ public void MessageConstructor_ExpectedValues()
+ {
+ // Setup
+ const string messageText = "";
+
+ // Call
+ var exception = new LineParseException(messageText);
+
+ // Assert
+ Assert.IsInstanceOf(exception);
+ Assert.AreEqual(messageText, exception.Message);
+ CollectionAssert.IsEmpty(exception.Data);
+ Assert.IsNull(exception.HelpLink);
+ Assert.IsNull(exception.InnerException);
+ Assert.IsNull(exception.Source);
+ Assert.IsNull(exception.StackTrace);
+ Assert.IsNull(exception.TargetSite);
+ }
+
+ [Test]
+ public void MessageAndInnerExceptionConstructor_ExpectedValues()
+ {
+ // Setup
+ var innerException = new Exception();
+ const string messageText = "";
+
+ // Call
+ var exception = new LineParseException(messageText, innerException);
+
+ // Assert
+ Assert.IsInstanceOf(exception);
+ Assert.AreEqual(messageText, exception.Message);
+ CollectionAssert.IsEmpty(exception.Data);
+ Assert.IsNull(exception.HelpLink);
+ Assert.AreEqual(innerException, exception.InnerException);
+ Assert.IsNull(exception.Source);
+ Assert.IsNull(exception.StackTrace);
+ Assert.IsNull(exception.TargetSite);
+ }
+ }
+}
\ No newline at end of file
Index: test/Plugins/Wti/Wti.IO.Test/PipingSurfaceLinesCsvReaderTest.cs
===================================================================
diff -u -ra24255dee45ce3bbeb2f140903969a2cd9f1fa67 -r91ec76d4b8a0fcf5962f442021c43f1ffa70743e
--- test/Plugins/Wti/Wti.IO.Test/PipingSurfaceLinesCsvReaderTest.cs (.../PipingSurfaceLinesCsvReaderTest.cs) (revision a24255dee45ce3bbeb2f140903969a2cd9f1fa67)
+++ test/Plugins/Wti/Wti.IO.Test/PipingSurfaceLinesCsvReaderTest.cs (.../PipingSurfaceLinesCsvReaderTest.cs) (revision 91ec76d4b8a0fcf5962f442021c43f1ffa70743e)
@@ -369,6 +369,59 @@
}
}
+ [Test]
+ [TestCase("X")]
+ [TestCase("Y")]
+ [TestCase("Z")]
+ public void ReadLine_FileHasInvalidCoordinate_ThrowLineParseException(string malformattedVariableName)
+ {
+ // Setup
+ string path = Path.Combine(testDataPath, string.Format("InvalidRow_{0}NotAValidNumber.csv", malformattedVariableName));
+
+ // Precondition
+ Assert.IsTrue(File.Exists(path));
+
+ using (var reader = new PipingSurfaceLinesCsvReader(path))
+ {
+ // Call
+ TestDelegate call = () => reader.ReadLine();
+
+ // Assert
+ var exception = Assert.Throws(call);
+ var expectedMessage = string.Format(IOResources.Error_File_0_has_not_double_Line_1_, path, 2);
+ Assert.AreEqual(expectedMessage, exception.Message);
+ Assert.IsInstanceOf(exception.InnerException);
+ }
+ }
+
+ [Test]
+ [TestCase("XOver")]
+ [TestCase("YOver")]
+ [TestCase("ZOver")]
+ [TestCase("XUnder")]
+ [TestCase("YUnder")]
+ [TestCase("ZUnder")]
+ public void ReadLine_FileHasCoordinateCausingOverOrUnderflow_ThrowLineParseException(string malformattedVariableName)
+ {
+ // Setup
+ string path = Path.Combine(testDataPath, string.Format("InvalidRow_{0}flowingNumber.csv", malformattedVariableName));
+
+ // Precondition
+ Assert.IsTrue(File.Exists(path));
+
+ using (var reader = new PipingSurfaceLinesCsvReader(path))
+ {
+ // Call
+ TestDelegate call = () => reader.ReadLine();
+
+ // Assert
+ var exception = Assert.Throws(call);
+ var expectedMessage = string.Format(IOResources.Error_File_0_Parsing_causes_overflow_Line_1_, path, 2);
+ Assert.AreEqual(expectedMessage, exception.Message);
+ Assert.IsInstanceOf(exception.InnerException);
+ }
+ }
+
private void DoReadLine_OpenedValidFileWithHeaderAndTwoSurfaceLines_ReturnCreatedSurfaceLine()
{
// Setup
Index: test/Plugins/Wti/Wti.IO.Test/Wti.IO.Test.csproj
===================================================================
diff -u -r148b1b06bb80e4ad65a7b8a722910db6eaef0098 -r91ec76d4b8a0fcf5962f442021c43f1ffa70743e
--- test/Plugins/Wti/Wti.IO.Test/Wti.IO.Test.csproj (.../Wti.IO.Test.csproj) (revision 148b1b06bb80e4ad65a7b8a722910db6eaef0098)
+++ test/Plugins/Wti/Wti.IO.Test/Wti.IO.Test.csproj (.../Wti.IO.Test.csproj) (revision 91ec76d4b8a0fcf5962f442021c43f1ffa70743e)
@@ -46,6 +46,7 @@
+
Index: test/Plugins/Wti/Wti.Plugin.Test/FileImporter/PipingSurfaceLineCsvImporterTest.cs
===================================================================
diff -u -ra24255dee45ce3bbeb2f140903969a2cd9f1fa67 -r91ec76d4b8a0fcf5962f442021c43f1ffa70743e
--- test/Plugins/Wti/Wti.Plugin.Test/FileImporter/PipingSurfaceLineCsvImporterTest.cs (.../PipingSurfaceLineCsvImporterTest.cs) (revision a24255dee45ce3bbeb2f140903969a2cd9f1fa67)
+++ test/Plugins/Wti/Wti.Plugin.Test/FileImporter/PipingSurfaceLineCsvImporterTest.cs (.../PipingSurfaceLineCsvImporterTest.cs) (revision 91ec76d4b8a0fcf5962f442021c43f1ffa70743e)
@@ -361,5 +361,49 @@
}
}
}
+
+ [Test]
+ public void ImportItem_FileWithTwoValidLinesAndOneInvalidDueToUnparsableNumber_SkipInvalidRowAndLog()
+ {
+ // Setup
+ string corruptPath = Path.Combine(testDataPath, "TwoValidAndOneInvalidNumberRowSurfaceLines.csv");
+
+ var mocks = new MockRepository();
+ var observer = mocks.StrictMock();
+ observer.Expect(o => o.UpdateObserver());
+ mocks.ReplayAll();
+
+ var importer = new PipingSurfaceLinesCsvImporter();
+ int progressCallCount = 0;
+ importer.ProgressChanged += (name, step, steps) =>
+ {
+ progressCallCount++;
+ };
+
+ var observableSurfaceLinesList = new ObservableList();
+ observableSurfaceLinesList.Attach(observer);
+
+ object importedItem = null;
+
+ // Call
+ Action call = () => importedItem = importer.ImportItem(corruptPath, observableSurfaceLinesList);
+
+ // Assert
+ var internalErrorMessage = String.Format(WtiIOResources.Error_File_0_has_not_double_Line_1_,
+ corruptPath, 3);
+ var expectedLogMessage = string.Format(ApplicationResources.PipingSurfaceLinesCsvImporter_ReadPipingSurfaceLines_ParseError_File_0_SurfaceLinesNumber_1_Message_2_,
+ corruptPath, 2, internalErrorMessage);
+ TestHelper.AssertLogMessageIsGenerated(call, expectedLogMessage, 1);
+ Assert.AreSame(observableSurfaceLinesList, importedItem);
+
+ Assert.AreEqual(2, observableSurfaceLinesList.Count,
+ "Ensure only the two valid surfacelines have been imported.");
+ Assert.AreEqual(1, observableSurfaceLinesList.Count(sl => sl.Name == "Rotterdam1"));
+ Assert.AreEqual(1, observableSurfaceLinesList.Count(sl => sl.Name == "ArtificalLocal"));
+
+ Assert.AreEqual(5, progressCallCount,
+ "Expect 1 call for each surfaceline (3 in total) +1 for 0/N progress, and 1 for putting data in model.");
+ mocks.VerifyAll();
+ }
}
}
\ No newline at end of file