Skip to content

Commit

Permalink
Add 1st integration test
Browse files Browse the repository at this point in the history
Fix issue with image for md export
  • Loading branch information
alxnbl committed Mar 3, 2021
1 parent 49147cc commit d270b3e
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 12 deletions.
13 changes: 11 additions & 2 deletions src/alxnbl.OneNoteMdExporter.IntTests/Helpers/TestHelper.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;

namespace alxnbl.OneNoteMdExporter.IntTests.Helpers
{
public static class TestHelper
{
public static (string output, int exitCode) RunExporter(string args = "")
public static (string output, int exitCode, string exportResult) RunExporter(string format, string notebook, string section, string page)
{
string args = $"-f \"{format}\" -n \"{notebook}\" -s \"{section}\" -p \"{page}\" --no-input";

var startInfo = new ProcessStartInfo
{
Expand All @@ -33,9 +35,16 @@ public static (string output, int exitCode) RunExporter(string args = "")
output = exeProcess.StandardOutput.ReadToEnd();
}

return (output: output, exitCode: exeProcess.ExitCode);
string exportResult = format == "1" ? TestHelper.GetMdExportResult(notebook, section, page) : "";

return (output, exeProcess.ExitCode, exportResult);
}

}

public static string GetMdExportResult(string notebook, string section, string page)
{
return File.ReadAllText(Path.Combine(notebook, section, page + ".md"));
}
}
}
8 changes: 5 additions & 3 deletions src/alxnbl.OneNoteMdExporter.IntTests/JoplinExportTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using alxnbl.OneNoteMdExporter.IntTests.Helpers;
using NUnit.Framework;
using System;
using System.IO;
using System.Text.RegularExpressions;

namespace alxnbl.OneNoteMdExporter.IntTests
{
Expand All @@ -12,11 +14,11 @@ public void Setup()
}

[Test]
public void ExecArguments_NotebookNameNotFound()
public void Image_SimpleImage()
{
var res = TestHelper.RunExporter(" -n TestBloc");
var res = TestHelper.RunExporter("2", "TestBloc", "Image", "Simple image");

Assert.Pass();
throw new NotImplementedException();
}
}
}
30 changes: 30 additions & 0 deletions src/alxnbl.OneNoteMdExporter.IntTests/MarkdownExportTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using alxnbl.OneNoteMdExporter.IntTests.Helpers;
using NUnit.Framework;
using System.IO;
using System.Text.RegularExpressions;

namespace alxnbl.OneNoteMdExporter.IntTests
{
public class MarkdownExportTests
{
[SetUp]
public void Setup()
{
}

[Test]
public void Image_SimpleImage()
{
var res = TestHelper.RunExporter("1", "TestBloc", "Image", "Simple image");


// http://regexstorm.net/tester
string regexImgAttributes = "!\\[.*\\]\\((?<path>\\.\\./_resources/).*\\.png\\)";

MatchCollection matchs = Regex.Matches(res.exportResult, regexImgAttributes, RegexOptions.IgnoreCase);

Assert.AreEqual("../_resources/", matchs[0].Groups["path"].Value);

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<COMReference Include="Microsoft.Office.OneNote.dll">
<WrapperTool>tlbimp</WrapperTool>
<VersionMinor>1</VersionMinor>
<VersionMajor>1</VersionMajor>
<Guid>0ea692ee-bb50-4e3c-aef0-356d91732725</Guid>
<Lcid>0</Lcid>
<Isolated>false</Isolated>
</COMReference>
</ItemGroup>

<ItemGroup>
<!-- COMReference of OneNoteMdExporter not yet supported by DotNet5 -->
<PackageReference Include="Interop.Microsoft.Office.Interop.OneNote" Version="1.1.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
Expand Down
16 changes: 11 additions & 5 deletions src/alxnbl.OneNoteMdExporter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public class Options

[Option('p', "page", Required = false, HelpText = "The name of the section page to export. Apply only if section parameter used.")]
public string PageName { get; set; }

[Option("no-input", Required = false, HelpText = "Do not request user input")]
public bool NoInput { get; set; }
}


Expand Down Expand Up @@ -102,10 +105,11 @@ private static void RunOptions(Options opts)
Log.Information("");
}


Log.Information(Localizer.GetString("EndOfExport"));

Console.ReadLine();
if (!opts.NoInput)
{
Log.Information(Localizer.GetString("EndOfExport"));
Console.ReadLine();
}
}

private static ExportFormat ExportFormatSelectionForm(string optsExportFormat = "")
Expand All @@ -128,6 +132,8 @@ private static ExportFormat ExportFormatSelectionForm(string optsExportFormat =
return ExportFormat.Undefined;
}

Log.Debug($"Format choosen: {exportFormat}");

return exportFormat;
}

Expand Down Expand Up @@ -182,7 +188,7 @@ private static IList<Notebook> NotebookSelectionForm()
private static void InitLogger()
{
Log.Logger = new LoggerConfiguration()
.WriteTo.File("OneNoteMdExporter.log")
.WriteTo.File("alxnbl.OneNoteMdExporter.log", outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
.WriteTo.Console(Serilog.Events.LogEventLevel.Information, "{Message:lj}{NewLine}")
.CreateLogger();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private void ExportSection(Node section, string pageNameFilter="")

try
{
mdFileContent = _convertServer.ExtractImagesToResourceFolder(page, mdFileContent, resourceFolderPath, mdFilePath, true, _appSettings.PostProcessingMdImgRef);
mdFileContent = _convertServer.ExtractImagesToResourceFolder(page, mdFileContent, resourceFolderPath, mdFilePath, false, _appSettings.PostProcessingMdImgRef);
}
catch (Exception ex)
{
Expand Down

0 comments on commit d270b3e

Please sign in to comment.