Skip to content

Commit

Permalink
Start implementation for #22 and #21
Browse files Browse the repository at this point in the history
  • Loading branch information
Cloud-Awesome committed Apr 19, 2022
1 parent b81dc2c commit 3a09024
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="ConvertPocoToMarkdownTests.cs" />
<Compile Include="MdBoldTextTests.cs" />
<Compile Include="MdCodeBlockTests.cs" />
<Compile Include="MdCommentTests.cs" />
Expand All @@ -84,6 +85,7 @@
<Compile Include="MdTableRowTests.cs" />
<Compile Include="MdTableTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestDataModels\Persona.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CloudAwesome.MarkdownMaker\CloudAwesome.MarkdownMaker.csproj">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using CloudAwesome.MarkdownMaker.Tests.TestDataModels;
using NUnit.Framework;

namespace CloudAwesome.MarkdownMaker.Tests
{
public class ConvertPocoToMarkdownTests
{
[Test]
public void FirstTest()
{
var persona = new Persona
{
FirstName = "Pedro",
LastName = "Gumula",
Description = "This person is a sample person, which is very interesting"
};


}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace CloudAwesome.MarkdownMaker.Tests.TestDataModels
{
public class Persona: IDocumentMe
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Description { get; set; }
public DateTime DateOfBirth { get; set; }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Converters\PocoConverter.cs" />
<Compile Include="Exceptions\MdInputValidationException.cs" />
<Compile Include="IDocumentMe.cs" />
<Compile Include="IDocumentPart.cs" />
<Compile Include="IListPart.cs" />
<Compile Include="ISingleLinePart.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;

namespace CloudAwesome.MarkdownMaker.Converters
{
public static class PocoConverter
{
public static List<IDocumentPart> Convert(this IDocumentMe pocoClass)
{
throw new NotImplementedException();
}

public static List<IDocumentPart> Convert(this IEnumerable<IDocumentMe> pocoClasses)
{
throw new NotImplementedException();
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace CloudAwesome.MarkdownMaker
{
/// <summary>
/// Inherit from this to enable POCO to MD conversion
/// </summary>
public interface IDocumentMe { }
}
35 changes: 31 additions & 4 deletions src/CloudAwesome.Markdown/CloudAwesome.MarkdownMaker/MdDocument.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO.Abstractions;
using System.Text;
using CloudAwesome.MarkdownMaker.Converters;

namespace CloudAwesome.MarkdownMaker
{
Expand All @@ -17,12 +19,25 @@ public class MdDocument

private readonly IFileSystem _fileSystem;

public MdDocument(string fileName) : this(fileName, new FileSystem()) { }
public MdDocument(string fileName)
: this(fileName, new FileSystem()) { }

public MdDocument(string fileName, IDocumentMe pocoClass, IFileSystem fileSystem = null)
: this(fileName, new List<IDocumentMe>() { pocoClass }, fileSystem) { }

public MdDocument(string fileName, IEnumerable<IDocumentMe> pocoClasses,
IFileSystem fileSystem = null)
{
FileName = fileName;
_fileSystem = fileSystem ?? new FileSystem();

public MdDocument(string fileName, IFileSystem fileSystem)
DocumentParts = pocoClasses.Convert();
}

public MdDocument(string fileName, IFileSystem fileSystem = null)
{
FileName = fileName;
_fileSystem = fileSystem;
_fileSystem = fileSystem ?? new FileSystem();

DocumentParts = new List<IDocumentPart>();
}
Expand All @@ -32,7 +47,7 @@ public MdDocument Add(IDocumentPart documentPart)
DocumentParts.Add(documentPart);
return this;
}

public MdDocument Save()
{
_fileSystem.File.Delete(FileName);
Expand All @@ -44,5 +59,17 @@ public MdDocument Save()

return this;
}

public override string ToString()
{
var stringBuilder = new StringBuilder();

foreach (var documentPart in DocumentParts)
{
stringBuilder.Append(documentPart.Markdown + Environment.NewLine);
}

return stringBuilder.ToString();
}
}
}

0 comments on commit 3a09024

Please sign in to comment.