Skip to content

Commit

Permalink
convert word documentation builder to use native file system (#619)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericcmmi authored Sep 22, 2021
1 parent 83fb8f3 commit f2301bf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void ShouldOutputFeaturesInParsedOrder()

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

using (var stream = this.FileSystem.File.OpenRead(outputPath))
using (var stream = File.OpenRead(outputPath))
{
var doc = WordprocessingDocument.Open(stream, false);
var body = doc.MainDocumentPart.Document.Body;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// --------------------------------------------------------------------------------------------------------------------

using System;
using System.IO.Abstractions;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Xml.Linq;
Expand All @@ -41,38 +41,36 @@ public class WordDocumentationBuilder : IDocumentationBuilder
private readonly WordFeatureFormatter wordFeatureFormatter;
private readonly WordFontApplicator wordFontApplicator;
private readonly WordHeaderFooterFormatter wordHeaderFooterFormatter;

private readonly IFileSystem fileSystem;

private readonly WordStyleApplicator wordStyleApplicator;

public WordDocumentationBuilder(
IConfiguration configuration,
WordFeatureFormatter wordFeatureFormatter,
WordStyleApplicator wordStyleApplicator,
WordFontApplicator wordFontApplicator,
WordHeaderFooterFormatter wordHeaderFooterFormatter,
IFileSystem fileSystem)
WordHeaderFooterFormatter wordHeaderFooterFormatter)
{
this.configuration = configuration;
this.wordFeatureFormatter = wordFeatureFormatter;
this.wordStyleApplicator = wordStyleApplicator;
this.wordFontApplicator = wordFontApplicator;
this.wordHeaderFooterFormatter = wordHeaderFooterFormatter;
this.fileSystem = fileSystem;
}

public void Build(Tree features)
{
string filename = string.IsNullOrEmpty(this.configuration.SystemUnderTestName)
? "features.docx"
: this.configuration.SystemUnderTestName + ".docx";
string documentFileName = this.fileSystem.Path.Combine(this.configuration.OutputFolder.FullName, filename);
if (this.fileSystem.File.Exists(documentFileName))

Directory.CreateDirectory(this.configuration.OutputFolder.FullName);
string documentFileName = Path.Combine(this.configuration.OutputFolder.FullName, filename);

if (File.Exists(documentFileName))
{
try
{
this.fileSystem.File.Delete(documentFileName);
File.Delete(documentFileName);
}
catch (System.IO.IOException ex)
{
Expand All @@ -81,7 +79,7 @@ public void Build(Tree features)
}
}

using (var stream = this.fileSystem.File.Create(documentFileName))
using (var stream = new FileStream(documentFileName, FileMode.CreateNew))
using (
WordprocessingDocument wordProcessingDocument = WordprocessingDocument.Create(
stream,
Expand Down Expand Up @@ -114,7 +112,7 @@ public void Build(Tree features)
}

// HACK - Add the table of contents
using (var stream = this.fileSystem.File.Open(documentFileName, System.IO.FileMode.Open))
using (var stream = new FileStream(documentFileName, System.IO.FileMode.Open))
using (WordprocessingDocument wordProcessingDocument = WordprocessingDocument.Open(stream, true))
{
XElement firstPara = wordProcessingDocument
Expand Down

0 comments on commit f2301bf

Please sign in to comment.