mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-19 06:59:43 +02:00
Use latest ProtoBufJsonConverter to support WellKnownTypes (#1161)
* Use latest ProtoBufJsonConverter to support WellKnownTypes * Fix * 02 * WireMockServer_WithBodyAsProtoBuf_WithWellKnownTypes * . * extra test * 0.4.0-preview-06 * 7 * <PackageReference Include="ProtoBufJsonConverter" Version="0.4.0-preview-08" /> * Update README.md * <PackageReference Include="ProtoBufJsonConverter" Version="0.4.0-preview-09" /> * <PackageReference Include="ProtoBufJsonConverter" Version="0.4.0" /> * Update README.md
This commit is contained in:
46
src/WireMock.Net/Util/WireMockProtoFileResolver.cs
Normal file
46
src/WireMock.Net/Util/WireMockProtoFileResolver.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
#if PROTOBUF
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using ProtoBufJsonConverter;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Util;
|
||||
|
||||
internal class WireMockProtoFileResolver : IProtoFileResolver
|
||||
{
|
||||
private readonly Dictionary<string, string> _files = new();
|
||||
|
||||
public WireMockProtoFileResolver(IReadOnlyCollection<string> protoDefinitions)
|
||||
{
|
||||
if (Guard.NotNullOrEmpty(protoDefinitions).Count() > 1)
|
||||
{
|
||||
foreach (var extraProtoDefinition in protoDefinitions.Skip(1))
|
||||
{
|
||||
var firstNonEmptyLine = extraProtoDefinition.Split(['\r', '\n']).FirstOrDefault(l => !string.IsNullOrEmpty(l));
|
||||
if (firstNonEmptyLine != null)
|
||||
{
|
||||
_files.Add(firstNonEmptyLine.TrimStart(['\r', '\n', '/', ' ']), extraProtoDefinition);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Exists(string path)
|
||||
{
|
||||
return _files.ContainsKey(path);
|
||||
}
|
||||
|
||||
public TextReader OpenText(string path)
|
||||
{
|
||||
if (_files.TryGetValue(path, out var extraProtoDefinition))
|
||||
{
|
||||
return new StringReader(extraProtoDefinition);
|
||||
}
|
||||
|
||||
throw new FileNotFoundException($"The ProtoDefinition '{path}' was not found.");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user