Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/CsvParser.cs =================================================================== diff -u -r4070 -r4259 --- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/CsvParser.cs (.../CsvParser.cs) (revision 4070) +++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/CsvParser.cs (.../CsvParser.cs) (revision 4259) @@ -27,22 +27,19 @@ namespace Deltares.Dam.Data; +/// +/// Parses a csv file and returns a sequence of entities of a specific type +/// public static class CsvParser { /// - /// This regex splits comma or semicolon separated lists of optionally quoted strings. It handles quoted delimiters and escaped quotes. + /// This regex splits semicolon separated lists of optionally quoted strings. It handles quoted delimiters and escaped quotes. /// Whitespace inside quotes is preserved, outside is eaten. /// See: http://regexlib.com/REDetails.aspx?regexp_id=1325 /// - public static string CsvSplitPatternCommaAndSemicolonCombined = - @"\s*[;,]\s*(?!(?<=(?:^|[;,])\s*""(?:[^""]|""""|\\"")*[;,]\s*)(?:[^""]|""""|\\"")*""\s*(?:[;,]|$))"; - - public static string CsvSplitPatternSemicolonOnly = + public static readonly string CsvSplitPatternSemicolonOnly = @"\s*[;]\s*(?!(?<=(?:^|[;])\s*""(?:[^""]|""""|\\"")*[;]\s*)(?:[^""]|""""|\\"")*""\s*(?:[;]|$))"; - public static string CsvSplitPatternCommaOnly = - @"\s*[,]\s*(?!(?<=(?:^|[,])\s*""(?:[^""]|""""|\\"")*[,]\s*)(?:[^""]|""""|\\"")*""\s*(?:[,]|$))"; - /// /// Parses the header of an csv import file /// @@ -90,11 +87,8 @@ { while (!sr.EndOfStream && !headerInfoHasBeenParsed) { - if (!headerInfoHasBeenParsed) - { - headers = ParseHeader(sr.ReadLine(), splitter); - headerInfoHasBeenParsed = true; - } + headers = ParseHeader(sr.ReadLine(), splitter); + headerInfoHasBeenParsed = true; } } @@ -149,7 +143,7 @@ ThrowHelper.ThrowWhenConditionIsTrue( materializer, StringResourceNames.CsvObjectMaterializerNotValid, - c => materializer.Count == 0, + _ => materializer.Count == 0, r => new CsvParserException(ThrowHelper.GetResourceString(r))); var splitter = new Regex(splitPattern, RegexOptions.IgnoreCase | RegexOptions.Compiled); Index: DamClients/DamUI/trunk/src/Dam/Forms/Properties/Resources.Designer.cs =================================================================== diff -u -r3526 -r4259 --- DamClients/DamUI/trunk/src/Dam/Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 3526) +++ DamClients/DamUI/trunk/src/Dam/Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 4259) @@ -100,5 +100,14 @@ return ((System.Drawing.Bitmap)(obj)); } } + + /// + /// Looks up a localized string similar to + /// + internal static string DamUserManual { + get { + return ResourceManager.GetString("DamUserManual", resourceCulture); + } + } } } Index: DamClients/DamUI/trunk/src/Dam/Deltares.Dam.TestHelper/TestUtils/MemoryLeakTestBase.cs =================================================================== diff -u -r4070 -r4259 --- DamClients/DamUI/trunk/src/Dam/Deltares.Dam.TestHelper/TestUtils/MemoryLeakTestBase.cs (.../MemoryLeakTestBase.cs) (revision 4070) +++ DamClients/DamUI/trunk/src/Dam/Deltares.Dam.TestHelper/TestUtils/MemoryLeakTestBase.cs (.../MemoryLeakTestBase.cs) (revision 4259) @@ -25,112 +25,100 @@ using Deltares.Dam.Tests.TestUtils; using NUnit.Framework; -namespace Deltares.Dam.TestHelper.TestUtils +namespace Deltares.Dam.TestHelper.TestUtils; + +/// +/// A base class providing template methods to be used for performing +/// memory leak tests. +/// +/// This class is working purely on non-GUI level. +[TestFixture] +public abstract class MemoryLeakTestBase { + private ObjectLeakMonitor objectLeakMonitor; + private ObjectLeakMonitor[] directCompositeChildrenLeakMonitors; + + [TearDown] + public void TearDown() + { + objectLeakMonitor = null; + directCompositeChildrenLeakMonitors = null; + } + /// - /// A base class providing template methods to be used for performing - /// memory leak tests. + /// Clear all static caches that should be cleared at end of application /// - /// This class is working purely on non-GUI level. - [TestFixture] - public abstract class MemoryLeakTestBase + private void ClearStaticCaches() { - private ObjectLeakMonitor objectLeakMonitor; - private ObjectLeakMonitor[] directCompositeChildrenLeakMonitors; + // Clear all static, non-GUI caches here + } - [TearDown] - public void TearDown() - { - objectLeakMonitor = null; - directCompositeChildrenLeakMonitors = null; - } + protected bool MonitorMemoryLeakage(Func> getMonitoredChildren, out string report) where T : class, IDisposable, new() + { + PerformMemoryMeasurements(() => new T(), getMonitoredChildren); - /// - /// Clear all static caches that should be cleared at end of application - /// - protected virtual void ClearStaticCaches() + bool isLeaking = CreateMemoryLeakReport(objectLeakMonitor, directCompositeChildrenLeakMonitors, out string memoryLeakReport); + if (!isLeaking) { - // Clear all static, non-GUI caches here + Console.WriteLine(memoryLeakReport); } - protected void MonitorMemoryLeakage(Func createMonitoredObject, Func> getMonitoredChildren) where T : class, IDisposable - { - PerformMemoryMeasurements(createMonitoredObject, getMonitoredChildren); + report = memoryLeakReport; + return isLeaking; + } - string report; - bool isLeaking = CreateMemoryLeakReport(objectLeakMonitor, directCompositeChildrenLeakMonitors, out report); - if (!isLeaking) - { - Console.WriteLine(report); - } - - Assert.IsFalse(isLeaking, report); - } - - protected void MonitorMemoryLeakage(Func> getMonitoredChildren) where T : class, IDisposable, new() + /// + /// Performs the memory measurements. + /// + /// The object type to be monitored. It's default constructor will be used. + /// The object creation method. + /// The get monitored children. + /// + /// + /// The creation is performed in a separate method than where the are checked to + /// ensure the objects will be garbage collected. + /// + /// + private void PerformMemoryMeasurements(Func createMonitoredObject, Func> getMonitoredChildren) where T : class, IDisposable + { + using (T objectToMonitor = createMonitoredObject()) { - PerformMemoryMeasurements(() => new T(), getMonitoredChildren); - - string report; - bool isLeaking = CreateMemoryLeakReport(objectLeakMonitor, directCompositeChildrenLeakMonitors, out report); - if (!isLeaking) - { - Console.WriteLine(report); - } - - Assert.IsFalse(isLeaking, report); + objectLeakMonitor = new ObjectLeakMonitor(objectToMonitor); + directCompositeChildrenLeakMonitors = getMonitoredChildren != null + ? getMonitoredChildren(objectToMonitor) + .Select(mc => new ObjectLeakMonitor(mc)) + .ToArray() + : null; } - /// - /// Performs the memory measurements. - /// - /// The object type to be monitored. It's default constructor will be used. - /// The object creation method. - /// The get monitored children. - /// - /// The creation is performed in a separate method than where the are checked to ensure the objects will be garbage collected. - /// - private void PerformMemoryMeasurements(Func createMonitoredObject, Func> getMonitoredChildren) where T : class, IDisposable - { - using (T objectToMonitor = createMonitoredObject()) - { - objectLeakMonitor = new ObjectLeakMonitor(objectToMonitor); - directCompositeChildrenLeakMonitors = getMonitoredChildren != null - ? getMonitoredChildren(objectToMonitor) - .Select(mc => new ObjectLeakMonitor(mc)) - .ToArray() - : null; - } + ClearStaticCaches(); + } - ClearStaticCaches(); - } + /// + /// Creates the memory leak report. + /// + /// The monitor for the object under test. + /// The composite children leak monitors. + /// Output: The memory leak report. + /// True if a memory or object leak has been detected; False otherwise. + private bool CreateMemoryLeakReport(ObjectLeakMonitor monitor, ObjectLeakMonitor[] compositeChildrenLeakMonitors, out string report) + { + report = Environment.NewLine + "=================================================================" + Environment.NewLine; + report += "Memory leak report for " + monitor.MonitoredObjectType + Environment.NewLine; + report += "Object garbage collected: " + !monitor.ObjectIsAlive() + Environment.NewLine; - /// - /// Creates the memory leak report. - /// - /// The monitor for the object under test. - /// The composite children leak monitors. - /// Output: The memory leak report. - /// True if a memory or object leak has been detected; False otherwise. - private bool CreateMemoryLeakReport(ObjectLeakMonitor monitor, ObjectLeakMonitor[] compositeChildrenLeakMonitors, out string report) + if ((compositeChildrenLeakMonitors != null) && compositeChildrenLeakMonitors.Any()) { - report = Environment.NewLine + "=================================================================" + Environment.NewLine; - report += "Memory leak report for " + monitor.MonitoredObjectType + Environment.NewLine; - report += "Object garbage collected: " + !monitor.ObjectIsAlive() + Environment.NewLine; + report += "All monitored composite children garbage collected: " + compositeChildrenLeakMonitors.All(c => !c.ObjectIsAlive()) + Environment.NewLine; - if (compositeChildrenLeakMonitors != null && compositeChildrenLeakMonitors.Any()) + foreach (ObjectLeakMonitor compositeChildrenLeakMonitor in compositeChildrenLeakMonitors) { - report += "All monitored composite children garbage collected: " + compositeChildrenLeakMonitors.All(c => !c.ObjectIsAlive()) + Environment.NewLine; - - foreach (ObjectLeakMonitor compositeChildrenLeakMonitor in compositeChildrenLeakMonitors) - { - report += "\tChild (" + compositeChildrenLeakMonitor.MonitoredObjectType + ") garbage collected: " + !compositeChildrenLeakMonitor.ObjectIsAlive() + Environment.NewLine; - } + report += "\tChild (" + compositeChildrenLeakMonitor.MonitoredObjectType + ") garbage collected: " + !compositeChildrenLeakMonitor.ObjectIsAlive() + Environment.NewLine; } + } - report += "================================================================="; + report += "================================================================="; - return monitor.ObjectIsAlive() || (compositeChildrenLeakMonitors != null && compositeChildrenLeakMonitors.Any(c => c.ObjectIsAlive())); - } + return monitor.ObjectIsAlive() || ((compositeChildrenLeakMonitors != null) && compositeChildrenLeakMonitors.Any(c => c.ObjectIsAlive())); } } \ No newline at end of file Index: DamClients/DamUI/trunk/src/Dam/Forms/DamPlugin.cs =================================================================== diff -u -r4255 -r4259 --- DamClients/DamUI/trunk/src/Dam/Forms/DamPlugin.cs (.../DamPlugin.cs) (revision 4255) +++ DamClients/DamUI/trunk/src/Dam/Forms/DamPlugin.cs (.../DamPlugin.cs) (revision 4259) @@ -36,6 +36,7 @@ using Deltares.Dam.Data.License; using Deltares.Dam.Data.Sensors; using Deltares.Dam.Data.UISupport; +using Deltares.Dam.Forms.Properties; using Deltares.DamEngine.Interface; using Deltares.DamEngine.Io; using Deltares.DamEngine.Io.XmlInput; @@ -678,7 +679,7 @@ // As documented by https://support.microsoft.com/en-gb/help/305703/how-to-start-the-default-internet-browser-programmatically-by-using-vi try { - Process.Start("https://publicwiki.deltares.nl/display/DAM/Gebruikershandleiding+DAM+19.1"); + Process.Start(Resources.DamUserManual); } catch (Win32Exception noBrowser) { @@ -712,42 +713,6 @@ } } - /// - /// Dummy calculation to generate values for the stability factors - /// - private void ExecuteCalculationDummy() - { - // This is a dummy calculation; - // Should be replaced with real calculation - var random = new Random(); - foreach (DikeJob dikeJob in (damProject.DamProjectData.WaterBoardJob as WaterBoardJob).Jobs) - { - foreach (LocationJob locationJob in dikeJob.Jobs) - { - var stabilityTimeSerie = new TimeSerie(); - stabilityTimeSerie.MissVal = damProject.DamProjectData.MissValStabilitySafetyFactor; - foreach (TimeSerieEntry timeSerieEntry in locationJob.WaterLevelTimeSerie.Entries) - { - if (locationJob.Run.Value) - { - double lran = random.NextDouble(); - if (lran <= 0.1) - { - stabilityTimeSerie.Entries.Add(new TimeSerieEntry(timeSerieEntry.DateTime, - stabilityTimeSerie.MissVal)); - } - else - { - stabilityTimeSerie.Entries.Add(new TimeSerieEntry(timeSerieEntry.DateTime, random.NextDouble() + 0.5)); - } - } - } - - locationJob.LocationResult.StabilityTimeSerie = stabilityTimeSerie; - } - } - } - [Label("Run")] private void ExecuteCalculation() { Index: DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/Memoryleaks/DamMemoryLeakTests.cs =================================================================== diff -u -r4255 -r4259 --- DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/Memoryleaks/DamMemoryLeakTests.cs (.../DamMemoryLeakTests.cs) (revision 4255) +++ DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/Memoryleaks/DamMemoryLeakTests.cs (.../DamMemoryLeakTests.cs) (revision 4259) @@ -27,131 +27,136 @@ using Deltares.Geotechnics.SurfaceLines; using NUnit.Framework; -namespace Deltares.Dam.Tests.Memoryleaks +namespace Deltares.Dam.Tests.Memoryleaks; + +[TestFixture] +public class DamMemoryLeakTests : MemoryLeakTestBase { - [TestFixture] - public class DamMemoryLeakTests : MemoryLeakTestBase + [Test] + public void Location_ShouldNotLeak() { - [Test] - public void Location_ShouldNotLeak() - { - MonitorMemoryLeakage(GetMonitoredChildren); - } + bool isLeaking = MonitorMemoryLeakage(GetMonitoredChildren, out string report); + Assert.That(isLeaking, Is.False, report); + } - [Test] - public void Dike_ShouldNotLeak() - { - MonitorMemoryLeakage(GetMonitoredChildren); - } + [Test] + public void Dike_ShouldNotLeak() + { + bool isLeaking = MonitorMemoryLeakage(GetMonitoredChildren, out string report); + Assert.That(isLeaking, Is.False, report); + } - [Test] - public void WaterBoard_ShouldNotLeak() - { - MonitorMemoryLeakage(GetMonitoredChildren); - } + [Test] + public void WaterBoard_ShouldNotLeak() + { + bool isLeaking = MonitorMemoryLeakage(GetMonitoredChildren, out string report); + Assert.That(isLeaking, Is.False, report); + } - [Test] - public void DamProjectData_ShouldNotLeak() - { - MonitorMemoryLeakage(GetMonitoredChildren); - } + [Test] + public void DamProjectData_ShouldNotLeak() + { + bool isLeaking = MonitorMemoryLeakage(GetMonitoredChildren, out string report); + Assert.That(isLeaking, Is.False, report); + } - [Test] - public void DamProjectCalculationSpecification_ShouldNotLeak() - { - MonitorMemoryLeakage(null); - } + [Test] + public void DamProjectCalculationSpecification_ShouldNotLeak() + { + bool isLeaking = MonitorMemoryLeakage(null, out string report); + Assert.That(isLeaking, Is.False, report); + } - [Test] - public void DamProject_ShouldNotLeak() - { - MonitorMemoryLeakage(GetMonitoredChildren); - } + [Test] + public void DamProject_ShouldNotLeak() + { + bool isLeaking = MonitorMemoryLeakage(GetMonitoredChildren, out string report); + Assert.That(isLeaking, Is.False, report); + } - private IEnumerable GetMonitoredChildren(Location location) + private IEnumerable GetMonitoredChildren(Location location) + { + var list = new List(); + // Local surfaceline is a composite child of Location: + var localXzSurfaceLine2 = new SurfaceLine2 { - var list = new List(); - // Local surfaceline is a composite child of Location: - var localXzSurfaceLine2 = new SurfaceLine2 + Geometry = new LocalizedGeometryPointString(), + CharacteristicPoints = { - Geometry = new LocalizedGeometryPointString(), - CharacteristicPoints = - { - GeometryMustContainPoint = true - } - }; - localXzSurfaceLine2.AddCharacteristicPoint(new GeometryPoint(1.1, 0.0, 2.2), CharacteristicPointType.ShoulderBaseInside); + GeometryMustContainPoint = true + } + }; + localXzSurfaceLine2.AddCharacteristicPoint(new GeometryPoint(1.1, 0.0, 2.2), CharacteristicPointType.ShoulderBaseInside); - location.LocalXZSurfaceLine2 = localXzSurfaceLine2; - list.Add(localXzSurfaceLine2); + location.LocalXZSurfaceLine2 = localXzSurfaceLine2; + list.Add(localXzSurfaceLine2); - return list; - } + return list; + } - private IEnumerable GetMonitoredChildren(Dike dike) - { - var list = new List(); - var localizedGeometryPointString = new LocalizedGeometryPointString(); // Aggregation relationship + private IEnumerable GetMonitoredChildren(Dike dike) + { + var list = new List(); + var localizedGeometryPointString = new LocalizedGeometryPointString(); // Aggregation relationship - // A composite child of Dike - var surfaceLine = new SurfaceLine2 + // A composite child of Dike + var surfaceLine = new SurfaceLine2 + { + Geometry = localizedGeometryPointString, + CharacteristicPoints = { - Geometry = localizedGeometryPointString, - CharacteristicPoints = - { - GeometryMustContainPoint = true - } - }; - surfaceLine.AddCharacteristicPoint(new GeometryPoint(1.1, 0.0, 2.2), CharacteristicPointType.InsertRiverChannel, CharacteristicPointType.SurfaceLevelInside); + GeometryMustContainPoint = true + } + }; + surfaceLine.AddCharacteristicPoint(new GeometryPoint(1.1, 0.0, 2.2), CharacteristicPointType.InsertRiverChannel, CharacteristicPointType.SurfaceLevelInside); - list.Add(surfaceLine); - dike.SurfaceLines2.Add(surfaceLine); + list.Add(surfaceLine); + dike.SurfaceLines2.Add(surfaceLine); - // Composite child of Dike - var location = new Location(); - list.Add(location); - GetMonitoredChildren(location); // Sets up 'leakable' Location instance - dike.Locations.Add(location); + // Composite child of Dike + var location = new Location(); + list.Add(location); + GetMonitoredChildren(location); // Sets up 'leakable' Location instance + dike.Locations.Add(location); - return list; - } + return list; + } - private IEnumerable GetMonitoredChildren(WaterBoard waterBoard) - { - var list = new List(); + private IEnumerable GetMonitoredChildren(WaterBoard waterBoard) + { + var list = new List(); - var dike = new Dike(); - list.Add(dike); - GetMonitoredChildren(dike); // Create 'leakable' Dike instance - waterBoard.Dikes.Add(dike); + var dike = new Dike(); + list.Add(dike); + GetMonitoredChildren(dike); // Create 'leakable' Dike instance + waterBoard.Dikes.Add(dike); - return list; - } + return list; + } - private IEnumerable GetMonitoredChildren(DamProjectData projectData) + private IEnumerable GetMonitoredChildren(DamProjectData projectData) + { + var list = new List { - var list = new List - { - projectData.WaterBoard - }; + projectData.WaterBoard + }; - GetMonitoredChildren(projectData.WaterBoard); // Create 'leakable' WaterBoard data + GetMonitoredChildren(projectData.WaterBoard); // Create 'leakable' WaterBoard data - list.Add(projectData.DamProjectCalculationSpecification); + list.Add(projectData.DamProjectCalculationSpecification); - return list; - } + return list; + } - private IEnumerable GetMonitoredChildren(DamProject damProject) + private IEnumerable GetMonitoredChildren(DamProject damProject) + { + var list = new List { - var list = new List - { - damProject.DamProjectData - }; + damProject.DamProjectData + }; - GetMonitoredChildren(damProject.DamProjectData); // Create 'leakable' DamProjectData data + GetMonitoredChildren(damProject.DamProjectData); // Create 'leakable' DamProjectData data - return list; - } + return list; } } \ No newline at end of file Index: DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/CsvParserTest.cs =================================================================== diff -u -r4070 -r4259 --- DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/CsvParserTest.cs (.../CsvParserTest.cs) (revision 4070) +++ DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/CsvParserTest.cs (.../CsvParserTest.cs) (revision 4259) @@ -27,171 +27,167 @@ using Deltares.Dam.Data; using NUnit.Framework; -namespace Deltares.Dam.Tests +namespace Deltares.Dam.Tests; + +[TestFixture] +public class CsvParserTest { - [TestFixture] - public class CsvParserTest + private string testFile; + + [SetUp] + public void FixtureSetup() { - private string testFile; + testFile = "test.csv"; + using StreamWriter writer = File.CreateText(testFile); + writer.WriteLine("name;age"); //<- header contains name and age + writer.WriteLine("Anouar;31"); + writer.WriteLine("Barry;39"); + writer.WriteLine("Tom;48"); + writer.WriteLine("Remko;39"); + } - [SetUp] - public void FixtureSetup() + [TearDown] + public void FixtureTearDown() + { + if (File.Exists(testFile)) { - testFile = "test.csv"; - using (StreamWriter writer = File.CreateText(testFile)) - { - writer.WriteLine("name;age"); //<- header contains name and age - writer.WriteLine("Anouar;31"); - writer.WriteLine("Barry;39"); - writer.WriteLine("Tom;48"); - writer.WriteLine("Remko;39"); - } + File.Delete(testFile); } + } - [TearDown] - public void FixtureTearDown() - { - if (File.Exists(testFile)) - { - File.Delete(testFile); - } - } + [Test] + public void ThrowsArgumentExceptionWhenHeaderStringIsNullByCallingParseHeader() + { + var expectedMessage = "The header in the import file is not valid"; + Assert.That(() => CsvParser.ParseHeader(null, new Regex("")), Throws.ArgumentException.With.Message.EqualTo(expectedMessage)); + } - [Test] - public void ThrowsArgumentExceptionWhenHeaderStringIsNullByCallingParseHeader() - { - var expectedMessage = "The header in the import file is not valid"; - Assert.That(() => CsvParser.ParseHeader(null, new Regex("")), Throws.TypeOf(typeof(ArgumentException)).With.Message.EqualTo(expectedMessage)); - } + [Test] + public void ThrowsArgumentExceptionSplitterIsNull() + { + string expectedMessage = "The given pattern to split the data values of the CSV files is not valid" + Environment.NewLine + "Parameter name: splitter"; + Assert.That(() => CsvParser.ParseHeader("test;test", null), Throws.ArgumentNullException.With.Message.EqualTo(expectedMessage)); + } - [Test] - public void ThrowsArgumentExceptionSplitterIsNull() - { - string expectedMessage = "The given pattern to split the data values of the CSV files is not valid" + Environment.NewLine + "Parameter name: splitter"; - Assert.That(() => CsvParser.ParseHeader("test;test", null), Throws.TypeOf(typeof(ArgumentNullException)).With.Message.EqualTo(expectedMessage)); - } + [Test] + public void ThrowsWhenSplitPatternIsEmpty() + { + var expectedMessage = "The given pattern to split the data values of the CSV files is not valid"; + Assert.That(() => CsvParser.ParseHeader("test", new Regex("")), Throws.ArgumentException.With.Message.EqualTo(expectedMessage)); + } - [Test] - public void ThrowsWhenSplitPatternIsEmpty() - { - var expectedMessage = "The given pattern to split the data values of the CSV files is not valid"; - Assert.That(() => CsvParser.ParseHeader("test", new Regex("")), Throws.TypeOf(typeof(ArgumentException)).With.Message.EqualTo(expectedMessage)); - } + [Test] + [Ignore("[ExpectedException(typeof(CsvParserException))]")] + public void ThrowsWhenNoHeaderItemsAreParsed() + { + Assert.That(() => CsvParser.ParseHeader("test", new Regex("")), Throws.InstanceOf()); + } - [Test] - [Ignore("[ExpectedException(typeof(CsvParserException))]")] - public void ThrowsWhenNoHeaderItemsAreParsed() - { - Assert.That(() => CsvParser.ParseHeader("test", new Regex("")), Throws.InstanceOf()); - } + [Test] + public void CanParseHeaderWithSemicolonSeparatedItems() + { + string[] items = CsvParser.ParseHeader("header1;header 2", new Regex(CsvParser.CsvSplitPatternSemicolonOnly)); + Assert.AreEqual(2, items.Length); + Assert.AreEqual("header1", items[0]); + Assert.AreEqual("header 2", items[1]); + } - [Test] - public void CanParseHeaderWithSemicolonSeparatedItems() - { - string[] items = CsvParser.ParseHeader("header1;header 2", new Regex(CsvParser.CsvSplitPatternCommaAndSemicolonCombined)); - Assert.AreEqual(2, items.Length); - Assert.AreEqual("header1", items[0]); - Assert.AreEqual("header 2", items[1]); - } + [Test] + public void CannotParseHeaderWithCommaSeparatedItems() + { + string[] items = CsvParser.ParseHeader("header1,header 2", new Regex(CsvParser.CsvSplitPatternSemicolonOnly)); + Assert.AreEqual(1, items.Length); + Assert.AreEqual("header1,header 2", items[0]); + } - [Test] - public void CanParseHeaderWithCommaSeparatedItems() - { - string[] items = CsvParser.ParseHeader("header1,header 2", new Regex(CsvParser.CsvSplitPatternCommaAndSemicolonCombined)); - Assert.AreEqual(2, items.Length); - Assert.AreEqual("header1", items[0]); - Assert.AreEqual("header 2", items[1]); - } + [Test] + public void ThrowsExceptionWhenObjectMaterializerNull() + { + Assert.That(() => CsvParser.LoadFromCsvFile(null, testFile).ToList(), Throws.ArgumentNullException); + } - [Test] - public void ThrowsExceptionWhenObjectMaterializerNull() - { - Assert.That(() => CsvParser.LoadFromCsvFile(null, testFile).ToList(), Throws.ArgumentNullException); - } + [Test] + public void ThrowsExceptionWhenObjectMaterializerNotValid() + { + var loader = new ObjectMaterializer(); + Assert.That(() => loader.LoadFromCsvFile(testFile).ToList(), Throws.InstanceOf()); + } - [Test] - public void ThrowsExceptionWhenObjectMaterializerNotValid() - { - var loader = new ObjectMaterializer(); - Assert.That(() => loader.LoadFromCsvFile(testFile).ToList(), Throws.InstanceOf()); - } + [Test] + public void ThrowsExceptionWhenFileNameNull() + { + var loader = new ObjectMaterializer(); + Assert.That(() => loader.LoadFromCsvFile(null).ToList(), Throws.ArgumentException); + } - [Test] - public void ThrowsExceptionWhenFileNameNull() - { - var loader = new ObjectMaterializer(); - Assert.That(() => loader.LoadFromCsvFile(null).ToList(), Throws.ArgumentException); - } + [Test] + public void ThrowsExceptionWhenFileNameEmpty() + { + var loader = new ObjectMaterializer(); + Assert.That(() => loader.LoadFromCsvFile("").ToList(), Throws.ArgumentException); + } - [Test] - public void ThrowsExceptionWhenFileNameEmpty() - { - var loader = new ObjectMaterializer(); - Assert.That(() => loader.LoadFromCsvFile("").ToList(), Throws.ArgumentException); - } + [Test] + public void ThrowsExceptionWhenFileNameContainsOnlySpaces() + { + var loader = new ObjectMaterializer(); + Assert.That(() => loader.LoadFromCsvFile(" ").ToList(), Throws.ArgumentException); + } - [Test] - public void ThrowsExceptionWhenFileNameContainsOnlySpaces() + [Test] + public void ThrowsExceptionWhenNumberOfItemsDoesntMatchWithHeader() + { + using (StreamWriter writer = File.CreateText(testFile)) { - var loader = new ObjectMaterializer(); - Assert.That(() => loader.LoadFromCsvFile(" ").ToList(), Throws.ArgumentException); + writer.WriteLine("name;age"); //<- header contains name and age + writer.WriteLine("Barry;39;20"); } - [Test] - public void ThrowsExceptionWhenNumberOfItemsDoesntMatchWithHeader() - { - using (StreamWriter writer = File.CreateText(testFile)) - { - writer.WriteLine("name;age"); //<- header contains name and age - writer.WriteLine("Barry;39;20"); - } + var loader = new ObjectMaterializer(); + loader.Add("name", (entity, value) => entity.Name = value); + loader.Add("age", (entity, value) => entity.Age = int.Parse(value)); + Assert.That(() => loader.LoadFromCsvFile(testFile).Count(), Throws.InstanceOf()); // <- use count() to force the parser to run because it uses defered execution + } - var loader = new ObjectMaterializer(); - loader.Add("name", (entity, value) => entity.Name = value); - loader.Add("age", (entity, value) => entity.Age = int.Parse(value)); - Assert.That(() => loader.LoadFromCsvFile(testFile).Count(), Throws.InstanceOf()); // <- use count() to force the parser to run because it uses defered execution - } - - [Test] - public void ThrowsExceptionWhenMappedKeyDoesntExistInCsvHeader() + [Test] + public void ThrowsExceptionWhenMappedKeyDoesntExistInCsvHeader() + { + using (StreamWriter writer = File.CreateText(testFile)) { - using (StreamWriter writer = File.CreateText(testFile)) - { - writer.WriteLine("name;age"); //<- header contains name and age - writer.WriteLine("Barry;39;"); - } - - var loader = new ObjectMaterializer(); - loader.Add("name", (entity, value) => entity.Name = value); - loader.Add("ages", (entity, value) => entity.Age = int.Parse(value)); - Assert.That(() => loader.LoadFromCsvFile(testFile).Count(), Throws.InstanceOf()); // <- use count() to force the parser to run because it uses defered execution + writer.WriteLine("name;age"); //<- header contains name and age + writer.WriteLine("Barry;39;"); } - [Test] - public void CanParseTestFile() - { - using (StreamWriter writer = File.CreateText(testFile)) - { - writer.WriteLine("name;age"); //<- header contains name and age - writer.WriteLine("Anouar;31"); - writer.WriteLine("Barry;39"); - writer.WriteLine("Tom;48"); - writer.WriteLine("Remko;39"); - } + var loader = new ObjectMaterializer(); + loader.Add("name", (entity, value) => entity.Name = value); + loader.Add("ages", (entity, value) => entity.Age = int.Parse(value)); + Assert.That(() => loader.LoadFromCsvFile(testFile).Count(), Throws.InstanceOf()); // <- use count() to force the parser to run because it uses defered execution + } - var loader = new ObjectMaterializer(); - loader.Add("name", (entity, value) => entity.Name = value); - loader.Add("age", (entity, value) => entity.Age = int.Parse(value)); - List items = loader.LoadFromCsvFile(testFile).ToList(); - Assert.AreEqual(4, items.Count()); - Assert.AreEqual("Tom", items.ElementAt(2).Name); - Assert.AreEqual(48, items.ElementAt(2).Age); - } - - class Foo + [Test] + public void CanParseTestFile() + { + using (StreamWriter writer = File.CreateText(testFile)) { - public string Name { get; set; } - public int Age { get; set; } + writer.WriteLine("name;age"); //<- header contains name and age + writer.WriteLine("Anouar;31"); + writer.WriteLine("Barry;39"); + writer.WriteLine("Tom;48"); + writer.WriteLine("Remko;39"); } + + var loader = new ObjectMaterializer(); + loader.Add("name", (entity, value) => entity.Name = value); + loader.Add("age", (entity, value) => entity.Age = int.Parse(value)); + List items = loader.LoadFromCsvFile(testFile).ToList(); + Assert.AreEqual(4, items.Count()); + Assert.AreEqual("Tom", items.ElementAt(2).Name); + Assert.AreEqual(48, items.ElementAt(2).Age); } + + private class Foo + { + public string Name { get; set; } + public int Age { get; set; } + } } \ No newline at end of file Index: DamClients/DamUI/trunk/src/Dam/Forms/Properties/Resources.resx =================================================================== diff -u -r4070 -r4259 --- DamClients/DamUI/trunk/src/Dam/Forms/Properties/Resources.resx (.../Resources.resx) (revision 4070) +++ DamClients/DamUI/trunk/src/Dam/Forms/Properties/Resources.resx (.../Resources.resx) (revision 4259) @@ -134,4 +134,7 @@ PublicKeyToken=b03f5f7f11d50a3a + > + https://publicwiki.deltares.nl/display/DAM/Gebruikershandleiding+DAM+19.1 + \ No newline at end of file
+ /// The creation is performed in a separate method than where the are checked to + /// ensure the objects will be garbage collected. + ///
The creation is performed in a separate method than where the are checked to ensure the objects will be garbage collected.