From bc8e97ca3f5b2f725b23897d32d3578466c381cd Mon Sep 17 00:00:00 2001 From: kevm Date: Thu, 5 Apr 2012 10:58:41 -0500 Subject: [PATCH] Added start of parser to be used by Htmlization of history items --- .../Dovetail.SDK.Bootstrap.Tests.csproj | 4 + .../history_parser.cs | 112 ++++++++++++++++++ .../packages.config | 3 +- .../Dovetail.SDK.Bootstrap.csproj | 8 +- .../History/HistoryParser.cs | 70 +++++++++++ source/Dovetail.SDK.Bootstrap/packages.config | 1 + source/Web/Web.csproj | 2 - 7 files changed, 196 insertions(+), 4 deletions(-) create mode 100644 source/Dovetail.SDK.Bootstrap.Tests/history_parser.cs create mode 100644 source/Dovetail.SDK.Bootstrap/History/HistoryParser.cs diff --git a/source/Dovetail.SDK.Bootstrap.Tests/Dovetail.SDK.Bootstrap.Tests.csproj b/source/Dovetail.SDK.Bootstrap.Tests/Dovetail.SDK.Bootstrap.Tests.csproj index 67ce5662..3b87265a 100644 --- a/source/Dovetail.SDK.Bootstrap.Tests/Dovetail.SDK.Bootstrap.Tests.csproj +++ b/source/Dovetail.SDK.Bootstrap.Tests/Dovetail.SDK.Bootstrap.Tests.csproj @@ -84,6 +84,9 @@ ..\packages\RhinoMocks.3.6\lib\Rhino.Mocks.dll + + ..\packages\Sprache.1.9.1.31\lib\NET40\Sprache.dll + ..\packages\structuremap.2.6.3\lib\StructureMap.dll @@ -101,6 +104,7 @@ + diff --git a/source/Dovetail.SDK.Bootstrap.Tests/history_parser.cs b/source/Dovetail.SDK.Bootstrap.Tests/history_parser.cs new file mode 100644 index 00000000..755c46e8 --- /dev/null +++ b/source/Dovetail.SDK.Bootstrap.Tests/history_parser.cs @@ -0,0 +1,112 @@ +using System.Linq; +using Dovetail.SDK.Bootstrap.History; +using NUnit.Framework; +using Sprache; + +namespace Dovetail.SDK.Bootstrap.Tests +{ + [TestFixture] + public class history_parser_document + { + [Test] + public void finds_all_items() + { + const string input = "item1\r\nitem2\nitem3"; + + var document = HistoryParser.Document.Parse(input); + + var items = document.Items.ToArray(); + items[0].ToString().ShouldEqual("item1"); + items[1].ToString().ShouldEqual("item2"); + items[2].ToString().ShouldEqual("item3"); + } + + [Test] + public void finds_email_headers_mixed_with_items() + { + const string input = "item1\r\nto: kmiller@dovetailsoftware.com\nitem3"; + + var document = HistoryParser.Document.Parse(input); + + var items = document.Items.ToArray(); + items[0].ToString().ShouldEqual("item1"); + + var emailHeaderItem = ((EmailHeader) items[1]).Headers.First(); + emailHeaderItem.ShouldEqual("to"); + emailHeaderItem.Text.ShouldEqual("kmiller@dovetailsoftware.com"); + + items[2].ToString().ShouldEqual("item3"); + } + } + + [TestFixture] + public class history_parser_items + { + [Test] + public void detect_item() + { + const string input = "line1\r\nline2"; + + var item = HistoryParser.Item.Parse(input); + + item.ToString().ShouldEqual("line1"); + } + + [Test] + public void item_white_space_is_removed() + { + const string input = " line1\r\n line2"; + + var item = HistoryParser.Item.Parse(input); + + item.ToString().ShouldEqual("line1"); + } + + [Test] + public void email_header_items_are_detected() + { + const string input = "from: yadda\nto:email@example.com\nsubject:math"; + + var item = HistoryParser.Item.Parse(input); + + var emailHeader = (item as EmailHeader); + emailHeader.ShouldNotBeNull(); + emailHeader.Headers.Count().ShouldEqual(3); + } + + [Test] + public void email_header_properties_are_populated() + { + const string input = "from: yadda\r\nan item"; + + var item = HistoryParser.Item.Parse(input); + + var emailHeaderItem = ((EmailHeader)item).Headers.First(); + emailHeaderItem.Title.ShouldEqual("from"); + emailHeaderItem.Text.ShouldEqual("yadda"); + } + + [Test] + public void email_header_titles_ignores_case() + { + const string input = "FROM: other content\r\nan item"; + + var item = HistoryParser.Item.Parse(input); + + var emailHeaderItem = ((EmailHeader)item).Headers.First(); + emailHeaderItem.Title.ShouldEqual("FROM"); + emailHeaderItem.Text.ShouldEqual("other content"); + } + + [Test] + public void item_similar_to_an_email_header_is_still_just_an_item() + { + const string input = "notaheader: yadda\r\nan item"; + + var item = HistoryParser.Item.Parse(input); + + (item as EmailHeader).ShouldBeNull(); + } + + } +} \ No newline at end of file diff --git a/source/Dovetail.SDK.Bootstrap.Tests/packages.config b/source/Dovetail.SDK.Bootstrap.Tests/packages.config index 2c9e2080..296a61bd 100644 --- a/source/Dovetail.SDK.Bootstrap.Tests/packages.config +++ b/source/Dovetail.SDK.Bootstrap.Tests/packages.config @@ -8,8 +8,9 @@ - + + \ No newline at end of file diff --git a/source/Dovetail.SDK.Bootstrap/Dovetail.SDK.Bootstrap.csproj b/source/Dovetail.SDK.Bootstrap/Dovetail.SDK.Bootstrap.csproj index ab12bcac..6d1a81d9 100644 --- a/source/Dovetail.SDK.Bootstrap/Dovetail.SDK.Bootstrap.csproj +++ b/source/Dovetail.SDK.Bootstrap/Dovetail.SDK.Bootstrap.csproj @@ -57,6 +57,9 @@ ..\packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll + + ..\packages\Sprache.1.9.1.31\lib\NET40\Sprache.dll + ..\packages\structuremap.2.6.3\lib\StructureMap.dll @@ -92,6 +95,7 @@ + @@ -123,7 +127,9 @@ - + + +