Skip to content

Commit

Permalink
Update tests to launch on non-windows platform
Browse files Browse the repository at this point in the history
Update filesystem abstraction nuget package System.IO
Make related changes to tests: 
use IDirectoryInfo instead of DirectoryInfoBase, 
IFileSystemInfo instead of FileSystemInfoBase,
IFileInfo instead of FileInfoBase


Update DocumentFormat.OpenXML package, but still have xml-related error on MacOS during unit tests 
Use filesystem to build paths 
Do not use Windows-specific filepaths like "c:\file"
Use Environment.NewLine instead of \r\n

Update NFluent to compare strings thinking less of different line endings on different platforms

picklesdoc#609
  • Loading branch information
Andrey Leskov committed Sep 20, 2021
1 parent 9a33c3f commit bda6b18
Show file tree
Hide file tree
Showing 65 changed files with 508 additions and 361 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
<ProjectReference Include="..\Pickles\Pickles.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="NFluent" Version="2.2.0" />
<PackageReference Include="NFluent" Version="2.7.2" />
<PackageReference Include="NUnit" Version="3.13.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="2.1.0.178" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="13.2.47" />
</ItemGroup>
</Project>

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>



<specFlow>

<unitTestProvider name="NUnit" />

</specFlow>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" /></startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>PicklesDoc.Pickles.DocumentationBuilders.Cucumber.UnitTests</RootNamespace>
<AssemblyName>PicklesDoc.Pickles.DocumentationBuilders.Cucumber.UnitTests</AssemblyName>
Expand Down Expand Up @@ -26,13 +26,8 @@
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="NUnit" Version="3.13.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="SpecFlow" Version="3.7.38" />
</ItemGroup>
<ItemGroup>
<None Include="FormattingAFeature.feature">
<Generator>SpecFlowSingleFileGenerator</Generator>
<LastGenOutput>FormattingAFeature.feature.cs</LastGenOutput>
</None>
<PackageReference Include="SpecFlow.NUnit" Version="3.7.38" />
<PackageReference Include="System.IO.Abstractions" Version="13.2.47" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Pickles.DocumentationBuilders.Cucumber\Pickles.DocumentationBuilders.Cucumber.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Autofac" Version="4.8.0" />
<PackageReference Include="DocumentFormat.OpenXml" Version="2.10.1" />
<PackageReference Include="DocumentFormat.OpenXml" Version="2.13.1" />
<PackageReference Include="NLog" Version="4.5.3" />
<PackageReference Include="System.IO.Packaging" Version="5.0.0" />
<PackageReference Include="System.ServiceModel.Duplex" Version="4.8.1" />
<PackageReference Include="System.ServiceModel.NetTcp" Version="4.8.1" />
<PackageReference Include="System.ServiceModel.Federation" Version="4.8.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public HtmlDocumentFormatter(
this.fileSystem = fileSystem;
}

