Index: src/Plugins/Wti/Wti.Data/PipingSoilLayer.cs =================================================================== diff -u -re5c186677d0ef8697eb04ea571b7c4ef8268183c -r356ac6ef31864aa207c8af9470df3349f8e4d1f1 --- src/Plugins/Wti/Wti.Data/PipingSoilLayer.cs (.../PipingSoilLayer.cs) (revision e5c186677d0ef8697eb04ea571b7c4ef8268183c) +++ src/Plugins/Wti/Wti.Data/PipingSoilLayer.cs (.../PipingSoilLayer.cs) (revision 356ac6ef31864aa207c8af9470df3349f8e4d1f1) @@ -1,12 +1,10 @@ -namespace Wti.Data +using System.Collections.Generic; + +namespace Wti.Data { public class PipingSoilLayer { - public PipingSoilLayer(long id) - { - Id = id; - } - - public long Id { get; private set; } + public HashSet OuterLoop { get; set; } + public HashSet InnerLoop { get; set; } } } \ No newline at end of file Index: src/Plugins/Wti/Wti.Data/PipingSoilProfile.cs =================================================================== diff -u -r2d05e18d1fcde2d8d00d2434a6e560d65337d2f7 -r356ac6ef31864aa207c8af9470df3349f8e4d1f1 --- src/Plugins/Wti/Wti.Data/PipingSoilProfile.cs (.../PipingSoilProfile.cs) (revision 2d05e18d1fcde2d8d00d2434a6e560d65337d2f7) +++ src/Plugins/Wti/Wti.Data/PipingSoilProfile.cs (.../PipingSoilProfile.cs) (revision 356ac6ef31864aa207c8af9470df3349f8e4d1f1) @@ -1,28 +1,31 @@ -using System.Collections.Generic; +using System.Collections; +using System.Collections.Generic; namespace Wti.Data { /// /// This class represents a soil profile, which was imported for use in a piping calculation. /// - public class PipingSoilProfile + public class PipingSoilProfile : IEnumerable { - public PipingSoilProfile(long id, string name) + public PipingSoilProfile(string name, IEnumerable layers) { - Id = id; Name = name; - Layers = new List(); + Layers = layers; } public string Name { get; private set; } - private ICollection Layers { get; set; } + public IEnumerator GetEnumerator() + { + return Layers.GetEnumerator(); + } - public long Id { get; private set; } - - public void Add(PipingSoilLayer pipingSoilLayer) + IEnumerator IEnumerable.GetEnumerator() { - Layers.Add(pipingSoilLayer); + return GetEnumerator(); } + + public IEnumerable Layers { get; private set; } } } \ No newline at end of file Index: src/Plugins/Wti/Wti.Data/Point3D.cs =================================================================== diff -u -rc42d0c47753135357002db6026ebbefc3603a62b -r356ac6ef31864aa207c8af9470df3349f8e4d1f1 --- src/Plugins/Wti/Wti.Data/Point3D.cs (.../Point3D.cs) (revision c42d0c47753135357002db6026ebbefc3603a62b) +++ src/Plugins/Wti/Wti.Data/Point3D.cs (.../Point3D.cs) (revision 356ac6ef31864aa207c8af9470df3349f8e4d1f1) @@ -19,5 +19,43 @@ /// Gets or sets the z coordinate. /// public double Z { get; set; } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) + { + return false; + } + if (ReferenceEquals(this, obj)) + { + return true; + } + if (obj.GetType() != GetType()) + { + return false; + } + return Equals((Point3D) obj); + } + + public override int GetHashCode() + { + unchecked + { + var hashCode = X.GetHashCode(); + hashCode = (hashCode*397) ^ Y.GetHashCode(); + hashCode = (hashCode*397) ^ Z.GetHashCode(); + return hashCode; + } + } + + /// + /// Compares the with based on , and . + /// + /// A to compare with. + /// True if the coordinates of the matches the coordinate of . False otherwise. + protected bool Equals(Point3D other) + { + return X.Equals(other.X) && Y.Equals(other.Y) && Z.Equals(other.Z); + } } } \ No newline at end of file Index: src/Plugins/Wti/Wti.IO/Exceptions/PipingSoilProfileReadException.cs =================================================================== diff -u --- src/Plugins/Wti/Wti.IO/Exceptions/PipingSoilProfileReadException.cs (revision 0) +++ src/Plugins/Wti/Wti.IO/Exceptions/PipingSoilProfileReadException.cs (revision 356ac6ef31864aa207c8af9470df3349f8e4d1f1) @@ -0,0 +1,37 @@ +using System; +using Wti.Data; + +namespace Wti.IO.Exceptions +{ + /// + /// Exception thrown when something went wrong while reading in . + /// + public class PipingSoilProfileReadException : Exception + { + /// + /// Initializes a new instance of the class. + /// + public PipingSoilProfileReadException() + { + } + + /// + /// Initializes a new instance of the class + /// with a specified error message. + /// + /// The message that describes the error. + public PipingSoilProfileReadException(string message) + : base(message) + { + } + + /// + /// Initializes a new instance of the System.Exception 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 if no inner exception is specified. + public PipingSoilProfileReadException(string message, Exception innerException) : base(message, innerException) { } + } +} \ No newline at end of file Index: src/Plugins/Wti/Wti.IO/PipingSoilLayerReader.cs =================================================================== diff -u --- src/Plugins/Wti/Wti.IO/PipingSoilLayerReader.cs (revision 0) +++ src/Plugins/Wti/Wti.IO/PipingSoilLayerReader.cs (revision 356ac6ef31864aa207c8af9470df3349f8e4d1f1) @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Xml; +using Wti.Data; + +namespace Wti.IO +{ + /// + /// This class is responsible for reading an array of bytes and interpret this as a XML document, which contains information about + /// the geometry of a . + /// + internal class PipingSoilLayerReader + { + private const string outerLoopElementName = "OuterLoop"; + private const string innerLoopElementName = "InnerLoop"; + private const string endPointElementName = "EndPoint"; + private const string headPointElementName = "HeadPoint"; + private const string xElementName = "X"; + private const string yElementName = "Y"; + private const string zElementName = "Z"; + + private readonly XmlTextReader xmlTextReader; + + /// + /// Constructs a new , which uses the as the source of the + /// geometry for a . + /// + /// An array of which contains the information of a + /// in an XML document. + internal PipingSoilLayerReader(byte[] geometry) + { + xmlTextReader = new XmlTextReader(new MemoryStream(geometry)); + } + + /// + /// Reads the XML document and from this obtains the required information and constructs a based + /// on this information. + /// + /// A new with information taken from the XML document. + /// When reading from the XML document of the failed. + internal PipingSoilLayer Read() + { + var pipingSoilLayer = new PipingSoilLayer(); + + while (xmlTextReader.Read()) + { + HashSet outerLoop; + HashSet innerLoop; + if (TryParseLoop(outerLoopElementName, out outerLoop)) + { + pipingSoilLayer.OuterLoop = outerLoop; + } + if (TryParseLoop(innerLoopElementName, out innerLoop)) + { + pipingSoilLayer.InnerLoop = innerLoop; + } + } + + return pipingSoilLayer; + } + + /// + /// Tries to parse the element with the given , which the reader should be currently pointing at, as a loop. + /// + /// The name of the element which the reader should be currently pointing at. + /// The result of parsing the element as a loop. null if the current element's name does not match . + /// True if the reader currently points to an element with name . False otherwise. + private bool TryParseLoop(String elementName, out HashSet loop) + { + loop = null; + + if (IsElementWithName(elementName)) + { + loop = new HashSet(); + + while (xmlTextReader.Read() && !IsEndElementWithName(elementName)) + { + Point3D parsedPoint; + if (TryParsePoint(out parsedPoint)) + { + loop.Add(parsedPoint); + } + } + + return true; + } + return false; + } + + /// + /// Tries to parse the element which the reader is currently pointing at as a point. + /// + /// The result of parsing the element as a point. null if current element is not a head or end point. + /// True if the reader currently points to an element with name or . False otherwise. + private bool TryParsePoint(out Point3D point) + { + point = null; + + if (IsElementWithName(headPointElementName) || IsElementWithName(endPointElementName)) + { + var pointValues = ReadChildValues(); + point = new Point3D + { + X = double.Parse(pointValues[xElementName]), + Y = double.Parse(pointValues[yElementName]), + Z = double.Parse(pointValues[zElementName]) + }; + return true; + } + return false; + } + + /// + /// Reads the name and values for the children of the current element and puts them in a name indexed dictionary. + /// + /// A . For each entry, key is equal to child element name and value is equal to the value of the child element's text node. + private Dictionary ReadChildValues() + { + string elementName = xmlTextReader.Name; + var nodeSibblings = new Dictionary(); + + while (xmlTextReader.Read() && !IsEndElementWithName(elementName)) + { + if (xmlTextReader.NodeType == XmlNodeType.Element) + { + nodeSibblings[xmlTextReader.Name] = xmlTextReader.ReadString(); + } + } + + return nodeSibblings; + } + + /// + /// Checks whether the element the reader is currently pointing at is of type and has a name equal to . + /// + /// The name which the element should have. + /// True if the current element has type and its name is equal to . + private bool IsElementWithName(string name) + { + var isElement = xmlTextReader.NodeType == XmlNodeType.Element; + var isPoint = xmlTextReader.Name == name; + + return isElement && isPoint; + } + /// + /// Checks whether the element the reader is currently pointing at is of type and has a name equal to . + /// + /// The name which the end element should have. + /// True if the current element has type and its name is equal to . + private bool IsEndElementWithName(string name) + { + var isElement = xmlTextReader.NodeType == XmlNodeType.EndElement; + var isPoint = xmlTextReader.Name == name; + + return isElement && isPoint; + } + } +} \ No newline at end of file Index: src/Plugins/Wti/Wti.IO/PipingSoilProfileReader.cs =================================================================== diff -u --- src/Plugins/Wti/Wti.IO/PipingSoilProfileReader.cs (revision 0) +++ src/Plugins/Wti/Wti.IO/PipingSoilProfileReader.cs (revision 356ac6ef31864aa207c8af9470df3349f8e4d1f1) @@ -0,0 +1,146 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Data; +using System.Data.SQLite; +using System.IO; +using System.Linq; +using System.Xml; +using Wti.Data; +using Wti.IO.Exceptions; +using Wti.IO.Properties; + +namespace Wti.IO +{ + /// + /// This class reads a SqLite database file and constructs from this database. + /// The database is created with the DSoilModel application. + /// + public class PipingSoilProfileReader : IDisposable + { + private const int pipingMechanismId = 4; + private const int profileNameIndex = 0; + private const int profileLayerGeometryIndex = 1; + private SQLiteConnection connection; + private SQLiteDataReader dataReader; + + /// + /// Creates a new instance of which will use the + /// as its source. + /// + /// + public PipingSoilProfileReader(string dbFile) + { + if (String.IsNullOrEmpty(dbFile)) + { + throw new ArgumentException(Resources.Error_PathMustBeSpecified); + } + if (!File.Exists(dbFile)) + { + throw new FileNotFoundException(String.Format(Resources.Error_File_0_does_not_exist, dbFile)); + } + + PrepareConnection(dbFile); + Connect(); + } + + /// + /// Creates instances of based on the database file of the . + /// + /// + /// Thrown when reading soil profile entries from the database failed. + /// Thrown when parsing the geometry of a soil layer failed. + public IEnumerable Read() + { + var pipingSoilProfiles = new Dictionary>(); + + CreateDataReader(); + + while (dataReader.Read()) + { + var profileName = (string) dataReader[profileNameIndex]; + if (!pipingSoilProfiles.ContainsKey(profileName)) + { + pipingSoilProfiles.Add(profileName, new Collection()); + } + + pipingSoilProfiles[profileName].Add(ReadPipingSoilLayer()); + } + + return pipingSoilProfiles.Select(keyValue => new PipingSoilProfile(keyValue.Key, keyValue.Value)); + } + + public void Dispose() + { + dataReader.Dispose(); + connection.Dispose(); + } + + private void PrepareConnection(string dbFile) + { + var connectionStringBuilder = new SQLiteConnectionStringBuilder + { + FailIfMissing = true, + DataSource = dbFile, + ReadOnly = true, + ForeignKeys = true + }; + + connection = new SQLiteConnection(connectionStringBuilder.ConnectionString); + } + + private void Connect() + { + try + { + connection.Open(); + } + catch (SQLiteException) + { + connection.Dispose(); + } + } + + private PipingSoilLayer ReadPipingSoilLayer() + { + var columnValue = dataReader[profileLayerGeometryIndex]; + var geometry = (byte[]) columnValue; + return new PipingSoilLayerReader(geometry).Read(); + } + + /// + /// Creates a new data reader to use in this class, based on a query which returns all the known soil layers for which its profile has a X coordinate defined for piping. + /// + private void CreateDataReader() + { + var mechanismParameterName = "mechanism"; + var query = new SQLiteCommand(connection) + { + CommandText = string.Format( + "SELECT p.SP2D_Name, l.GeometrySurface " + + "FROM MechanismPointLocation as m " + + "JOIN SoilProfile2D as p ON m.SP2D_ID = p.SP2D_ID " + + "JOIN SoilLayer2D as l ON l.SP2D_ID = p.SP2D_ID " + + "WHERE m.ME_ID = @{0} " + + "ORDER BY p.SP2D_ID, l.SP2D_ID", + mechanismParameterName) + }; + + query.Parameters.Add(new SQLiteParameter + { + DbType = DbType.Int32, + Value = pipingMechanismId, + ParameterName = mechanismParameterName + }); + + try + { + dataReader = query.ExecuteReader(); + } + catch (SQLiteException e) + { + throw new PipingSoilProfileReadException(string.Format(Resources.Error_SoilProfileReadFromDatabase, connection.DataSource), e); + } + } + } +} \ No newline at end of file Fisheye: Tag 356ac6ef31864aa207c8af9470df3349f8e4d1f1 refers to a dead (removed) revision in file `src/Plugins/Wti/Wti.IO/PipingSoilProfilesReader.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: src/Plugins/Wti/Wti.IO/Properties/AssemblyInfo.cs =================================================================== diff -u -r5fc71a385897af92ccb092f2f969b5709afab85a -r356ac6ef31864aa207c8af9470df3349f8e4d1f1 --- src/Plugins/Wti/Wti.IO/Properties/AssemblyInfo.cs (.../AssemblyInfo.cs) (revision 5fc71a385897af92ccb092f2f969b5709afab85a) +++ src/Plugins/Wti/Wti.IO/Properties/AssemblyInfo.cs (.../AssemblyInfo.cs) (revision 356ac6ef31864aa207c8af9470df3349f8e4d1f1) @@ -1,6 +1,8 @@ using System.Reflection; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; [assembly: AssemblyTitle("Wti.IO")] [assembly: AssemblyProduct("Wti.IO")] -[assembly: Guid("f5af3cbe-d10c-42a5-b625-95222648aeaf")] \ No newline at end of file +[assembly: Guid("f5af3cbe-d10c-42a5-b625-95222648aeaf")] +[assembly: InternalsVisibleTo("Wti.IO.Test")] \ No newline at end of file Index: src/Plugins/Wti/Wti.IO/Properties/Resources.Designer.cs =================================================================== diff -u -recfa21abcbbd04db3963323e308dd0b94c8cb7a0 -r356ac6ef31864aa207c8af9470df3349f8e4d1f1 --- src/Plugins/Wti/Wti.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision ecfa21abcbbd04db3963323e308dd0b94c8cb7a0) +++ src/Plugins/Wti/Wti.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 356ac6ef31864aa207c8af9470df3349f8e4d1f1) @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.18444 +// Runtime Version:4.0.30319.34209 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -133,6 +133,15 @@ } /// + /// Looks up a localized string similar to Kon geen ondergrond profielen verkrijgen van de database '{0}'.. + /// + public static string Error_SoilProfileReadFromDatabase { + get { + return ResourceManager.GetString("Error_SoilProfileReadFromDatabase", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Het bestand op '{0}' heeft op regel {1} teveel tekst om in het RAM geheugen opgeslagen te worden.. /// public static string Error_Unexpected_IOError_File_0_Line_1_ { Index: src/Plugins/Wti/Wti.IO/Properties/Resources.resx =================================================================== diff -u -recfa21abcbbd04db3963323e308dd0b94c8cb7a0 -r356ac6ef31864aa207c8af9470df3349f8e4d1f1 --- src/Plugins/Wti/Wti.IO/Properties/Resources.resx (.../Resources.resx) (revision ecfa21abcbbd04db3963323e308dd0b94c8cb7a0) +++ src/Plugins/Wti/Wti.IO/Properties/Resources.resx (.../Resources.resx) (revision 356ac6ef31864aa207c8af9470df3349f8e4d1f1) @@ -147,4 +147,7 @@ Het bestand op '{0}' is niet geschikt om dwarsdoorsneden uit te lezen (Verwachte header: locationid;X1;Y1;Z1). + + Kon geen ondergrond profielen verkrijgen van de database '{0}'. + \ No newline at end of file Index: src/Plugins/Wti/Wti.IO/Wti.IO.csproj =================================================================== diff -u -rf2284364cde43ab7969dd8f0fb038f846138ec41 -r356ac6ef31864aa207c8af9470df3349f8e4d1f1 --- src/Plugins/Wti/Wti.IO/Wti.IO.csproj (.../Wti.IO.csproj) (revision f2284364cde43ab7969dd8f0fb038f846138ec41) +++ src/Plugins/Wti/Wti.IO/Wti.IO.csproj (.../Wti.IO.csproj) (revision 356ac6ef31864aa207c8af9470df3349f8e4d1f1) @@ -51,7 +51,9 @@ Properties\GlobalAssembly.cs - + + + Index: test/Plugins/Wti/Wti.Calculation.TestUtil/TestPipingSoilProfile.cs =================================================================== diff -u -re5c186677d0ef8697eb04ea571b7c4ef8268183c -r356ac6ef31864aa207c8af9470df3349f8e4d1f1 --- test/Plugins/Wti/Wti.Calculation.TestUtil/TestPipingSoilProfile.cs (.../TestPipingSoilProfile.cs) (revision e5c186677d0ef8697eb04ea571b7c4ef8268183c) +++ test/Plugins/Wti/Wti.Calculation.TestUtil/TestPipingSoilProfile.cs (.../TestPipingSoilProfile.cs) (revision 356ac6ef31864aa207c8af9470df3349f8e4d1f1) @@ -4,6 +4,6 @@ { public class TestPipingSoilProfile : PipingSoilProfile { - public TestPipingSoilProfile() : base(0, "") {} + public TestPipingSoilProfile() : base("", null) {} } } \ No newline at end of file Index: test/Plugins/Wti/Wti.Data.Test/Point3DTest.cs =================================================================== diff -u -rc42d0c47753135357002db6026ebbefc3603a62b -r356ac6ef31864aa207c8af9470df3349f8e4d1f1 --- test/Plugins/Wti/Wti.Data.Test/Point3DTest.cs (.../Point3DTest.cs) (revision c42d0c47753135357002db6026ebbefc3603a62b) +++ test/Plugins/Wti/Wti.Data.Test/Point3DTest.cs (.../Point3DTest.cs) (revision 356ac6ef31864aa207c8af9470df3349f8e4d1f1) @@ -1,4 +1,5 @@ -using NUnit.Framework; +using System; +using NUnit.Framework; namespace Wti.Data.Test { @@ -33,5 +34,107 @@ Assert.AreEqual(2.2, point.Y); Assert.AreEqual(-1.1, point.Z); } + + [Test] + public void Equals_ToItself_ReturnsTrue() + { + // Setup + var point = new Point3D(); + + // Call + var result = point.Equals(point); + + // Assert + Assert.IsTrue(result); + } + + [Test] + [TestCase(0,0,0)] + [TestCase(1,2,3)] + [TestCase(3.5,3.6,3.7)] + public void Equals_OtherWithSameCoordinates_ReturnsTrue(double x, double y, double z) + { + // Setup + var point = new Point3D + { + X = x, + Y = y, + Z = z + }; + var otherPoint = new Point3D + { + X = x, + Y = y, + Z = z + }; + + // Call + var result = point.Equals(otherPoint); + + // Assert + Assert.IsTrue(result); + } + + [Test] + [TestCase(1e-8, 0, 0)] + [TestCase(0, 1e-8, 0)] + [TestCase(0, 0, 1e-8)] + public void Equals_CloseToOtherPoint_ReturnsFalse(double deltaX, double deltaY, double deltaZ) + { + // Setup + var random = new Random(22); + var x = random.NextDouble(); + var y = random.NextDouble(); + var z = random.NextDouble(); + + var point = new Point3D + { + X = x, + Y = y, + Z = z + }; + var otherPoint = new Point3D + { + X = x + deltaX, + Y = y + deltaY, + Z = z + deltaZ + }; + + // Call + var result = point.Equals(otherPoint); + + // Assert + Assert.IsFalse(result); + } + + [Test] + public void GetHashCode_PointsAreEqual_PointsHashesEqual() + { + // Setup + var random = new Random(22); + var x = random.NextDouble(); + var y = random.NextDouble(); + var z = random.NextDouble(); + + var point = new Point3D + { + X = x, + Y = y, + Z = z + }; + var otherPoint = new Point3D + { + X = x, + Y = y, + Z = z + }; + + // Call + var result = point.GetHashCode(); + var otherResult = otherPoint.GetHashCode(); + + // Assert + Assert.AreEqual(result, otherResult); + } } } \ No newline at end of file Index: test/Plugins/Wti/Wti.IO.Test/Exceptions/PipingSoilProfileReadExceptionTest.cs =================================================================== diff -u --- test/Plugins/Wti/Wti.IO.Test/Exceptions/PipingSoilProfileReadExceptionTest.cs (revision 0) +++ test/Plugins/Wti/Wti.IO.Test/Exceptions/PipingSoilProfileReadExceptionTest.cs (revision 356ac6ef31864aa207c8af9470df3349f8e4d1f1) @@ -0,0 +1,52 @@ +using System; +using NUnit.Framework; +using Wti.IO.Exceptions; + +namespace Wti.IO.Test.Exceptions +{ + public class PipingSoilProfileReadExceptionTest + { + [Test] + public void DefaultConstructor_InnerExceptionNullAndMessageDefault() + { + // Setup + var expectedMessage = String.Format("Exception of type '{0}' was thrown.", typeof(PipingSoilProfileReadException).FullName); + + // Call + var exception = new PipingSoilProfileReadException(); + + // Assert + Assert.IsNull(exception.InnerException); + Assert.AreEqual(expectedMessage, exception.Message); + } + + [Test] + public void Constructor_WithCustomMessage_InnerExceptionNullAndMessageSetToCustom() + { + // Setup + var expectedMessage ="Some exception message"; + + // Call + var exception = new PipingSoilProfileReadException(expectedMessage); + + // Assert + Assert.IsNull(exception.InnerException); + Assert.AreEqual(expectedMessage, exception.Message); + } + + [Test] + public void Constructor_WithCustomMessageAndInnerException_InnerExceptionSetAndMessageSetToCustom() + { + // Setup + var expectedMessage = "Some exception message"; + var expectedInnerException = new Exception(); + + // Call + var exception = new PipingSoilProfileReadException(expectedMessage, expectedInnerException); + + // Assert + Assert.AreSame(expectedInnerException, exception.InnerException); + Assert.AreEqual(expectedMessage, exception.Message); + } + } +} \ No newline at end of file Index: test/Plugins/Wti/Wti.IO.Test/PipingSoilProfileReaderTest.cs =================================================================== diff -u --- test/Plugins/Wti/Wti.IO.Test/PipingSoilProfileReaderTest.cs (revision 0) +++ test/Plugins/Wti/Wti.IO.Test/PipingSoilProfileReaderTest.cs (revision 356ac6ef31864aa207c8af9470df3349f8e4d1f1) @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using DelftTools.TestUtils; +using NUnit.Framework; +using Wti.Data; +using Wti.IO.Exceptions; +using Wti.IO.Properties; + +namespace Wti.IO.Test +{ + public class PipingSoilProfileReaderTest + { + + private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Plugins.Wti.WtiIOPath, "PipingSoilProfilesReader"); + + [Test] + public void Constructor_CorrectPath_ReturnsNewInstance() + { + // Setup + var testFile = "empty.soil"; + + // Call + var pipingSoilProfilesReader = new PipingSoilProfileReader(Path.Combine(testDataPath, testFile)); + + // Assert + Assert.NotNull(pipingSoilProfilesReader); + } + + [Test] + public void Constructor_NonExistingPath_ThrowsFileNotFoundException() + { + // Setup + var testFile = Path.Combine(testDataPath, "none.soil"); + + // Call + TestDelegate test = () => new PipingSoilProfileReader(testFile); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual(String.Format(Resources.Error_File_0_does_not_exist, testFile), exception.Message); + } + + [Test] + [TestCase(null)] + [TestCase("")] + public void ReadSoilProfiles_NullOrEmpty_ThrowsArgumentException(string fileName) + { + // Call + TestDelegate test = () => new PipingSoilProfileReader(fileName); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual(Resources.Error_PathMustBeSpecified, exception.Message); + } + + [Test] + public void ReadSoilProfiles_IncorrectFormatFile_ThrowsSqLiteException() + { + // Setup + var dbName = "text"; + var testFile = Path.Combine(testDataPath, dbName + ".txt"); + var pipingSoilProfilesReader = new PipingSoilProfileReader(testFile); + + // Call + TestDelegate test = () => pipingSoilProfilesReader.Read(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual(String.Format(Resources.Error_SoilProfileReadFromDatabase, dbName), exception.Message); + } + + [Test] + public void ReadSoilProfiles_CompleteDatabase_Returns2ProfilesWithLayersAndGeometries() + { + // Setup + var testFile = "complete.soil"; + var pipingSoilProfilesReader = new PipingSoilProfileReader(Path.Combine(testDataPath, testFile)); + + var firstProfileFirstLayerOuterLoop = new HashSet + { + new Point3D{X=0,Y=0,Z=-10}, + new Point3D{X=0,Y=0,Z=-3.5}, + new Point3D{X=70.208,Y=0,Z=-3.5}, + new Point3D{X=73.91,Y=0,Z=-3.5}, + new Point3D{X=80.78,Y=0,Z=-3.5}, + new Point3D{X=80.78,Y=0,Z=-10}, + }; + + var secondProfileSecondLayerOuterLoop = new HashSet + { + new Point3D{X=87.516,Y=0,Z=-1.5}, + new Point3D{X=87.567000000000007,Y=0,Z=-0.70000000000000007}, + new Point3D{X=101.4,Y=0,Z=-0.70000000000000007}, + new Point3D{X=101.4,Y=0,Z=-1.5}, + }; + + // Call + IEnumerable result = pipingSoilProfilesReader.Read().ToArray(); + + // Assert + Assert.AreEqual(2, result.Count()); + var firstProfile = result.SingleOrDefault(psp => psp.Name == "10Y_005_STBI"); + Assert.NotNull(firstProfile); + Assert.AreEqual(13, firstProfile.Count()); + CollectionAssert.AreEqual(firstProfileFirstLayerOuterLoop, firstProfile.Layers.ToArray()[0].OuterLoop); + Assert.IsNull(firstProfile.Layers.ToArray()[0].InnerLoop); + + var secondProfile = result.SingleOrDefault(psp => psp.Name == "10Y_041_STBI"); + Assert.NotNull(secondProfile); + Assert.AreEqual(14, secondProfile.Count()); + CollectionAssert.AreEqual(secondProfileSecondLayerOuterLoop, secondProfile.Layers.ToArray()[1].OuterLoop); + Assert.IsNull(secondProfile.Layers.ToArray()[1].InnerLoop); + } + } +} \ No newline at end of file Fisheye: Tag 356ac6ef31864aa207c8af9470df3349f8e4d1f1 refers to a dead (removed) revision in file `test/Plugins/Wti/Wti.IO.Test/PipingSoilProfilesReaderTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: test/Plugins/Wti/Wti.IO.Test/Wti.IO.Test.csproj =================================================================== diff -u -rf2284364cde43ab7969dd8f0fb038f846138ec41 -r356ac6ef31864aa207c8af9470df3349f8e4d1f1 --- test/Plugins/Wti/Wti.IO.Test/Wti.IO.Test.csproj (.../Wti.IO.Test.csproj) (revision f2284364cde43ab7969dd8f0fb038f846138ec41) +++ test/Plugins/Wti/Wti.IO.Test/Wti.IO.Test.csproj (.../Wti.IO.Test.csproj) (revision 356ac6ef31864aa207c8af9470df3349f8e4d1f1) @@ -41,7 +41,8 @@ - + +