aboutsummaryrefslogtreecommitdiff
path: root/Mammoth.Tests
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2017-05-10 20:11:39 +0100
committerMichael Williamson <mike@zwobble.org>2017-05-10 20:11:39 +0100
commitd46578f9c125e4700f0c8e1f4db3d896edb9cd92 (patch)
tree63fe2045daadce4d5d769173edc79f6efc52853c /Mammoth.Tests
parentc70ed0148f584d5fa23f1c553cd618bc3368dd3c (diff)
Add support for image converters
Diffstat (limited to 'Mammoth.Tests')
-rw-r--r--Mammoth.Tests/DocumentConverterTests.cs23
1 files changed, 23 insertions, 0 deletions
diff --git a/Mammoth.Tests/DocumentConverterTests.cs b/Mammoth.Tests/DocumentConverterTests.cs
index 416893f..5469e08 100644
--- a/Mammoth.Tests/DocumentConverterTests.cs
+++ b/Mammoth.Tests/DocumentConverterTests.cs
@@ -2,6 +2,7 @@
using System.IO;
using Xunit.Sdk;
using System;
+using System.Collections.Generic;
using System.Linq;
namespace Mammoth.Tests {
@@ -97,6 +98,28 @@ namespace Mammoth.Tests {
Directory.Delete(tempDirectory, recursive: true);
}
}
+
+ [Fact]
+ public void ImageConversionCanBeCustomised() {
+ AssertSuccessfulConversion(
+ ConvertToHtml("tiny-picture.docx", mammoth => mammoth.ImageConverter(ConvertImage)),
+ "<p><img src=\"iV,image/png\" /></p>"
+ );
+ }
+
+ private IDictionary<string, string> ConvertImage(IImage image) {
+ using (var stream = image.GetStream()) {
+ var base64 = StreamToBase64(stream);
+ var src = base64.Substring(0, 2) + "," + image.ContentType;
+ return new Dictionary<string, string> { { "src", src } };
+ }
+ }
+
+ private static string StreamToBase64(System.IO.Stream stream) {
+ var memoryStream = new System.IO.MemoryStream();
+ stream.CopyTo(memoryStream);
+ return System.Convert.ToBase64String(memoryStream.ToArray());
+ }
[Fact]
public void ContentTypesAreRead() {