Skip to content

Commit

Permalink
Fix TestXmlReferenceResolver semantics for missing files
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Mar 8, 2021
1 parent 425dcad commit 67c220e
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
Expand All @@ -24,18 +25,28 @@ public override int GetHashCode()
return RuntimeHelpers.GetHashCode(this);
}

public override Stream? OpenRead(string resolvedPath)
public override Stream OpenRead(string resolvedPath)
{
if (resolvedPath is null)
{
throw new ArgumentNullException(nameof(resolvedPath));
}

if (!XmlReferences.TryGetValue(resolvedPath, out var content))
{
return null;
throw new IOException($"Unable to read XML file: {resolvedPath}");
}

return new MemoryStream(Encoding.UTF8.GetBytes(content));
}

public override string ResolveReference(string path, string baseFilePath)
public override string? ResolveReference(string path, string baseFilePath)
{
if (!XmlReferences.ContainsKey(path))
{
return null;
}

return path;
}
}
Expand Down

0 comments on commit 67c220e

Please sign in to comment.