From bc52c6d7cdd6797b77eee18963abff1792b6a65a Mon Sep 17 00:00:00 2001 From: "Fernando P. Najera Cano" Date: Thu, 21 Jul 2016 10:03:29 +0200 Subject: [PATCH 1/4] Avoid hiding methods --- src/Onion.SolutionParser.Parser/GlobalSectionParser.cs | 2 +- src/Onion.SolutionParser.Parser/ProjectParser.cs | 2 +- src/Onion.SolutionParser.Parser/SolutionItemParserBase.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Onion.SolutionParser.Parser/GlobalSectionParser.cs b/src/Onion.SolutionParser.Parser/GlobalSectionParser.cs index 861c677..3728fdb 100644 --- a/src/Onion.SolutionParser.Parser/GlobalSectionParser.cs +++ b/src/Onion.SolutionParser.Parser/GlobalSectionParser.cs @@ -14,7 +14,7 @@ public GlobalSectionParser(string solutionContents) : base (solutionContents) } - public new IEnumerable Parse() + public override IEnumerable Parse() { var match = GlobalPattern.Match(SolutionContents); while (match.Success) diff --git a/src/Onion.SolutionParser.Parser/ProjectParser.cs b/src/Onion.SolutionParser.Parser/ProjectParser.cs index a1ce85e..7396097 100644 --- a/src/Onion.SolutionParser.Parser/ProjectParser.cs +++ b/src/Onion.SolutionParser.Parser/ProjectParser.cs @@ -16,7 +16,7 @@ public ProjectParser(string solutionContents) : base(solutionContents) } - public new IEnumerable Parse() + public override IEnumerable Parse() { var match = ProjectPattern.Match(SolutionContents); while (match.Success) diff --git a/src/Onion.SolutionParser.Parser/SolutionItemParserBase.cs b/src/Onion.SolutionParser.Parser/SolutionItemParserBase.cs index af77a21..e334fca 100644 --- a/src/Onion.SolutionParser.Parser/SolutionItemParserBase.cs +++ b/src/Onion.SolutionParser.Parser/SolutionItemParserBase.cs @@ -12,7 +12,7 @@ protected SolutionItemParserBase(string solutionContents) SolutionContents = solutionContents; } - public new IEnumerable Parse() + public virtual IEnumerable Parse() { throw new System.NotImplementedException(); } From 5b8c7c3116bd48761ed23d07c5b8de97d4684c6f Mon Sep 17 00:00:00 2001 From: "Fernando P. Najera Cano" Date: Thu, 21 Jul 2016 10:16:48 +0200 Subject: [PATCH 2/4] Parse the header of the solution file --- .../HeaderParser.cs | 35 +++++++++++++++ .../Model/ISolution.cs | 1 + .../Model/Solution.cs | 1 + .../Onion.SolutionParser.Parser.csproj | 1 + .../SolutionParser.cs | 1 + .../Onion.SolutionParser.Tests.csproj | 1 + .../Parser/HeaderParserTest.cs | 44 +++++++++++++++++++ 7 files changed, 84 insertions(+) create mode 100644 src/Onion.SolutionParser.Parser/HeaderParser.cs create mode 100644 tests/Onion.SolutionParser.Tests/Parser/HeaderParserTest.cs diff --git a/src/Onion.SolutionParser.Parser/HeaderParser.cs b/src/Onion.SolutionParser.Parser/HeaderParser.cs new file mode 100644 index 0000000..f794d27 --- /dev/null +++ b/src/Onion.SolutionParser.Parser/HeaderParser.cs @@ -0,0 +1,35 @@ +using System.Collections.Generic; +using System.IO; + +namespace Onion.SolutionParser.Parser +{ + public class HeaderParser + { + private readonly string _solutionContents; + + public HeaderParser(string solutionContents) + { + _solutionContents = solutionContents; + } + + public IEnumerable Parse() + { + var result = new List(); + using (var sr = new StringReader(_solutionContents)) + { + var line = sr.ReadLine(); + while (line != null) + { + if (line.TrimStart().StartsWith("Project(") || line.TrimStart().StartsWith("Global(")) + { + break; + } + result.Add(line); + line = sr.ReadLine(); + } + } + return result; + } + + } +} diff --git a/src/Onion.SolutionParser.Parser/Model/ISolution.cs b/src/Onion.SolutionParser.Parser/Model/ISolution.cs index 8b2dd96..92e319b 100644 --- a/src/Onion.SolutionParser.Parser/Model/ISolution.cs +++ b/src/Onion.SolutionParser.Parser/Model/ISolution.cs @@ -4,6 +4,7 @@ namespace Onion.SolutionParser.Parser.Model { public interface ISolution { + IEnumerable Header { get; } IEnumerable Global { get; } IEnumerable Projects { get; } } diff --git a/src/Onion.SolutionParser.Parser/Model/Solution.cs b/src/Onion.SolutionParser.Parser/Model/Solution.cs index 69dc907..6927213 100644 --- a/src/Onion.SolutionParser.Parser/Model/Solution.cs +++ b/src/Onion.SolutionParser.Parser/Model/Solution.cs @@ -4,6 +4,7 @@ namespace Onion.SolutionParser.Parser.Model { public class Solution : ISolution { + public IEnumerable Header { get; set; } public IEnumerable Global { get; set; } public IEnumerable Projects { get; set; } } diff --git a/src/Onion.SolutionParser.Parser/Onion.SolutionParser.Parser.csproj b/src/Onion.SolutionParser.Parser/Onion.SolutionParser.Parser.csproj index 90fc6e3..974d666 100644 --- a/src/Onion.SolutionParser.Parser/Onion.SolutionParser.Parser.csproj +++ b/src/Onion.SolutionParser.Parser/Onion.SolutionParser.Parser.csproj @@ -40,6 +40,7 @@ + diff --git a/src/Onion.SolutionParser.Parser/SolutionParser.cs b/src/Onion.SolutionParser.Parser/SolutionParser.cs index b11658e..402470b 100644 --- a/src/Onion.SolutionParser.Parser/SolutionParser.cs +++ b/src/Onion.SolutionParser.Parser/SolutionParser.cs @@ -21,6 +21,7 @@ public ISolution Parse() { return new Solution { + Header = (new HeaderParser(_solutionContents)).Parse(), Global = (new GlobalSectionParser(_solutionContents)).Parse(), Projects = (new ProjectParser(_solutionContents)).Parse() }; diff --git a/tests/Onion.SolutionParser.Tests/Onion.SolutionParser.Tests.csproj b/tests/Onion.SolutionParser.Tests/Onion.SolutionParser.Tests.csproj index c6f9009..b43fc7a 100644 --- a/tests/Onion.SolutionParser.Tests/Onion.SolutionParser.Tests.csproj +++ b/tests/Onion.SolutionParser.Tests/Onion.SolutionParser.Tests.csproj @@ -45,6 +45,7 @@ + diff --git a/tests/Onion.SolutionParser.Tests/Parser/HeaderParserTest.cs b/tests/Onion.SolutionParser.Tests/Parser/HeaderParserTest.cs new file mode 100644 index 0000000..3323532 --- /dev/null +++ b/tests/Onion.SolutionParser.Tests/Parser/HeaderParserTest.cs @@ -0,0 +1,44 @@ +using System.Collections.Generic; +using System.Linq; +using NUnit.Framework; +using Onion.SolutionParser.Parser; + +namespace Onion.SolutionParser.Tests.Parser +{ + [TestFixture] + public class HeaderParserTest + { + public HeaderParser Parser { get; set; } + public string SolutionContents { get; set; } + + [TestFixtureSetUp] + public void BeforeAll() + { + SolutionContents = Utility.GetFixtureContents("NDriven.sln"); + } + + [SetUp] + public void BeforeEach() + { + Parser = new HeaderParser(SolutionContents); + } + + [Test] + public void Parse_should_return_IEnumerable_of_string_with_correct_count() + { + var lines = Parser.Parse(); + var count = lines.Count(); + Assert.IsInstanceOf>(lines); + Assert.AreEqual(3, count); + } + + [Test] + public void Parse_should_return_correct_lines() + { + var lines = Parser.Parse(); + Assert.AreEqual("", lines.ElementAt(0)); + Assert.AreEqual("Microsoft Visual Studio Solution File, Format Version 12.00", lines.ElementAt(1)); + Assert.AreEqual("# Visual Studio 2012", lines.ElementAt(2)); + } + } +} From 10ea908efce642a489d17c9a1a9e6689457214ca Mon Sep 17 00:00:00 2001 From: "Fernando P. Najera Cano" Date: Thu, 21 Jul 2016 10:47:48 +0200 Subject: [PATCH 3/4] Add a solution renderer --- .../ISolutionRenderer.cs | 7 ++ .../Onion.SolutionParser.Parser.csproj | 2 + .../SolutionRenderer.cs | 111 ++++++++++++++++++ .../Onion.SolutionParser.Tests.csproj | 1 + .../Renderer/SolutionRendererTest.cs | 34 ++++++ 5 files changed, 155 insertions(+) create mode 100644 src/Onion.SolutionParser.Parser/ISolutionRenderer.cs create mode 100644 src/Onion.SolutionParser.Parser/SolutionRenderer.cs create mode 100644 tests/Onion.SolutionParser.Tests/Renderer/SolutionRendererTest.cs diff --git a/src/Onion.SolutionParser.Parser/ISolutionRenderer.cs b/src/Onion.SolutionParser.Parser/ISolutionRenderer.cs new file mode 100644 index 0000000..b147b25 --- /dev/null +++ b/src/Onion.SolutionParser.Parser/ISolutionRenderer.cs @@ -0,0 +1,7 @@ +namespace Onion.SolutionParser.Parser +{ + public interface ISolutionRenderer + { + string Render(); + } +} diff --git a/src/Onion.SolutionParser.Parser/Onion.SolutionParser.Parser.csproj b/src/Onion.SolutionParser.Parser/Onion.SolutionParser.Parser.csproj index 974d666..591c590 100644 --- a/src/Onion.SolutionParser.Parser/Onion.SolutionParser.Parser.csproj +++ b/src/Onion.SolutionParser.Parser/Onion.SolutionParser.Parser.csproj @@ -43,6 +43,7 @@ + @@ -53,6 +54,7 @@ +