diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-04-28 22:32:25 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-04-28 22:32:25 +0100 |
| commit | deaf4b7d433aeab4a422f1b875f802cad16b7014 (patch) | |
| tree | 9c4fcf22b6f75218d933867d275c5bb00e7a30e6 | |
| parent | f563dc02191e2261224077942f27ecbd70566b68 (diff) | |
Handle files not found
| -rw-r--r-- | dotnet/Mammoth.Tests/DocumentConverterTests.cs | 18 | ||||
| -rw-r--r-- | dotnet/Mammoth/Couscous/java/net/URL.cs | 2 |
2 files changed, 17 insertions, 3 deletions
diff --git a/dotnet/Mammoth.Tests/DocumentConverterTests.cs b/dotnet/Mammoth.Tests/DocumentConverterTests.cs index de1c37c..8526b04 100644 --- a/dotnet/Mammoth.Tests/DocumentConverterTests.cs +++ b/dotnet/Mammoth.Tests/DocumentConverterTests.cs @@ -2,6 +2,7 @@ using System.IO; using Xunit.Sdk; using System; +using System.Linq; namespace Mammoth.Tests { public class DocumentConverterTests { @@ -75,9 +76,20 @@ namespace Mammoth.Tests { } } - // TODO: image warnings - - + [Fact] + public void WarnIfImagesStoredOutsideOfDocumentAreNotFound() { + var tempDirectory = Path.Combine(Path.GetTempPath(), "mammoth-" + Guid.NewGuid()); + Directory.CreateDirectory(tempDirectory); + try { + var documentPath = Path.Combine(tempDirectory, "external-picture.docx"); + File.Copy(TestFilePath("external-picture.docx"), documentPath); + var result = new DocumentConverter().ConvertToHtml(documentPath); + Assert.Equal("", result.Value); + Assert.StartsWith("could not open external image 'tiny-picture.png':", result.Warnings.Single()); + } finally { + Directory.Delete(tempDirectory, recursive: true); + } + } [Fact] public void ContentTypesAreRead() { diff --git a/dotnet/Mammoth/Couscous/java/net/URL.cs b/dotnet/Mammoth/Couscous/java/net/URL.cs index af6e021..88479e8 100644 --- a/dotnet/Mammoth/Couscous/java/net/URL.cs +++ b/dotnet/Mammoth/Couscous/java/net/URL.cs @@ -20,6 +20,8 @@ namespace Mammoth.Couscous.java.net { } } catch (System.UriFormatException) { return ToJava.StreamToInputStream(System.IO.File.OpenRead(_url)); + } catch (System.Net.WebException exception) { + throw new java.io.IOException(exception.Message); } } } |
