diff --git a/Directory.Build.props b/Directory.Build.props
index 668f8119..5166753d 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -50,15 +50,12 @@
-
-
-
-
+
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/README.md b/README.md
index f1ec01a8..66b15070 100644
--- a/README.md
+++ b/README.md
@@ -56,13 +56,14 @@ For more info, see also this WIKI page: [What is WireMock.Net](https://github.co
| **WireMock.Net.OpenApiParser** | [](https://www.nuget.org/packages/WireMock.Net.OpenApiParser) | [](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.OpenApiParser)
| **WireMock.Net.MimePart** | [](https://www.nuget.org/packages/WireMock.Net.MimePart) | [](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.MimePart)
| **WireMock.Net.GraphQL** | [](https://www.nuget.org/packages/WireMock.Net.GraphQL) | [](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.GraphQL)
+| **WireMock.Net.ProtoBuf** | [](https://www.nuget.org/packages/WireMock.Net.ProtoBuf) | [](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.ProtoBuf)
| | | |
| **WireMock.Net.RestClient** | [](https://www.nuget.org/packages/WireMock.Net.RestClient) | [](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.RestClient)
| **WireMock.Org.RestClient** | [](https://www.nuget.org/packages/WireMock.Org.RestClient) | [](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Org.RestClient)
-🔺 **WireMock.Net.Minimal** does not include *WireMock.Net.MimePart* and *WireMock.Net.GraphQL*.
+🔺 **WireMock.Net.Minimal** does not include *WireMock.Net.MimePart*, *WireMock.Net.GraphQL* and *WireMock.Net.ProtoBuf*.
---
diff --git a/WireMock.Net Solution.sln b/WireMock.Net Solution.sln
index 2fd76f42..89ca8789 100644
--- a/WireMock.Net Solution.sln
+++ b/WireMock.Net Solution.sln
@@ -142,6 +142,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.Extensions.Rou
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.Extensions.Routing", "src\WireMock.Net.Extensions.Routing\WireMock.Net.Extensions.Routing.csproj", "{1E874C8F-08A2-493B-8421-619F9A6E9E77}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.ProtoBuf", "src\WireMock.Net.ProtoBuf\WireMock.Net.ProtoBuf.csproj", "{B47413AA-55D3-49A7-896A-17ADBFF72407}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -344,6 +346,10 @@ Global
{1E874C8F-08A2-493B-8421-619F9A6E9E77}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1E874C8F-08A2-493B-8421-619F9A6E9E77}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1E874C8F-08A2-493B-8421-619F9A6E9E77}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B47413AA-55D3-49A7-896A-17ADBFF72407}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B47413AA-55D3-49A7-896A-17ADBFF72407}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B47413AA-55D3-49A7-896A-17ADBFF72407}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B47413AA-55D3-49A7-896A-17ADBFF72407}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -400,6 +406,7 @@ Global
{B6269AAC-170A-4346-8B9A-444DED3D9A45} = {8F890C6F-9ACC-438D-928A-AD61CDA862F2}
{3FCBCA9C-9DB0-4A96-B47E-30470764CC9C} = {0BB8B634-407A-4610-A91F-11586990767A}
{1E874C8F-08A2-493B-8421-619F9A6E9E77} = {8F890C6F-9ACC-438D-928A-AD61CDA862F2}
+ {B47413AA-55D3-49A7-896A-17ADBFF72407} = {8F890C6F-9ACC-438D-928A-AD61CDA862F2}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DC539027-9852-430C-B19F-FD035D018458}
diff --git a/src/WireMock.Net.Abstractions/IResponseMessage.cs b/src/WireMock.Net.Abstractions/IResponseMessage.cs
index 92cd2219..7951e2ed 100644
--- a/src/WireMock.Net.Abstractions/IResponseMessage.cs
+++ b/src/WireMock.Net.Abstractions/IResponseMessage.cs
@@ -15,12 +15,12 @@ public interface IResponseMessage
///
/// The Body.
///
- IBodyData? BodyData { get; }
+ IBodyData? BodyData { get; set; }
///
/// Gets the body destination (Null, SameAsSource, String or Bytes).
///
- string? BodyDestination { get; }
+ string? BodyDestination { get; set; }
///
/// Gets or sets the body.
@@ -30,27 +30,27 @@ public interface IResponseMessage
///
/// Gets the Fault percentage.
///
- double? FaultPercentage { get; }
+ double? FaultPercentage { get; set; }
///
/// The FaultType.
///
- FaultType FaultType { get; }
+ FaultType FaultType { get; set; }
///
/// Gets the headers.
///
- IDictionary>? Headers { get; }
+ IDictionary>? Headers { get; set; }
///
/// Gets the trailing headers.
///
- IDictionary>? TrailingHeaders { get; }
+ IDictionary>? TrailingHeaders { get; set; }
///
/// Gets or sets the status code.
///
- object? StatusCode { get; }
+ object? StatusCode { get; set; }
///
/// Adds the header.
diff --git a/src/WireMock.Net.Abstractions/WireMock.Net.Abstractions.csproj b/src/WireMock.Net.Abstractions/WireMock.Net.Abstractions.csproj
index 49e7fae7..0af7ecb7 100644
--- a/src/WireMock.Net.Abstractions/WireMock.Net.Abstractions.csproj
+++ b/src/WireMock.Net.Abstractions/WireMock.Net.Abstractions.csproj
@@ -38,9 +38,6 @@
-
-
-
all
@@ -50,34 +47,15 @@
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/WireMock.Net.Extensions.Routing/Delegates/WireMockHttpRequestHandler.cs b/src/WireMock.Net.Extensions.Routing/Delegates/WireMockHttpRequestHandler.cs
index d094aac8..83164bc4 100644
--- a/src/WireMock.Net.Extensions.Routing/Delegates/WireMockHttpRequestHandler.cs
+++ b/src/WireMock.Net.Extensions.Routing/Delegates/WireMockHttpRequestHandler.cs
@@ -7,4 +7,4 @@ namespace WireMock.Net.Extensions.Routing.Delegates;
///
/// The incoming request message.
/// A task that resolves to a .
-public delegate Task WireMockHttpRequestHandler(IRequestMessage requestMessage);
+public delegate Task WireMockHttpRequestHandler(IRequestMessage requestMessage);
diff --git a/src/WireMock.Net.Extensions.Routing/WireMockRouter.cs b/src/WireMock.Net.Extensions.Routing/WireMockRouter.cs
index 8661e314..297049eb 100644
--- a/src/WireMock.Net.Extensions.Routing/WireMockRouter.cs
+++ b/src/WireMock.Net.Extensions.Routing/WireMockRouter.cs
@@ -105,7 +105,7 @@ public sealed class WireMockRouter(WireMockServer server)
Func requestHandler) =>
request => CreateResponseMessageAsync(requestHandler(request));
- private static async Task CreateResponseMessageAsync(object? response)
+ private static async Task CreateResponseMessageAsync(object? response)
{
var awaitedResponse = response is Task task
? await task.ToGenericTaskAsync()
diff --git a/src/WireMock.Net.Minimal/Owin/Mappers/OwinResponseMapper.cs b/src/WireMock.Net.Minimal/Owin/Mappers/OwinResponseMapper.cs
index 41a8fc09..1bb412d4 100644
--- a/src/WireMock.Net.Minimal/Owin/Mappers/OwinResponseMapper.cs
+++ b/src/WireMock.Net.Minimal/Owin/Mappers/OwinResponseMapper.cs
@@ -177,11 +177,10 @@ namespace WireMock.Owin.Mappers
var jsonBody = JsonConvert.SerializeObject(bodyData.BodyAsJson, new JsonSerializerSettings { Formatting = formatting, NullValueHandling = NullValueHandling.Ignore });
return (bodyData.Encoding ?? _utf8NoBom).GetBytes(jsonBody);
-#if PROTOBUF
case BodyType.ProtoBuf:
var protoDefinitions = bodyData.ProtoDefinition?.Invoke().Texts;
- return await ProtoBufUtils.GetProtoBufMessageWithHeaderAsync(protoDefinitions, bodyData.ProtoBufMessageType, bodyData.BodyAsJson).ConfigureAwait(false);
-#endif
+ var protoBufUtils = TypeLoader.LoadStaticInstance();
+ return await protoBufUtils.GetProtoBufMessageWithHeaderAsync(protoDefinitions, bodyData.ProtoBufMessageType, bodyData.BodyAsJson).ConfigureAwait(false);
case BodyType.Bytes:
return bodyData.BodyAsBytes;
diff --git a/src/WireMock.Net.Minimal/RequestBuilders/Request.WithBodyAsProtoBuf.cs b/src/WireMock.Net.Minimal/RequestBuilders/Request.WithBodyAsProtoBuf.cs
deleted file mode 100644
index 395e472e..00000000
--- a/src/WireMock.Net.Minimal/RequestBuilders/Request.WithBodyAsProtoBuf.cs
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright © WireMock.Net
-
-using System;
-using System.Collections.Generic;
-using WireMock.Matchers;
-using WireMock.Matchers.Request;
-using WireMock.Models;
-
-namespace WireMock.RequestBuilders;
-
-public partial class Request
-{
- ///
- public IRequestBuilder WithBodyAsProtoBuf(string protoDefinition, string messageType, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
- {
- return WithBodyAsProtoBuf([protoDefinition], messageType, matchBehaviour);
- }
-
- ///
- public IRequestBuilder WithBodyAsProtoBuf(string protoDefinition, string messageType, IObjectMatcher matcher, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
- {
- return WithBodyAsProtoBuf([protoDefinition], messageType, matcher, matchBehaviour);
- }
-
- ///
- public IRequestBuilder WithBodyAsProtoBuf(IReadOnlyList protoDefinitions, string messageType, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
- {
- return Add(new RequestMessageProtoBufMatcher(matchBehaviour, () => new IdOrTexts(null, protoDefinitions), messageType));
- }
-
- ///
- public IRequestBuilder WithBodyAsProtoBuf(IReadOnlyList protoDefinitions, string messageType, IObjectMatcher matcher, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
- {
- return Add(new RequestMessageProtoBufMatcher(matchBehaviour, () => new IdOrTexts(null, protoDefinitions), messageType, matcher));
- }
-
- ///
- public IRequestBuilder WithBodyAsProtoBuf(string messageType, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
- {
- return Add(new RequestMessageProtoBufMatcher(matchBehaviour, ProtoDefinitionFunc(), messageType));
- }
-
- ///
- public IRequestBuilder WithBodyAsProtoBuf(string messageType, IObjectMatcher matcher, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
- {
- return Add(new RequestMessageProtoBufMatcher(matchBehaviour, ProtoDefinitionFunc(), messageType, matcher));
- }
-
- private Func ProtoDefinitionFunc()
- {
- return () =>
- {
- if (Mapping.ProtoDefinition == null)
- {
- throw new InvalidOperationException($"No ProtoDefinition defined on mapping '{Mapping.Guid}'. Please use the WireMockServerSettings to define ProtoDefinitions.");
- }
-
- return Mapping.ProtoDefinition.Value;
- };
- }
-}
\ No newline at end of file
diff --git a/src/WireMock.Net.Minimal/RequestBuilders/Request.cs b/src/WireMock.Net.Minimal/RequestBuilders/Request.cs
index 2b3f21ae..4071cf95 100644
--- a/src/WireMock.Net.Minimal/RequestBuilders/Request.cs
+++ b/src/WireMock.Net.Minimal/RequestBuilders/Request.cs
@@ -20,9 +20,7 @@ public partial class Request : RequestMessageCompositeMatcher, IRequestBuilder
{
private readonly IList _requestMatchers;
- ///
- /// The link back to the Mapping.
- ///
+ ///
public IMapping Mapping { get; set; } = null!;
///
@@ -73,6 +71,7 @@ public partial class Request : RequestMessageCompositeMatcher, IRequestBuilder
return _requestMatchers.OfType().FirstOrDefault(func);
}
+ ///
public IRequestBuilder Add(T requestMatcher) where T : IRequestMatcher
{
foreach (var existing in _requestMatchers.OfType().ToArray())
diff --git a/src/WireMock.Net.Minimal/ResponseBuilders/IResponseBuilder.cs b/src/WireMock.Net.Minimal/ResponseBuilders/IResponseBuilder.cs
deleted file mode 100644
index 2492cff2..00000000
--- a/src/WireMock.Net.Minimal/ResponseBuilders/IResponseBuilder.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright © WireMock.Net
-
-namespace WireMock.ResponseBuilders;
-
-///
-/// The ResponseBuilder interface.
-///
-public interface IResponseBuilder : IProxyResponseBuilder
-{
-}
\ No newline at end of file
diff --git a/src/WireMock.Net.Minimal/ResponseBuilders/Response.WithBody.cs b/src/WireMock.Net.Minimal/ResponseBuilders/Response.WithBody.cs
index 9c0aa7ed..f9a7d8ab 100644
--- a/src/WireMock.Net.Minimal/ResponseBuilders/Response.WithBody.cs
+++ b/src/WireMock.Net.Minimal/ResponseBuilders/Response.WithBody.cs
@@ -1,12 +1,10 @@
// Copyright © WireMock.Net
using System;
-using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using JsonConverter.Abstractions;
using Stef.Validation;
-using WireMock.Exceptions;
using WireMock.Models;
using WireMock.Types;
using WireMock.Util;
@@ -235,72 +233,4 @@ public partial class Response
return this;
}
-
- ///
- public IResponseBuilder WithBodyAsProtoBuf(
- string protoDefinition,
- string messageType,
- object value,
- IJsonConverter? jsonConverter = null,
- JsonConverterOptions? options = null
- )
- {
- return WithBodyAsProtoBuf([protoDefinition], messageType, value, jsonConverter, options);
- }
-
- ///
- public IResponseBuilder WithBodyAsProtoBuf(
- IReadOnlyList protoDefinitions,
- string messageType,
- object value,
- IJsonConverter? jsonConverter = null,
- JsonConverterOptions? options = null
- )
- {
- Guard.NotNullOrEmpty(protoDefinitions);
- Guard.NotNullOrWhiteSpace(messageType);
- Guard.NotNull(value);
-
-#if !PROTOBUF
- throw new NotSupportedException("The WithBodyAsProtoBuf method can not be used for .NETStandard1.3 or .NET Framework 4.6.1 or lower.");
-#else
- ResponseMessage.BodyDestination = null;
- ResponseMessage.BodyData = new BodyData
- {
- DetectedBodyType = BodyType.ProtoBuf,
- BodyAsJson = value,
- ProtoDefinition = () => new IdOrTexts(null, protoDefinitions),
- ProtoBufMessageType = messageType
- };
-
- return this;
-#endif
- }
-
- ///
- public IResponseBuilder WithBodyAsProtoBuf(
- string messageType,
- object value,
- IJsonConverter? jsonConverter = null,
- JsonConverterOptions? options = null
- )
- {
- Guard.NotNullOrWhiteSpace(messageType);
- Guard.NotNull(value);
-
-#if !PROTOBUF
- throw new NotSupportedException("The WithBodyAsProtoBuf method can not be used for .NETStandard1.3 or .NET Framework 4.6.1 or lower.");
-#else
- ResponseMessage.BodyDestination = null;
- ResponseMessage.BodyData = new BodyData
- {
- DetectedBodyType = BodyType.ProtoBuf,
- BodyAsJson = value,
- ProtoDefinition = () => Mapping.ProtoDefinition ?? throw new WireMockException("ProtoDefinition cannot be resolved. You probably forgot to call .WithProtoDefinition(...) on the mapping."),
- ProtoBufMessageType = messageType
- };
-
- return this;
-#endif
- }
}
\ No newline at end of file
diff --git a/src/WireMock.Net.Minimal/ResponseBuilders/Response.WithCallback.cs b/src/WireMock.Net.Minimal/ResponseBuilders/Response.WithCallback.cs
index cdfca99d..2782d9bf 100644
--- a/src/WireMock.Net.Minimal/ResponseBuilders/Response.WithCallback.cs
+++ b/src/WireMock.Net.Minimal/ResponseBuilders/Response.WithCallback.cs
@@ -13,13 +13,13 @@ public partial class Response
/// A delegate to execute to generate the response.
///
[MemberNotNullWhen(true, nameof(WithCallbackUsed))]
- public Func? Callback { get; private set; }
+ public Func? Callback { get; private set; }
///
/// A delegate to execute to generate the response async.
///
[MemberNotNullWhen(true, nameof(WithCallbackUsed))]
- public Func>? CallbackAsync { get; private set; }
+ public Func>? CallbackAsync { get; private set; }
///
/// Defines if the method WithCallback(...) is used.
@@ -27,7 +27,7 @@ public partial class Response
public bool WithCallbackUsed { get; private set; }
///
- public IResponseBuilder WithCallback(Func callbackHandler)
+ public IResponseBuilder WithCallback(Func callbackHandler)
{
Guard.NotNull(callbackHandler);
@@ -35,14 +35,14 @@ public partial class Response
}
///
- public IResponseBuilder WithCallback(Func> callbackHandler)
+ public IResponseBuilder WithCallback(Func> callbackHandler)
{
Guard.NotNull(callbackHandler);
return WithCallbackInternal(true, callbackHandler);
}
- private IResponseBuilder WithCallbackInternal(bool withCallbackUsed, Func callbackHandler)
+ private IResponseBuilder WithCallbackInternal(bool withCallbackUsed, Func callbackHandler)
{
Guard.NotNull(callbackHandler);
@@ -52,7 +52,7 @@ public partial class Response
return this;
}
- private IResponseBuilder WithCallbackInternal(bool withCallbackUsed, Func> callbackHandler)
+ private IResponseBuilder WithCallbackInternal(bool withCallbackUsed, Func> callbackHandler)
{
Guard.NotNull(callbackHandler);
diff --git a/src/WireMock.Net.Minimal/ResponseBuilders/Response.cs b/src/WireMock.Net.Minimal/ResponseBuilders/Response.cs
index 08713fa2..bcf98491 100644
--- a/src/WireMock.Net.Minimal/ResponseBuilders/Response.cs
+++ b/src/WireMock.Net.Minimal/ResponseBuilders/Response.cs
@@ -28,9 +28,7 @@ public partial class Response : IResponseBuilder
private TimeSpan? _delay;
- ///
- /// The link back to the mapping.
- ///
+ ///
public IMapping Mapping { get; set; } = null!;
///
@@ -81,10 +79,8 @@ public partial class Response : IResponseBuilder
///
public ReplaceNodeOptions TransformerReplaceNodeOptions { get; private set; }
- ///
- /// Gets the response message.
- ///
- public ResponseMessage ResponseMessage { get; }
+ ///
+ public IResponseMessage ResponseMessage { get; }
///
/// Creates this instance.
@@ -226,7 +222,7 @@ public partial class Response : IResponseBuilder
).ConfigureAwait(false);
}
- ResponseMessage responseMessage;
+ IResponseMessage responseMessage;
if (!WithCallbackUsed)
{
responseMessage = ResponseMessage;
diff --git a/src/WireMock.Net.Minimal/Serialization/MappingConverter.cs b/src/WireMock.Net.Minimal/Serialization/MappingConverter.cs
index f5c31a54..5819d7cc 100644
--- a/src/WireMock.Net.Minimal/Serialization/MappingConverter.cs
+++ b/src/WireMock.Net.Minimal/Serialization/MappingConverter.cs
@@ -126,12 +126,10 @@ internal class MappingConverter(MatcherMapper mapper)
}
}
-#if PROTOBUF
if (requestMessageProtoBufMatcher?.Matcher != null)
{
sb.AppendLine(" // .WithBodyAsProtoBuf() is not yet supported");
}
-#endif
if (requestMessageBodyMatcher?.Matchers != null)
{
@@ -188,7 +186,7 @@ internal class MappingConverter(MatcherMapper mapper)
sb.AppendLine($" .WithStatusCode({(int)httpStatusCode})");
}
- if (response.ResponseMessage.Headers is { })
+ if (response.ResponseMessage.Headers != null)
{
foreach (var header in response.ResponseMessage.Headers)
{
@@ -196,7 +194,7 @@ internal class MappingConverter(MatcherMapper mapper)
}
}
- if (response.ResponseMessage.TrailingHeaders is { })
+ if (response.ResponseMessage.TrailingHeaders != null)
{
foreach (var header in response.ResponseMessage.TrailingHeaders)
{
@@ -400,13 +398,11 @@ internal class MappingConverter(MatcherMapper mapper)
{
void AfterMap(MatcherModel matcherModel)
{
-#if PROTOBUF
// In case the ProtoDefinition is defined at the Mapping level, clear the Pattern at the Matcher level
- if (bodyMatchers?.OfType().Any() == true && mappingModel.ProtoDefinition != null)
+ if (bodyMatchers?.OfType().Any() == true && mappingModel.ProtoDefinition != null)
{
matcherModel.Pattern = null;
}
-#endif
}
mappingModel.Request.Body = new BodyModel();
diff --git a/src/WireMock.Net.Minimal/Serialization/MatcherMapper.cs b/src/WireMock.Net.Minimal/Serialization/MatcherMapper.cs
index 73d4c723..429ac679 100644
--- a/src/WireMock.Net.Minimal/Serialization/MatcherMapper.cs
+++ b/src/WireMock.Net.Minimal/Serialization/MatcherMapper.cs
@@ -80,10 +80,9 @@ internal class MatcherMapper
case "MimePartMatcher":
return CreateMimePartMatcher(matchBehaviour, matcherModel);
-#if PROTOBUF
- case nameof(ProtoBufMatcher):
+ case "ProtoBufMatcher":
return CreateProtoBufMatcher(matchBehaviour, stringPatterns.GetPatterns(), matcherModel);
-#endif
+
case nameof(RegexMatcher):
return new RegexMatcher(matchBehaviour, stringPatterns, ignoreCase, useRegexExtended, matchOperator);
@@ -210,7 +209,7 @@ internal class MatcherMapper
break;
#if PROTOBUF
- case ProtoBufMatcher protoBufMatcher:
+ case IProtoBufMatcher protoBufMatcher:
protoBufMatcher.ProtoDefinition().Value(id => model.Pattern = id, texts =>
{
if (texts.Count == 1)
@@ -286,17 +285,15 @@ internal class MatcherMapper
return TypeLoader.LoadNewInstance(matchBehaviour, contentTypeMatcher, contentDispositionMatcher, contentTransferEncodingMatcher, contentMatcher);
}
-#if PROTOBUF
- private ProtoBufMatcher CreateProtoBufMatcher(MatchBehaviour? matchBehaviour, IReadOnlyList protoDefinitions, MatcherModel matcher)
+ private IProtoBufMatcher CreateProtoBufMatcher(MatchBehaviour? matchBehaviour, IReadOnlyList protoDefinitions, MatcherModel matcher)
{
var objectMatcher = Map(matcher.ContentMatcher) as IObjectMatcher;
- return new ProtoBufMatcher(
- () => ProtoDefinitionHelper.GetIdOrTexts(_settings, protoDefinitions.ToArray()),
+ return TypeLoader.LoadNewInstance(
+ () => ProtoDefinitionUtils.GetIdOrTexts(_settings, protoDefinitions.ToArray()),
matcher.ProtoBufMessageType!,
matchBehaviour ?? MatchBehaviour.AcceptOnMatch,
objectMatcher
);
}
-#endif
}
\ No newline at end of file
diff --git a/src/WireMock.Net.Minimal/Server/RespondWithAProvider.cs b/src/WireMock.Net.Minimal/Server/RespondWithAProvider.cs
index 2dc4e07c..510252b8 100644
--- a/src/WireMock.Net.Minimal/Server/RespondWithAProvider.cs
+++ b/src/WireMock.Net.Minimal/Server/RespondWithAProvider.cs
@@ -356,12 +356,9 @@ internal class RespondWithAProvider : IRespondWithAProvider
{
Guard.NotNull(protoDefinitionOrId);
-#if PROTOBUF
- ProtoDefinition = ProtoDefinitionHelper.GetIdOrTexts(_settings, protoDefinitionOrId);
+ ProtoDefinition = ProtoDefinitionUtils.GetIdOrTexts(_settings, protoDefinitionOrId);
+
return this;
-#else
- throw new NotSupportedException("The WithProtoDefinition method can not be used for .NETStandard1.3 or .NET Framework 4.6.1 or lower.");
-#endif
}
///
diff --git a/src/WireMock.Net.Minimal/Server/WireMockServer.ConvertMapping.cs b/src/WireMock.Net.Minimal/Server/WireMockServer.ConvertMapping.cs
index 50d8c4e6..d345b057 100644
--- a/src/WireMock.Net.Minimal/Server/WireMockServer.ConvertMapping.cs
+++ b/src/WireMock.Net.Minimal/Server/WireMockServer.ConvertMapping.cs
@@ -241,13 +241,13 @@ public partial class WireMockServer
if (requestModel.Body?.Matcher != null)
{
var bodyMatcher = _matcherMapper.Map(requestModel.Body.Matcher)!;
-#if PROTOBUF
+
// If the BodyMatcher is a ProtoBufMatcher, and if ProtoDefinition is defined on Mapping-level, set the ProtoDefinition from that Mapping.
- if (bodyMatcher is ProtoBufMatcher protoBufMatcher && mappingModel?.ProtoDefinition != null)
+ if (bodyMatcher is IProtoBufMatcher protoBufMatcher && mappingModel?.ProtoDefinition != null)
{
- protoBufMatcher.ProtoDefinition = () => ProtoDefinitionHelper.GetIdOrTexts(_settings, mappingModel.ProtoDefinition);
+ protoBufMatcher.ProtoDefinition = () => ProtoDefinitionUtils.GetIdOrTexts(_settings, mappingModel.ProtoDefinition);
}
-#endif
+
requestBuilder = requestBuilder.WithBody(bodyMatcher);
}
else if (requestModel.Body?.Matchers != null)
@@ -368,18 +368,19 @@ public partial class WireMockServer
{
if (responseModel.ProtoBufMessageType != null)
{
+ var protoBufUtils = TypeLoader.LoadStaticInstance();
+
if (responseModel.ProtoDefinition != null)
{
- responseBuilder = responseBuilder.WithBodyAsProtoBuf(responseModel.ProtoDefinition, responseModel.ProtoBufMessageType, responseModel.BodyAsJson);
+ responseBuilder = protoBufUtils.UpdateResponseBuilder(responseBuilder, responseModel.ProtoBufMessageType, responseModel.BodyAsJson, responseModel.ProtoDefinition);
}
else if (responseModel.ProtoDefinitions != null)
{
- responseBuilder = responseBuilder.WithBodyAsProtoBuf(responseModel.ProtoDefinitions, responseModel.ProtoBufMessageType, responseModel.BodyAsJson);
+ responseBuilder = protoBufUtils.UpdateResponseBuilder(responseBuilder, responseModel.ProtoBufMessageType, responseModel.BodyAsJson, responseModel.ProtoDefinitions);
}
else
{
- // ProtoDefinition(s) is/are defined at Mapping/Server level
- responseBuilder = responseBuilder.WithBodyAsProtoBuf(responseModel.ProtoBufMessageType, responseModel.BodyAsJson);
+ responseBuilder = protoBufUtils.UpdateResponseBuilder(responseBuilder, responseModel.ProtoBufMessageType, responseModel.BodyAsJson);
}
}
else
diff --git a/src/WireMock.Net.Minimal/WireMock.Net.Minimal.csproj b/src/WireMock.Net.Minimal/WireMock.Net.Minimal.csproj
index f3fb103a..107dc10b 100644
--- a/src/WireMock.Net.Minimal/WireMock.Net.Minimal.csproj
+++ b/src/WireMock.Net.Minimal/WireMock.Net.Minimal.csproj
@@ -125,9 +125,9 @@
-
+
-
-
-
-
-
-
-
diff --git a/src/WireMock.Net.Minimal/Matchers/ProtoBufMatcher.cs b/src/WireMock.Net.ProtoBuf/Matchers/ProtoBufMatcher.cs
similarity index 89%
rename from src/WireMock.Net.Minimal/Matchers/ProtoBufMatcher.cs
rename to src/WireMock.Net.ProtoBuf/Matchers/ProtoBufMatcher.cs
index 12e0c61b..bbba63f3 100644
--- a/src/WireMock.Net.Minimal/Matchers/ProtoBufMatcher.cs
+++ b/src/WireMock.Net.ProtoBuf/Matchers/ProtoBufMatcher.cs
@@ -1,6 +1,5 @@
// Copyright © WireMock.Net
-#if PROTOBUF
using System;
using System.Threading;
using System.Threading.Tasks;
@@ -24,19 +23,13 @@ public class ProtoBufMatcher : IProtoBufMatcher
///
public MatchBehaviour MatchBehaviour { get; }
- ///
- /// The Func to define the proto definition as id or texts.
- ///
- public Func ProtoDefinition { get; internal set; }
+ ///
+ public Func ProtoDefinition { get; set; }
- ///
- /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}".
- ///
+ ///
public string MessageType { get; }
- ///
- /// The Matcher to use (optional).
- ///
+ ///
public IObjectMatcher? Matcher { get; }
private static readonly Converter ProtoBufToJsonConverter = SingletonFactory.GetInstance();
@@ -122,5 +115,4 @@ public class ProtoBufMatcher : IProtoBufMatcher
return null;
}
}
-}
-#endif
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/src/WireMock.Net.Minimal/Models/ProtoDefinitionData.cs b/src/WireMock.Net.ProtoBuf/Models/ProtoDefinitionData.cs
similarity index 100%
rename from src/WireMock.Net.Minimal/Models/ProtoDefinitionData.cs
rename to src/WireMock.Net.ProtoBuf/Models/ProtoDefinitionData.cs
diff --git a/src/WireMock.Net.ProtoBuf/Properties/AssemblyInfo.cs b/src/WireMock.Net.ProtoBuf/Properties/AssemblyInfo.cs
new file mode 100644
index 00000000..6bfd54d8
--- /dev/null
+++ b/src/WireMock.Net.ProtoBuf/Properties/AssemblyInfo.cs
@@ -0,0 +1,8 @@
+// Copyright © WireMock.Net
+
+using System.Runtime.CompilerServices;
+
+[assembly: InternalsVisibleTo("WireMock.Net.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")]
+
+// Needed for Moq in the UnitTest project
+// [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
\ No newline at end of file
diff --git a/src/WireMock.Net.ProtoBuf/RequestBuilders/IRequestBuilderExtensions.cs b/src/WireMock.Net.ProtoBuf/RequestBuilders/IRequestBuilderExtensions.cs
new file mode 100644
index 00000000..9771428f
--- /dev/null
+++ b/src/WireMock.Net.ProtoBuf/RequestBuilders/IRequestBuilderExtensions.cs
@@ -0,0 +1,108 @@
+// Copyright © WireMock.Net
+
+using System;
+using System.Collections.Generic;
+using WireMock.Matchers;
+using WireMock.Matchers.Request;
+using WireMock.Models;
+
+namespace WireMock.RequestBuilders;
+
+///
+/// IRequestBuilderExtensions extensions for ProtoBuf.
+///
+// ReSharper disable once InconsistentNaming
+public static class IRequestBuilderExtensions
+{
+ ///
+ /// WithBodyAsProtoBuf
+ ///
+ /// The .
+ /// The proto definition as text.
+ /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}".
+ /// The match behaviour. (default = "AcceptOnMatch")
+ /// The .
+ public static IRequestBuilder WithBodyAsProtoBuf(this IRequestBuilder requestBuilder, string protoDefinition, string messageType, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
+ {
+ return requestBuilder.WithBodyAsProtoBuf([protoDefinition], messageType, matchBehaviour);
+ }
+
+ ///
+ /// WithBodyAsProtoBuf
+ ///
+ /// The .
+ /// The proto definition as text.
+ /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}".
+ /// The matcher to use to match the ProtoBuf as (json) object.
+ /// The match behaviour. (default = "AcceptOnMatch")
+ /// The .
+ public static IRequestBuilder WithBodyAsProtoBuf(this IRequestBuilder requestBuilder, string protoDefinition, string messageType, IObjectMatcher matcher, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
+ {
+ return requestBuilder.WithBodyAsProtoBuf([protoDefinition], messageType, matcher, matchBehaviour);
+ }
+
+ ///
+ /// WithBodyAsProtoBuf
+ ///
+ /// The .
+ /// The proto definitions as text.
+ /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}".
+ /// The match behaviour. (default = "AcceptOnMatch")
+ /// The .
+ public static IRequestBuilder WithBodyAsProtoBuf(this IRequestBuilder requestBuilder, IReadOnlyList protoDefinitions, string messageType, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
+ {
+ return requestBuilder.Add(new RequestMessageProtoBufMatcher(matchBehaviour, () => new IdOrTexts(null, protoDefinitions), messageType));
+ }
+
+ ///
+ /// WithBodyAsProtoBuf
+ ///
+ /// The .
+ /// The proto definitions as text.
+ /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}".
+ /// The matcher to use to match the ProtoBuf as (json) object.
+ /// The match behaviour. (default = "AcceptOnMatch")
+ /// The .
+ public static IRequestBuilder WithBodyAsProtoBuf(this IRequestBuilder requestBuilder, IReadOnlyList protoDefinitions, string messageType, IObjectMatcher matcher, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
+ {
+ return requestBuilder.Add(new RequestMessageProtoBufMatcher(matchBehaviour, () => new IdOrTexts(null, protoDefinitions), messageType, matcher));
+ }
+
+ ///
+ /// WithBodyAsProtoBuf
+ ///
+ /// The .
+ /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}".
+ /// The match behaviour. (default = "AcceptOnMatch")
+ /// The .
+ public static IRequestBuilder WithBodyAsProtoBuf(this IRequestBuilder requestBuilder, string messageType, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
+ {
+ return requestBuilder.Add(new RequestMessageProtoBufMatcher(matchBehaviour, ProtoDefinitionFunc(requestBuilder), messageType));
+ }
+
+ ///
+ /// WithBodyAsProtoBuf
+ ///
+ /// The .
+ /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}".
+ /// The matcher to use to match the ProtoBuf as (json) object.
+ /// The match behaviour. (default = "AcceptOnMatch")
+ /// The .
+ public static IRequestBuilder WithBodyAsProtoBuf(this IRequestBuilder requestBuilder, string messageType, IObjectMatcher matcher, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
+ {
+ return requestBuilder.Add(new RequestMessageProtoBufMatcher(matchBehaviour, ProtoDefinitionFunc(requestBuilder), messageType, matcher));
+ }
+
+ private static Func ProtoDefinitionFunc(IRequestBuilder requestBuilder)
+ {
+ return () =>
+ {
+ if (requestBuilder.Mapping.ProtoDefinition == null)
+ {
+ throw new InvalidOperationException($"No ProtoDefinition defined on mapping '{requestBuilder.Mapping.Guid}'. Please use the WireMockServerSettings to define ProtoDefinitions.");
+ }
+
+ return requestBuilder.Mapping.ProtoDefinition.Value;
+ };
+ }
+}
\ No newline at end of file
diff --git a/src/WireMock.Net.ProtoBuf/ResponseBuilders/IResponseBuilderExtensions.cs b/src/WireMock.Net.ProtoBuf/ResponseBuilders/IResponseBuilderExtensions.cs
new file mode 100644
index 00000000..6bb68a44
--- /dev/null
+++ b/src/WireMock.Net.ProtoBuf/ResponseBuilders/IResponseBuilderExtensions.cs
@@ -0,0 +1,106 @@
+// Copyright © WireMock.Net
+
+using System.Collections.Generic;
+using JsonConverter.Abstractions;
+using Stef.Validation;
+using WireMock.Exceptions;
+using WireMock.Models;
+using WireMock.Types;
+using WireMock.Util;
+
+namespace WireMock.ResponseBuilders;
+
+///
+/// Extensions for to implement WithBodyAsProtoBuf.
+///
+public static class IResponseBuilderExtensions
+{
+ ///
+ /// WithBodyAsProtoBuf : Create a ProtoBuf byte[] response based on a proto definition, message type and the value.
+ ///
+ /// The response builder.
+ /// The proto definition as text.
+ /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}".
+ /// The object to convert to protobuf byte[].
+ /// The [optional]. Default value is NewtonsoftJsonConverter.
+ /// The [optional].
+ /// A .
+ public static IResponseBuilder WithBodyAsProtoBuf(
+ this IResponseBuilder responseBuilder,
+ string protoDefinition,
+ string messageType,
+ object value,
+ IJsonConverter? jsonConverter = null,
+ JsonConverterOptions? options = null
+ )
+ {
+ return responseBuilder.WithBodyAsProtoBuf([protoDefinition], messageType, value, jsonConverter, options);
+ }
+
+ ///
+ /// WithBodyAsProtoBuf : Create a ProtoBuf byte[] response based on proto definitions, message type and the value.
+ ///
+ /// The response builder.
+ /// The proto definition as text.
+ /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}".
+ /// The object to convert to protobuf byte[].
+ /// The [optional]. Default value is NewtonsoftJsonConverter.
+ /// The [optional].
+ /// A .
+ public static IResponseBuilder WithBodyAsProtoBuf(
+ this IResponseBuilder responseBuilder,
+ IReadOnlyList protoDefinitions,
+ string messageType,
+ object value,
+ IJsonConverter? jsonConverter = null,
+ JsonConverterOptions? options = null
+ )
+ {
+ Guard.NotNullOrEmpty(protoDefinitions);
+ Guard.NotNullOrWhiteSpace(messageType);
+ Guard.NotNull(value);
+
+ responseBuilder.ResponseMessage.BodyDestination = null;
+ responseBuilder.ResponseMessage.BodyData = new BodyData
+ {
+ DetectedBodyType = BodyType.ProtoBuf,
+ BodyAsJson = value,
+ ProtoDefinition = () => new IdOrTexts(null, protoDefinitions),
+ ProtoBufMessageType = messageType
+ };
+
+ return responseBuilder;
+ }
+
+ ///
+ /// WithBodyAsProtoBuf : Create a ProtoBuf byte[] response based on a proto definition, message type and the value.
+ ///
+ /// The response builder.
+ /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}".
+ /// The object to convert to protobuf byte[].
+ /// The [optional]. Default value is NewtonsoftJsonConverter.
+ /// The [optional].
+ /// A .
+ public static IResponseBuilder WithBodyAsProtoBuf(
+ this IResponseBuilder responseBuilder,
+ string messageType,
+ object value,
+ IJsonConverter? jsonConverter = null,
+ JsonConverterOptions? options = null
+ )
+ {
+ Guard.NotNullOrWhiteSpace(messageType);
+ Guard.NotNull(value);
+
+ responseBuilder.ResponseMessage.BodyDestination = null;
+ responseBuilder.ResponseMessage.BodyData = new BodyData
+ {
+ DetectedBodyType = BodyType.ProtoBuf,
+ BodyAsJson = value,
+ ProtoDefinition = () => responseBuilder.Mapping.ProtoDefinition ?? throw new WireMockException("ProtoDefinition cannot be resolved. You probably forgot to call .WithProtoDefinition(...) on the mapping."),
+ ProtoBufMessageType = messageType
+ };
+
+ return responseBuilder;
+ }
+}
\ No newline at end of file
diff --git a/src/WireMock.Net.Minimal/Util/ProtoBufUtils.cs b/src/WireMock.Net.ProtoBuf/Util/ProtoBufUtils.cs
similarity index 60%
rename from src/WireMock.Net.Minimal/Util/ProtoBufUtils.cs
rename to src/WireMock.Net.ProtoBuf/Util/ProtoBufUtils.cs
index a76d2171..591ae5b4 100644
--- a/src/WireMock.Net.Minimal/Util/ProtoBufUtils.cs
+++ b/src/WireMock.Net.ProtoBuf/Util/ProtoBufUtils.cs
@@ -1,18 +1,18 @@
// Copyright © WireMock.Net
-#if PROTOBUF
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using JsonConverter.Abstractions;
using ProtoBufJsonConverter;
using ProtoBufJsonConverter.Models;
+using WireMock.ResponseBuilders;
namespace WireMock.Util;
-internal static class ProtoBufUtils
+internal class ProtoBufUtils : IProtoBufUtils
{
- internal static async Task GetProtoBufMessageWithHeaderAsync(
+ public async Task GetProtoBufMessageWithHeaderAsync(
IReadOnlyList? protoDefinitions,
string? messageType,
object? value,
@@ -33,5 +33,15 @@ internal static class ProtoBufUtils
.GetInstance()
.ConvertAsync(request, cancellationToken).ConfigureAwait(false);
}
-}
-#endif
\ No newline at end of file
+
+ public IResponseBuilder UpdateResponseBuilder(IResponseBuilder responseBuilder, string protoBufMessageType, object bodyAsJson, params string[] protoDefinitions)
+ {
+ if (protoDefinitions.Length > 0)
+ {
+ return responseBuilder.WithBodyAsProtoBuf(protoDefinitions, protoBufMessageType, bodyAsJson);
+ }
+
+ // ProtoDefinition(s) is/are defined at Mapping/Server level
+ return responseBuilder.WithBodyAsProtoBuf(protoBufMessageType, bodyAsJson);
+ }
+}
\ No newline at end of file
diff --git a/src/WireMock.Net.Minimal/Util/ProtoDefinitionHelper.cs b/src/WireMock.Net.ProtoBuf/Util/ProtoDefinitionDataHelper.cs
similarity index 81%
rename from src/WireMock.Net.Minimal/Util/ProtoDefinitionHelper.cs
rename to src/WireMock.Net.ProtoBuf/Util/ProtoDefinitionDataHelper.cs
index d616abc2..1ba3c06f 100644
--- a/src/WireMock.Net.Minimal/Util/ProtoDefinitionHelper.cs
+++ b/src/WireMock.Net.ProtoBuf/Util/ProtoDefinitionDataHelper.cs
@@ -1,6 +1,5 @@
// Copyright © WireMock.Net
-#if PROTOBUF
using System.Collections.Generic;
using System.IO;
using System.Threading;
@@ -9,14 +8,13 @@ using ProtoBufJsonConverter;
using ProtoBufJsonConverter.Models;
using Stef.Validation;
using WireMock.Models;
-using WireMock.Settings;
namespace WireMock.Util;
///
/// Some helper methods for Proto Definitions.
///
-public static class ProtoDefinitionHelper
+internal static class ProtoDefinitionDataHelper
{
///
/// Builds a dictionary of ProtoDefinitions from a directory.
@@ -42,7 +40,7 @@ public static class ProtoDefinitionHelper
// Build comment and get content from file.
var comment = $"// {protoRelativePath}";
-#if NETSTANDARD2_0
+#if NETSTANDARD2_0 || NET462
var content = File.ReadAllText(filePath);
#else
var content = await File.ReadAllTextAsync(filePath, cancellationToken);
@@ -79,23 +77,4 @@ public static class ProtoDefinitionHelper
return new ProtoDefinitionData(fileNameMappedToProtoDefinition);
}
-
- internal static IdOrTexts GetIdOrTexts(WireMockServerSettings settings, params string[] protoDefinitionOrId)
- {
- switch (protoDefinitionOrId.Length)
- {
- case 1:
- var idOrText = protoDefinitionOrId[0];
- if (settings.ProtoDefinitions?.TryGetValue(idOrText, out var protoDefinitions) == true)
- {
- return new(idOrText, protoDefinitions);
- }
-
- return new(null, protoDefinitionOrId);
-
- default:
- return new(null, protoDefinitionOrId);
- }
- }
-}
-#endif
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/src/WireMock.Net.Minimal/Util/WireMockProtoFileResolver.cs b/src/WireMock.Net.ProtoBuf/Util/WireMockProtoFileResolver.cs
similarity index 91%
rename from src/WireMock.Net.Minimal/Util/WireMockProtoFileResolver.cs
rename to src/WireMock.Net.ProtoBuf/Util/WireMockProtoFileResolver.cs
index e81893f2..9366c542 100644
--- a/src/WireMock.Net.Minimal/Util/WireMockProtoFileResolver.cs
+++ b/src/WireMock.Net.ProtoBuf/Util/WireMockProtoFileResolver.cs
@@ -1,6 +1,5 @@
// Copyright © WireMock.Net
-#if PROTOBUF
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
@@ -30,10 +29,10 @@ internal class WireMockProtoFileResolver : IProtoFileResolver
foreach (var extraProtoDefinition in protoDefinitions)
{
- var firstNonEmptyLine = extraProtoDefinition.Split(['\r', '\n']).FirstOrDefault(l => !string.IsNullOrEmpty(l));
+ var firstNonEmptyLine = extraProtoDefinition.Split('\r', '\n').FirstOrDefault(l => !string.IsNullOrEmpty(l));
if (firstNonEmptyLine != null)
{
- if (TryGetValidPath(firstNonEmptyLine.TrimStart(['/', ' ']), out var validPath))
+ if (TryGetValidPath(firstNonEmptyLine.TrimStart('/', ' '), out var validPath))
{
_files.Add(validPath, extraProtoDefinition);
}
@@ -71,5 +70,4 @@ internal class WireMockProtoFileResolver : IProtoFileResolver
validPath = null;
return false;
}
-}
-#endif
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/src/WireMock.Net.ProtoBuf/WireMock.Net.ProtoBuf.csproj b/src/WireMock.Net.ProtoBuf/WireMock.Net.ProtoBuf.csproj
new file mode 100644
index 00000000..090808f1
--- /dev/null
+++ b/src/WireMock.Net.ProtoBuf/WireMock.Net.ProtoBuf.csproj
@@ -0,0 +1,37 @@
+
+
+
+ 1.10.1-preview-00
+ ProtoBuf and gRPC support for WireMock.Net
+ WireMock.Net.ProtoBuf
+ Stef Heyenrath
+ netstandard2.1;net462;net6.0;net8.0
+ true
+ wiremock;matchers;matcher;protobuf;grpc
+ WireMock
+ {B47413AA-55D3-49A7-896A-17ADBFF72407}
+ true
+ true
+ true
+ true
+ ../WireMock.Net/WireMock.Net.ruleset
+ true
+ ../WireMock.Net/WireMock.Net.snk
+
+ true
+ MIT
+
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/WireMock.Net.Minimal/Extensions/StringExtensions.cs b/src/WireMock.Net.Shared/Extensions/StringExtensions.cs
similarity index 100%
rename from src/WireMock.Net.Minimal/Extensions/StringExtensions.cs
rename to src/WireMock.Net.Shared/Extensions/StringExtensions.cs
diff --git a/src/WireMock.Net.Minimal/IMapping.cs b/src/WireMock.Net.Shared/IMapping.cs
similarity index 100%
rename from src/WireMock.Net.Minimal/IMapping.cs
rename to src/WireMock.Net.Shared/IMapping.cs
diff --git a/src/WireMock.Net.Shared/Matchers/IProtoBufMatcher.cs b/src/WireMock.Net.Shared/Matchers/IProtoBufMatcher.cs
index 9cd183ae..8c90c8d0 100644
--- a/src/WireMock.Net.Shared/Matchers/IProtoBufMatcher.cs
+++ b/src/WireMock.Net.Shared/Matchers/IProtoBufMatcher.cs
@@ -1,5 +1,8 @@
// Copyright © WireMock.Net
+using System;
+using WireMock.Models;
+
namespace WireMock.Matchers;
///
@@ -7,4 +10,18 @@ namespace WireMock.Matchers;
///
public interface IProtoBufMatcher : IDecodeBytesMatcher, IBytesMatcher
{
+ ///
+ /// The Func to define the proto definition as id or texts.
+ ///
+ Func ProtoDefinition { get; set; }
+
+ ///
+ /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}".
+ ///
+ string MessageType { get; }
+
+ ///
+ /// The Matcher to use (optional).
+ ///
+ IObjectMatcher? Matcher { get; }
}
\ No newline at end of file
diff --git a/src/WireMock.Net.Minimal/Matchers/Request/RequestMessageProtoBufMatcher.cs b/src/WireMock.Net.Shared/Matchers/Request/RequestMessageProtoBufMatcher.cs
similarity index 85%
rename from src/WireMock.Net.Minimal/Matchers/Request/RequestMessageProtoBufMatcher.cs
rename to src/WireMock.Net.Shared/Matchers/Request/RequestMessageProtoBufMatcher.cs
index 0f5f62ff..372bd906 100644
--- a/src/WireMock.Net.Minimal/Matchers/Request/RequestMessageProtoBufMatcher.cs
+++ b/src/WireMock.Net.Shared/Matchers/Request/RequestMessageProtoBufMatcher.cs
@@ -2,6 +2,7 @@
using System;
using WireMock.Models;
+using WireMock.Util;
namespace WireMock.Matchers.Request;
@@ -24,11 +25,7 @@ public class RequestMessageProtoBufMatcher : IRequestMatcher
/// The optional matcher to use to match the ProtoBuf as (json) object.
public RequestMessageProtoBufMatcher(MatchBehaviour matchBehaviour, Func protoDefinition, string messageType, IObjectMatcher? matcher = null)
{
-#if PROTOBUF
- Matcher = new ProtoBufMatcher(protoDefinition, messageType, matchBehaviour, matcher);
-#else
- throw new System.NotSupportedException("The ProtoBufMatcher can not be used for .NETStandard1.3 or .NET Framework 4.6.1 or lower.");
-#endif
+ Matcher = TypeLoader.LoadNewInstance(protoDefinition, messageType, matchBehaviour, matcher);
}
///
diff --git a/src/WireMock.Net.Minimal/Models/GraphQLSchemaDetails.cs b/src/WireMock.Net.Shared/Models/GraphQLSchemaDetails.cs
similarity index 100%
rename from src/WireMock.Net.Minimal/Models/GraphQLSchemaDetails.cs
rename to src/WireMock.Net.Shared/Models/GraphQLSchemaDetails.cs
diff --git a/src/WireMock.Net.Shared/Properties/AssemblyInfo.cs b/src/WireMock.Net.Shared/Properties/AssemblyInfo.cs
index 60438b3d..2b4ab3ad 100644
--- a/src/WireMock.Net.Shared/Properties/AssemblyInfo.cs
+++ b/src/WireMock.Net.Shared/Properties/AssemblyInfo.cs
@@ -5,6 +5,7 @@ using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("WireMock.Net.Minimal, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")]
[assembly: InternalsVisibleTo("WireMock.Net.MimePart, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")]
[assembly: InternalsVisibleTo("WireMock.Net.GraphQL, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")]
+[assembly: InternalsVisibleTo("WireMock.Net.ProtoBuf, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")]
[assembly: InternalsVisibleTo("WireMock.Net.Matchers.CSharpCode, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")]
// [assembly: InternalsVisibleTo("WireMock.Net.StandAlone, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")]
[assembly: InternalsVisibleTo("WireMock.Net.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")]
diff --git a/src/WireMock.Net.Shared/RequestBuilders/IBodyRequestBuilder.cs b/src/WireMock.Net.Shared/RequestBuilders/IBodyRequestBuilder.cs
index f720988f..f22c1b33 100644
--- a/src/WireMock.Net.Shared/RequestBuilders/IBodyRequestBuilder.cs
+++ b/src/WireMock.Net.Shared/RequestBuilders/IBodyRequestBuilder.cs
@@ -10,7 +10,7 @@ namespace WireMock.RequestBuilders;
///
/// The BodyRequestBuilder interface.
///
-public interface IBodyRequestBuilder : IProtoBufRequestBuilder
+public interface IBodyRequestBuilder : IMultiPartRequestBuilder
{
///
/// WithBody: IMatcher
diff --git a/src/WireMock.Net.Shared/RequestBuilders/IProtoBufRequestBuilder.cs b/src/WireMock.Net.Shared/RequestBuilders/IProtoBufRequestBuilder.cs
deleted file mode 100644
index c3908be7..00000000
--- a/src/WireMock.Net.Shared/RequestBuilders/IProtoBufRequestBuilder.cs
+++ /dev/null
@@ -1,67 +0,0 @@
-// Copyright © WireMock.Net
-
-using System.Collections.Generic;
-using WireMock.Matchers;
-
-namespace WireMock.RequestBuilders;
-
-///
-/// The ProtoBufRequestBuilder interface.
-///
-public interface IProtoBufRequestBuilder : IMultiPartRequestBuilder
-{
- ///
- /// WithBodyAsProtoBuf
- ///
- /// The proto definition as text.
- /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}".
- /// The match behaviour. (default = "AcceptOnMatch")
- /// The .
- IRequestBuilder WithBodyAsProtoBuf(string protoDefinition, string messageType, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
-
- ///
- /// WithBodyAsProtoBuf
- ///
- /// The proto definition as text.
- /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}".
- /// The matcher to use to match the ProtoBuf as (json) object.
- /// The match behaviour. (default = "AcceptOnMatch")
- /// The .
- IRequestBuilder WithBodyAsProtoBuf(string protoDefinition, string messageType, IObjectMatcher matcher, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
-
- ///
- /// WithBodyAsProtoBuf
- ///
- /// The proto definitions as text.
- /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}".
- /// The match behaviour. (default = "AcceptOnMatch")
- /// The .
- IRequestBuilder WithBodyAsProtoBuf(IReadOnlyList protoDefinitions, string messageType, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
-
- ///
- /// WithBodyAsProtoBuf
- ///
- /// The proto definitions as text.
- /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}".
- /// The matcher to use to match the ProtoBuf as (json) object.
- /// The match behaviour. (default = "AcceptOnMatch")
- /// The .
- IRequestBuilder WithBodyAsProtoBuf(IReadOnlyList protoDefinitions, string messageType, IObjectMatcher matcher, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
-
- ///
- /// WithBodyAsProtoBuf
- ///
- /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}".
- /// The match behaviour. (default = "AcceptOnMatch")
- /// The .
- IRequestBuilder WithBodyAsProtoBuf(string messageType, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
-
- ///
- /// WithBodyAsProtoBuf
- ///
- /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}".
- /// The matcher to use to match the ProtoBuf as (json) object.
- /// The match behaviour. (default = "AcceptOnMatch")
- /// The .
- IRequestBuilder WithBodyAsProtoBuf(string messageType, IObjectMatcher matcher, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
-}
\ No newline at end of file
diff --git a/src/WireMock.Net.Shared/RequestBuilders/IRequestBuilder.cs b/src/WireMock.Net.Shared/RequestBuilders/IRequestBuilder.cs
index 2ebe40f3..9f217d86 100644
--- a/src/WireMock.Net.Shared/RequestBuilders/IRequestBuilder.cs
+++ b/src/WireMock.Net.Shared/RequestBuilders/IRequestBuilder.cs
@@ -9,5 +9,16 @@ namespace WireMock.RequestBuilders;
///
public interface IRequestBuilder : IClientIPRequestBuilder
{
- public IRequestBuilder Add(T requestMatcher) where T : IRequestMatcher;
+ ///
+ /// Adds a request matcher to the builder.
+ ///
+ /// The type of the request matcher.
+ /// The request matcher to add.
+ /// The current instance.
+ IRequestBuilder Add(T requestMatcher) where T : IRequestMatcher;
+
+ ///
+ /// The link back to the Mapping.
+ ///
+ IMapping Mapping { get; set; }
}
\ No newline at end of file
diff --git a/src/WireMock.Net.Minimal/ResponseBuilders/BodyDestinationFormat.cs b/src/WireMock.Net.Shared/ResponseBuilders/BodyDestinationFormat.cs
similarity index 100%
rename from src/WireMock.Net.Minimal/ResponseBuilders/BodyDestinationFormat.cs
rename to src/WireMock.Net.Shared/ResponseBuilders/BodyDestinationFormat.cs
diff --git a/src/WireMock.Net.Minimal/ResponseBuilders/IBodyResponseBuilder.cs b/src/WireMock.Net.Shared/ResponseBuilders/IBodyResponseBuilder.cs
similarity index 69%
rename from src/WireMock.Net.Minimal/ResponseBuilders/IBodyResponseBuilder.cs
rename to src/WireMock.Net.Shared/ResponseBuilders/IBodyResponseBuilder.cs
index 758ea69a..a3ca1d0b 100644
--- a/src/WireMock.Net.Minimal/ResponseBuilders/IBodyResponseBuilder.cs
+++ b/src/WireMock.Net.Shared/ResponseBuilders/IBodyResponseBuilder.cs
@@ -1,7 +1,6 @@
// Copyright © WireMock.Net
using System;
-using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using JsonConverter.Abstractions;
@@ -84,7 +83,7 @@ public interface IBodyResponseBuilder : IFaultResponseBuilder
IResponseBuilder WithBodyAsJson(Func bodyFactory, Encoding? encoding = null);
///
- /// WithBodyAsJson : Create a ... response based on a async callback function.
+ /// WithBodyAsJson : Create a ... response based on an async callback function.
///
/// The async delegate to build the body.
/// The body encoding.
@@ -117,53 +116,4 @@ public interface IBodyResponseBuilder : IFaultResponseBuilder
/// The [optional].
/// A .
IResponseBuilder WithBody(object body, Encoding? encoding, IJsonConverter jsonConverter, JsonConverterOptions? options = null);
-
- ///
- /// WithBodyAsProtoBuf : Create a ProtoBuf byte[] response based on a proto definition, message type and the value.
- ///
- /// The proto definition as text.
- /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}".
- /// The object to convert to protobuf byte[].
- /// The [optional]. Default value is NewtonsoftJsonConverter.
- /// The [optional].
- /// A .
- IResponseBuilder WithBodyAsProtoBuf(
- string protoDefinition,
- string messageType,
- object value,
- IJsonConverter? jsonConverter = null,
- JsonConverterOptions? options = null
- );
-
- ///
- /// WithBodyAsProtoBuf : Create a ProtoBuf byte[] response based on proto definitions, message type and the value.
- ///
- /// The proto definition as text.
- /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}".
- /// The object to convert to protobuf byte[].
- /// The [optional]. Default value is NewtonsoftJsonConverter.
- /// The [optional].
- /// A .
- IResponseBuilder WithBodyAsProtoBuf(
- IReadOnlyList protoDefinitions,
- string messageType,
- object value,
- IJsonConverter? jsonConverter = null,
- JsonConverterOptions? options = null
- );
-
- ///
- /// WithBodyAsProtoBuf : Create a ProtoBuf byte[] response based on a proto definition, message type and the value.
- ///
- /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}".
- /// The object to convert to protobuf byte[].
- /// The [optional]. Default value is NewtonsoftJsonConverter.
- /// The [optional].
- /// A .
- IResponseBuilder WithBodyAsProtoBuf(
- string messageType,
- object value,
- IJsonConverter? jsonConverter = null,
- JsonConverterOptions? options = null
- );
}
\ No newline at end of file
diff --git a/src/WireMock.Net.Minimal/ResponseBuilders/ICallbackResponseBuilder.cs b/src/WireMock.Net.Shared/ResponseBuilders/ICallbackResponseBuilder.cs
similarity index 76%
rename from src/WireMock.Net.Minimal/ResponseBuilders/ICallbackResponseBuilder.cs
rename to src/WireMock.Net.Shared/ResponseBuilders/ICallbackResponseBuilder.cs
index 1eaf1148..5a927542 100644
--- a/src/WireMock.Net.Minimal/ResponseBuilders/ICallbackResponseBuilder.cs
+++ b/src/WireMock.Net.Shared/ResponseBuilders/ICallbackResponseBuilder.cs
@@ -17,12 +17,12 @@ public interface ICallbackResponseBuilder : IResponseProvider
///
/// The .
[PublicAPI]
- IResponseBuilder WithCallback(Func callbackHandler);
+ IResponseBuilder WithCallback(Func callbackHandler);
///
/// The async callback builder
///
/// The .
[PublicAPI]
- IResponseBuilder WithCallback(Func> callbackHandler);
+ IResponseBuilder WithCallback(Func> callbackHandler);
}
\ No newline at end of file
diff --git a/src/WireMock.Net.Minimal/ResponseBuilders/IDelayResponseBuilder.cs b/src/WireMock.Net.Shared/ResponseBuilders/IDelayResponseBuilder.cs
similarity index 100%
rename from src/WireMock.Net.Minimal/ResponseBuilders/IDelayResponseBuilder.cs
rename to src/WireMock.Net.Shared/ResponseBuilders/IDelayResponseBuilder.cs
diff --git a/src/WireMock.Net.Minimal/ResponseBuilders/IFaultRequestBuilder.cs b/src/WireMock.Net.Shared/ResponseBuilders/IFaultRequestBuilder.cs
similarity index 100%
rename from src/WireMock.Net.Minimal/ResponseBuilders/IFaultRequestBuilder.cs
rename to src/WireMock.Net.Shared/ResponseBuilders/IFaultRequestBuilder.cs
diff --git a/src/WireMock.Net.Minimal/ResponseBuilders/IHeadersResponseBuilder.cs b/src/WireMock.Net.Shared/ResponseBuilders/IHeadersResponseBuilder.cs
similarity index 100%
rename from src/WireMock.Net.Minimal/ResponseBuilders/IHeadersResponseBuilder.cs
rename to src/WireMock.Net.Shared/ResponseBuilders/IHeadersResponseBuilder.cs
diff --git a/src/WireMock.Net.Minimal/ResponseBuilders/IProxyResponseBuilder.cs b/src/WireMock.Net.Shared/ResponseBuilders/IProxyResponseBuilder.cs
similarity index 100%
rename from src/WireMock.Net.Minimal/ResponseBuilders/IProxyResponseBuilder.cs
rename to src/WireMock.Net.Shared/ResponseBuilders/IProxyResponseBuilder.cs
diff --git a/src/WireMock.Net.Shared/ResponseBuilders/IResponseBuilder.cs b/src/WireMock.Net.Shared/ResponseBuilders/IResponseBuilder.cs
new file mode 100644
index 00000000..73c35229
--- /dev/null
+++ b/src/WireMock.Net.Shared/ResponseBuilders/IResponseBuilder.cs
@@ -0,0 +1,19 @@
+// Copyright © WireMock.Net
+
+namespace WireMock.ResponseBuilders;
+
+///
+/// The ResponseBuilder interface.
+///
+public interface IResponseBuilder : IProxyResponseBuilder
+{
+ ///
+ /// The link back to the mapping.
+ ///
+ IMapping Mapping { get; }
+
+ ///
+ /// Gets the response message.
+ ///
+ IResponseMessage ResponseMessage { get; }
+}
\ No newline at end of file
diff --git a/src/WireMock.Net.Minimal/ResponseBuilders/IStatusCodeResponseBuilder.cs b/src/WireMock.Net.Shared/ResponseBuilders/IStatusCodeResponseBuilder.cs
similarity index 100%
rename from src/WireMock.Net.Minimal/ResponseBuilders/IStatusCodeResponseBuilder.cs
rename to src/WireMock.Net.Shared/ResponseBuilders/IStatusCodeResponseBuilder.cs
diff --git a/src/WireMock.Net.Minimal/ResponseBuilders/ITransformResponseBuilder.cs b/src/WireMock.Net.Shared/ResponseBuilders/ITransformResponseBuilder.cs
similarity index 100%
rename from src/WireMock.Net.Minimal/ResponseBuilders/ITransformResponseBuilder.cs
rename to src/WireMock.Net.Shared/ResponseBuilders/ITransformResponseBuilder.cs
diff --git a/src/WireMock.Net.Minimal/ResponseProviders/IResponseProvider.cs b/src/WireMock.Net.Shared/ResponseProviders/IResponseProvider.cs
similarity index 88%
rename from src/WireMock.Net.Minimal/ResponseProviders/IResponseProvider.cs
rename to src/WireMock.Net.Shared/ResponseProviders/IResponseProvider.cs
index b82b2730..81fa5ca6 100644
--- a/src/WireMock.Net.Minimal/ResponseProviders/IResponseProvider.cs
+++ b/src/WireMock.Net.Shared/ResponseProviders/IResponseProvider.cs
@@ -18,6 +18,6 @@ public interface IResponseProvider
/// The used mapping.
/// The request.
/// The WireMockServerSettings.
- /// The including a new (optional) .
+ /// The including a new (optional) .
Task<(IResponseMessage Message, IMapping? Mapping)> ProvideResponseAsync(IMapping mapping, IRequestMessage requestMessage, WireMockServerSettings settings);
}
\ No newline at end of file
diff --git a/src/WireMock.Net.Minimal/Settings/HandlebarsSettings.cs b/src/WireMock.Net.Shared/Settings/HandlebarsSettings.cs
similarity index 100%
rename from src/WireMock.Net.Minimal/Settings/HandlebarsSettings.cs
rename to src/WireMock.Net.Shared/Settings/HandlebarsSettings.cs
diff --git a/src/WireMock.Net.Minimal/Settings/HttpClientSettings.cs b/src/WireMock.Net.Shared/Settings/HttpClientSettings.cs
similarity index 100%
rename from src/WireMock.Net.Minimal/Settings/HttpClientSettings.cs
rename to src/WireMock.Net.Shared/Settings/HttpClientSettings.cs
diff --git a/src/WireMock.Net.Minimal/Settings/ProxyAndRecordSettings.cs b/src/WireMock.Net.Shared/Settings/ProxyAndRecordSettings.cs
similarity index 100%
rename from src/WireMock.Net.Minimal/Settings/ProxyAndRecordSettings.cs
rename to src/WireMock.Net.Shared/Settings/ProxyAndRecordSettings.cs
diff --git a/src/WireMock.Net.Minimal/Settings/ProxySaveMappingSetting.cs b/src/WireMock.Net.Shared/Settings/ProxySaveMappingSetting.cs
similarity index 100%
rename from src/WireMock.Net.Minimal/Settings/ProxySaveMappingSetting.cs
rename to src/WireMock.Net.Shared/Settings/ProxySaveMappingSetting.cs
diff --git a/src/WireMock.Net.Minimal/Settings/ProxySaveMappingSettings.cs b/src/WireMock.Net.Shared/Settings/ProxySaveMappingSettings.cs
similarity index 100%
rename from src/WireMock.Net.Minimal/Settings/ProxySaveMappingSettings.cs
rename to src/WireMock.Net.Shared/Settings/ProxySaveMappingSettings.cs
diff --git a/src/WireMock.Net.Minimal/Settings/ProxyUrlReplaceSettings.cs b/src/WireMock.Net.Shared/Settings/ProxyUrlReplaceSettings.cs
similarity index 100%
rename from src/WireMock.Net.Minimal/Settings/ProxyUrlReplaceSettings.cs
rename to src/WireMock.Net.Shared/Settings/ProxyUrlReplaceSettings.cs
diff --git a/src/WireMock.Net.Minimal/Settings/WebProxySettings.cs b/src/WireMock.Net.Shared/Settings/WebProxySettings.cs
similarity index 100%
rename from src/WireMock.Net.Minimal/Settings/WebProxySettings.cs
rename to src/WireMock.Net.Shared/Settings/WebProxySettings.cs
diff --git a/src/WireMock.Net.Minimal/Settings/WebhookSettings.cs b/src/WireMock.Net.Shared/Settings/WebhookSettings.cs
similarity index 100%
rename from src/WireMock.Net.Minimal/Settings/WebhookSettings.cs
rename to src/WireMock.Net.Shared/Settings/WebhookSettings.cs
diff --git a/src/WireMock.Net.Minimal/Settings/WireMockCertificateSettings.cs b/src/WireMock.Net.Shared/Settings/WireMockCertificateSettings.cs
similarity index 100%
rename from src/WireMock.Net.Minimal/Settings/WireMockCertificateSettings.cs
rename to src/WireMock.Net.Shared/Settings/WireMockCertificateSettings.cs
diff --git a/src/WireMock.Net.Minimal/Settings/WireMockServerSettings.cs b/src/WireMock.Net.Shared/Settings/WireMockServerSettings.cs
similarity index 99%
rename from src/WireMock.Net.Minimal/Settings/WireMockServerSettings.cs
rename to src/WireMock.Net.Shared/Settings/WireMockServerSettings.cs
index 8fb01e22..86f99f38 100644
--- a/src/WireMock.Net.Minimal/Settings/WireMockServerSettings.cs
+++ b/src/WireMock.Net.Shared/Settings/WireMockServerSettings.cs
@@ -14,6 +14,7 @@ using WireMock.RegularExpressions;
using WireMock.Types;
using System.Globalization;
using WireMock.Models;
+
#if USE_ASPNETCORE
using Microsoft.Extensions.DependencyInjection;
#endif
diff --git a/src/WireMock.Net.Minimal/Util/FilePathUtils.cs b/src/WireMock.Net.Shared/Util/FilePathUtils.cs
similarity index 100%
rename from src/WireMock.Net.Minimal/Util/FilePathUtils.cs
rename to src/WireMock.Net.Shared/Util/FilePathUtils.cs
diff --git a/src/WireMock.Net.Shared/Util/IProtoBufUtils.cs b/src/WireMock.Net.Shared/Util/IProtoBufUtils.cs
new file mode 100644
index 00000000..7170d6dd
--- /dev/null
+++ b/src/WireMock.Net.Shared/Util/IProtoBufUtils.cs
@@ -0,0 +1,19 @@
+// Copyright © WireMock.Net
+
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+using JsonConverter.Abstractions;
+using WireMock.ResponseBuilders;
+
+namespace WireMock.Util;
+
+///
+/// Defines the interface for ProtoBufUtils.
+///
+public interface IProtoBufUtils
+{
+ Task GetProtoBufMessageWithHeaderAsync(IReadOnlyList? protoDefinitions, string? messageType, object? value, IJsonConverter? jsonConverter = null, CancellationToken cancellationToken = default);
+
+ IResponseBuilder UpdateResponseBuilder(IResponseBuilder responseBuilder, string protoBufMessageType, object bodyAsJson, params string[] protoDefinitions);
+}
\ No newline at end of file
diff --git a/src/WireMock.Net.Shared/Util/ProtoDefinitionUtils.cs b/src/WireMock.Net.Shared/Util/ProtoDefinitionUtils.cs
new file mode 100644
index 00000000..a492a364
--- /dev/null
+++ b/src/WireMock.Net.Shared/Util/ProtoDefinitionUtils.cs
@@ -0,0 +1,30 @@
+// Copyright © WireMock.Net
+
+using WireMock.Models;
+using WireMock.Settings;
+
+namespace WireMock.Util;
+
+///
+/// Some helper methods for Proto Definitions.
+///
+public static class ProtoDefinitionUtils
+{
+ internal static IdOrTexts GetIdOrTexts(WireMockServerSettings settings, params string[] protoDefinitionOrId)
+ {
+ switch (protoDefinitionOrId.Length)
+ {
+ case 1:
+ var idOrText = protoDefinitionOrId[0];
+ if (settings.ProtoDefinitions?.TryGetValue(idOrText, out var protoDefinitions) == true)
+ {
+ return new(idOrText, protoDefinitions);
+ }
+
+ return new(null, protoDefinitionOrId);
+
+ default:
+ return new(null, protoDefinitionOrId);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/WireMock.Net.Minimal/Util/SingletonFactory.cs b/src/WireMock.Net.Shared/Util/SingletonFactory.cs
similarity index 100%
rename from src/WireMock.Net.Minimal/Util/SingletonFactory.cs
rename to src/WireMock.Net.Shared/Util/SingletonFactory.cs
diff --git a/src/WireMock.Net.Shared/WireMock.Net.Shared.csproj b/src/WireMock.Net.Shared/WireMock.Net.Shared.csproj
index 2e438c5e..2b01dd01 100644
--- a/src/WireMock.Net.Shared/WireMock.Net.Shared.csproj
+++ b/src/WireMock.Net.Shared/WireMock.Net.Shared.csproj
@@ -29,6 +29,18 @@
true
+
+ $(DefineConstants);NETSTANDARD;USE_ASPNETCORE
+
+
+
+ $(DefineConstants);USE_ASPNETCORE
+
+
+
+ $(DefineConstants);USE_ASPNETCORE;NET46
+
+
all
@@ -37,6 +49,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/WireMock.Net/WireMock.Net.csproj b/src/WireMock.Net/WireMock.Net.csproj
index 90b06baa..f07348a0 100644
--- a/src/WireMock.Net/WireMock.Net.csproj
+++ b/src/WireMock.Net/WireMock.Net.csproj
@@ -35,5 +35,6 @@
+
\ No newline at end of file
diff --git a/test/WireMock.Net.Tests/Grpc/ProtoBufUtilsTests.cs b/test/WireMock.Net.Tests/Grpc/ProtoBufUtilsTests.cs
index c8ff777c..aa1df07d 100644
--- a/test/WireMock.Net.Tests/Grpc/ProtoBufUtilsTests.cs
+++ b/test/WireMock.Net.Tests/Grpc/ProtoBufUtilsTests.cs
@@ -12,6 +12,8 @@ namespace WireMock.Net.Tests.Grpc;
public class ProtoBufUtilsTests
{
+ private static readonly IProtoBufUtils ProtoBufUtils = new ProtoBufUtils();
+
[Fact]
public async Task GetProtoBufMessageWithHeader_MultipleProtoFiles()
{
diff --git a/test/WireMock.Net.Tests/Grpc/ProtoDefinitionHelperTests.cs b/test/WireMock.Net.Tests/Grpc/ProtoDefinitionHelperTests.cs
index 7a501a25..c9c4c29d 100644
--- a/test/WireMock.Net.Tests/Grpc/ProtoDefinitionHelperTests.cs
+++ b/test/WireMock.Net.Tests/Grpc/ProtoDefinitionHelperTests.cs
@@ -12,6 +12,8 @@ namespace WireMock.Net.Tests.Grpc;
public class ProtoDefinitionHelperTests
{
+ private static readonly IProtoBufUtils ProtoBufUtils = new ProtoBufUtils();
+
[Fact]
public async Task FromDirectory_Greet_ShouldReturnModifiedProtoFiles()
{
@@ -21,7 +23,7 @@ public class ProtoDefinitionHelperTests
var expectedComment = $"// {expectedFilename}";
// Act
- var protoDefinitionData = await ProtoDefinitionHelper.FromDirectory(directory);
+ var protoDefinitionData = await ProtoDefinitionDataHelper.FromDirectory(directory);
var protoDefinitions = protoDefinitionData.ToList("greet");
// Assert
@@ -50,7 +52,7 @@ public class ProtoDefinitionHelperTests
var directory = Path.Combine(Directory.GetCurrentDirectory(), "Grpc", "ot");
// Act
- var protoDefinitionData = await ProtoDefinitionHelper.FromDirectory(directory);
+ var protoDefinitionData = await ProtoDefinitionDataHelper.FromDirectory(directory);
var protoDefinitions = protoDefinitionData.ToList("trace_service");
// Assert