public XDocument Format(INode featureNode, Tree features, DirectoryInfoBase rootFolder)
public XDocument Format(INode featureNode, Tree features, IDirectoryInfo rootFolder)
{
XNamespace xmlns = HtmlNamespace.Xhtml;
string featureNodeOutputPath = this.fileSystem.Path.Combine(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public XElement Format(INode node, IEnumerable<INode> features)
</ul>
<div>
*/
var directoryInfo = node.OriginalLocation as DirectoryInfoBase;
var directoryInfo = node.OriginalLocation as IDirectoryInfo;

if (directoryInfo == null)
{
Expand All @@ -55,7 +55,7 @@ public XElement Format(INode node, IEnumerable<INode> features)
string[] files = directoryInfo.GetFiles().Select(f => f.FullName).ToArray();

INode[] featuresThatAreDirectChildrenOfFolder =
features.Where(f => f.OriginalLocation is FileInfoBase).Where(
features.Where(f => f.OriginalLocation is IFileInfo).Where(
f => files.Contains(f.OriginalLocation.FullName)).ToArray();

var div = new XElement(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ private XElement AddNodeForDirectory(XNamespace xmlns, Uri file, Tree childNode)
return xElement;
}

private XElement AddNodeForHome(XNamespace xmlns, Uri file, DirectoryInfoBase rootFolder)
private XElement AddNodeForHome(XNamespace xmlns, Uri file, IDirectoryInfo rootFolder)
{
var rootfile = this.fileSystem.FileInfo.FromFileName(this.fileSystem.Path.Combine(rootFolder.FullName, "index.html"));

var rootfile = (IFileInfo)this.fileSystem.FileInfo.FromFileName(this.fileSystem.Path.Combine(rootFolder.FullName, "index.html"));
var xElement = new XElement(xmlns + "li", new XAttribute("class", "file"), new XAttribute("id", "root"));

string nodeText = "Home";
Expand All @@ -105,7 +104,7 @@ private XElement AddNodeForHome(XNamespace xmlns, Uri file, DirectoryInfoBase ro
return xElement;
}

private bool DetermineWhetherFileIsTheRootFile(Uri file, FileInfoBase rootfile)
private bool DetermineWhetherFileIsTheRootFile(Uri file, IFileInfo rootfile)
{
var fileInfo = this.fileSystem.FileInfo.FromFileName(file.LocalPath);

Expand Down Expand Up @@ -171,7 +170,7 @@ private XElement BuildCollapser(XNamespace xmlns)
new XText("«"));
}

public XElement Format(Uri file, Tree features, DirectoryInfoBase outputFolder)
public XElement Format(Uri file, Tree features, IDirectoryInfo outputFolder)
{
XNamespace xmlns = HtmlNamespace.Xhtml;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

Scenario: Output is written to specified location

Given I specify the output folder as 'C:\testing'
Given I specify the output folder as 'testing'

When I generate Markdown output
Then the file 'C:\testing\features.md' exists

Then the file 'features.md' exists in folder 'testing'
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ namespace PicklesDoc.Pickles.DocumentationBuilders.Markdown.AcceptanceTests.Step
[Binding]
public sealed class MarkdownSteps : BaseFixture
{
private string filePath;

[Given(@"I specify the output folder as '(.*)'")]
public void Given_I_Specify_The_Output_File_As(string outputFolder)
{
Expand Down Expand Up @@ -125,10 +127,12 @@ public void Then_The_Markdown_Output_Has_The_Lines_In_The_Following_Order(Table
}
}

[Then(@"the file '(.*)' exists")]
public void Then_The_File_Exists(string expectedFile)
[Then(@"the file '(.*)' exists in folder '(.*)'")]

public void Then_The_File_Exists(string expectedFile, string expectedFolder)
{
Assert.IsTrue(this.FileSystem.File.Exists(expectedFile),string.Format("File \"{0}\" not found",expectedFile));
this.filePath = FileSystem.Path.Combine(expectedFolder,expectedFile);
Assert.IsTrue(this.FileSystem.File.Exists(this.filePath),string.Format("File \"{0}\" not found",filePath));
}

// Duplicated logic from Builder class, should be moved to it's own class?
Expand All @@ -139,11 +143,11 @@ private string TargetFile(IConfiguration configuration)
string defaultOutputFile = string.Empty;
if (configuration.OutputFolder == null)
{
defaultOutputFile = Path.Combine(@"C:\testing", fileName);
defaultOutputFile =FileSystem.Path.Combine(@"C:\testing", fileName);
}
else
{
defaultOutputFile = Path.Combine(configuration.OutputFolder.FullName, fileName);
defaultOutputFile =FileSystem.Path.Combine(configuration.OutputFolder.FullName, fileName);
}

return defaultOutputFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

using System;
using NUnit.Framework;
using PicklesDoc.Pickles.DocumentationBuilders.Markdown.Blocks;

Expand All @@ -34,7 +35,7 @@ public void ToString_Returns_Blocks_Markdown_Content()

(mockBlock as MockBlock).Add("Hello, World");

Assert.AreEqual("Hello, World\r\n", mockBlock.ToString());
Assert.AreEqual("Hello, World"+Environment.NewLine, mockBlock.ToString());
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

using System;
using NUnit.Framework;

namespace PicklesDoc.Pickles.DocumentationBuilders.Markdown.UnitTests
Expand Down Expand Up @@ -66,7 +67,7 @@ public void Converting_Lines_Object_To_String_Returns_All_Lines_With_NewLine_Sep
lines.Add("Hello");
lines.Add("World");

Assert.AreEqual("Hello\r\nWorld\r\n", lines.ToString());
Assert.AreEqual($"Hello{Environment.NewLine}World{Environment.NewLine}", lines.ToString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using PicklesDoc.Pickles.DirectoryCrawler;
using PicklesDoc.Pickles.ObjectModel;
using System;
using System.IO;
using System.IO.Abstractions;
using System.IO.Abstractions.TestingHelpers;
using System.Reflection;
Expand Down Expand Up @@ -58,12 +59,13 @@ public void Autofac_Can_Resolve_MarkdownDocumentationBuilder_Request()
[Test]
public void When_I_Build_Documentation_A_File_Is_Created()
{
var outputFolder = @"c:\output";
var defaultOutputFile = @"c:\output\features.md";
var outputFolder = "output";

var container = BuildContainer();
var configuration = container.Resolve<IConfiguration>();
var fileSystem = (MockFileSystem)container.Resolve<IFileSystem>();
var defaultOutputFile = fileSystem.Path.Combine("output","features.md");

configuration.OutputFolder = fileSystem.DirectoryInfo.FromDirectoryName(outputFolder);
var markdownDocumentationBuilder = container.Resolve<MarkdownDocumentationBuilder>();

Expand All @@ -75,7 +77,7 @@ public void When_I_Build_Documentation_A_File_Is_Created()
[Test]
public void When_I_Build_Documentation_Icon_Files_Are_Created()
{
var outputFolder = @"c:\output";
var outputFolder = "output";

var container = BuildContainer();
var configuration = container.Resolve<IConfiguration>();
Expand All @@ -85,16 +87,15 @@ public void When_I_Build_Documentation_Icon_Files_Are_Created()

markdownDocumentationBuilder.Build(null);

Assert.IsTrue(fileSystem.FileExists(@"c:\output\pass.png"));
Assert.IsTrue(fileSystem.FileExists(@"c:\output\fail.png"));
Assert.IsTrue(fileSystem.FileExists(@"c:\output\inconclusive.png"));
Assert.IsTrue(fileSystem.FileExists(fileSystem.Path.Combine("output","pass.png")));
Assert.IsTrue(fileSystem.FileExists(fileSystem.Path.Combine("output","fail.png")));
Assert.IsTrue(fileSystem.FileExists(fileSystem.Path.Combine("output","inconclusive.png")));
}

[Test]
public void With_A_Null_Tree_The_Output_Has_Default_Content()
{
var outputFolder = @"c:\output";
var defaultOutputFile = @"c:\output\features.md";
var outputFolder = "output";
var expectedFile = new string[]
{
"# Features",
Expand All @@ -105,6 +106,8 @@ public void With_A_Null_Tree_The_Output_Has_Default_Content()
var container = BuildContainer();
var configuration = container.Resolve<IConfiguration>();
var fileSystem = (MockFileSystem)container.Resolve<IFileSystem>();
var defaultOutputFile = fileSystem.Path.Combine("output","features.md");

configuration.OutputFolder = fileSystem.DirectoryInfo.FromDirectoryName(outputFolder);
var markdownDocumentationBuilder = container.Resolve<MarkdownDocumentationBuilder>();

Expand All @@ -121,8 +124,7 @@ public void With_A_Null_Tree_The_Output_Has_Default_Content()
[Test]
public void With_A_Simple_Feature_The_Output_Has_Default_Content()
{
var outputFolder = @"c:\output";
var defaultOutputFile = @"c:\output\features.md";
var outputFolder = "output";
var expectedFile = new string[]
{
"# Features",
Expand All @@ -136,13 +138,15 @@ public void With_A_Simple_Feature_The_Output_Has_Default_Content()
var container = BuildContainer();
var configuration = container.Resolve<IConfiguration>();
var fileSystem = (MockFileSystem)container.Resolve<IFileSystem>();
var defaultOutputFile = fileSystem.Path.Combine("output", "features.md");

configuration.OutputFolder = fileSystem.DirectoryInfo.FromDirectoryName(outputFolder);
var markdownDocumentationBuilder = container.Resolve<MarkdownDocumentationBuilder>();

var simpleFeature = new Feature();
simpleFeature.Name = "Simple Feature";
var relPath = "fakedir";
var location = fileSystem.FileInfo.FromFileName(@"c:\");
var location = fileSystem.FileInfo.FromFileName(fileSystem.Directory.GetCurrentDirectory());
var newNode = new FeatureNode(location, relPath, simpleFeature);
var featureTree = new Tree(new FolderNode(location, relPath));
featureTree.Add(newNode);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>PicklesDoc.Pickles.DocumentationBuilders.Markdown.UnitTests</RootNamespace>
<AssemblyName>PicklesDoc.Pickles.DocumentationBuilders.Markdown.UnitTests</AssemblyName>
Expand Down Expand Up @@ -30,10 +30,10 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
<PackageReference Include="NFluent" Version="2.2.0" />
<PackageReference Include="NFluent" Version="2.7.2" />
<PackageReference Include="NUnit" Version="3.13.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="SpecFlow.NUnit" Version="3.7.38" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="2.1.0.178" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="13.2.47" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ public MarkdownDocumentationBuilder(IFileSystem fileSystem, IConfiguration confi

if (configuration.OutputFolder == null)
{
outputFolder = @"C:\testing";
}
else
{
outputFolder = configuration.OutputFolder.FullName;
configuration.OutputFolder = fileSystem.DirectoryInfo.FromDirectoryName("testing");
}
if(!configuration.OutputFolder.Exists)
configuration.OutputFolder.Create();

outputFolder = configuration.OutputFolder.FullName;
}

public void Build(Tree featureTree)
{
var documentation = new Documentation(featureTree);

WriteContentToFile(TargetFile(), documentation.CurrentPage);
this.WriteContentToFile(fileSystem.Path.Combine(this.outputFolder, "features.md"), documentation.CurrentPage);

WriteImage(outputFolder, "pass_32.png", "pass.png");
WriteImage(outputFolder, "fail_32.png", "fail.png");
Expand All @@ -75,17 +75,6 @@ private void WriteContentToFile(string filePath, string content)
}
}

private string TargetFile()
{
var fileName = "features.md";

string defaultOutputFile = string.Empty;
defaultOutputFile = Path.Combine(outputFolder, fileName);

return defaultOutputFile;
}



private void WriteImage(string folder, string sourcefilename, string targetfilename)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
<PackageReference Include="System.IO.Abstractions" Version="2.1.0.178" />
<PackageReference Include="System.IO.Abstractions" Version="13.2.47" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ public class WhenBuildingWordDocuments : BaseFixture
{
private WordDocumentationBuilder builder;
private Tree features;
private const string RootPath = FileSystemPrefix + @"OrderingTests";
private string RootPath { get; }

public WhenBuildingWordDocuments()
{
this.RootPath =FileSystem.Path.Combine(FileSystemPrefix,"OrderingTests");
}

[SetUp]
public void Setup()
Expand Down Expand Up @@ -75,7 +80,7 @@ public void ShouldOutputFeaturesInParsedOrder()

this.builder.Build(this.features);

var outputPath = Path.Combine(Configuration.OutputFolder.FullName, "features.docx");
var outputPath =FileSystem.Path.Combine(Configuration.OutputFolder.FullName, "features.docx");

using (var stream = this.FileSystem.File.OpenRead(outputPath))
{
Expand Down
Loading

0 comments on commit bda6b18

Please sign in to comment.