Create WireMock.Net.ProtoBuf project (#1350)

* Create WireMock.Net.ProtoBuf project

* ok

* Update Directory.Build.props

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Stef Heyenrath
2025-08-26 07:55:02 +02:00
committed by GitHub
parent 124d29c86a
commit e5c4605020
66 changed files with 478 additions and 416 deletions

View File

@@ -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<ProtoBufMatcher>().Any() == true && mappingModel.ProtoDefinition != null)
if (bodyMatchers?.OfType<IProtoBufMatcher>().Any() == true && mappingModel.ProtoDefinition != null)
{
matcherModel.Pattern = null;
}
#endif
}
mappingModel.Request.Body = new BodyModel();

View File

@@ -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<IMimePartMatcher>(matchBehaviour, contentTypeMatcher, contentDispositionMatcher, contentTransferEncodingMatcher, contentMatcher);
}
#if PROTOBUF
private ProtoBufMatcher CreateProtoBufMatcher(MatchBehaviour? matchBehaviour, IReadOnlyList<string> protoDefinitions, MatcherModel matcher)
private IProtoBufMatcher CreateProtoBufMatcher(MatchBehaviour? matchBehaviour, IReadOnlyList<string> protoDefinitions, MatcherModel matcher)
{
var objectMatcher = Map(matcher.ContentMatcher) as IObjectMatcher;
return new ProtoBufMatcher(
() => ProtoDefinitionHelper.GetIdOrTexts(_settings, protoDefinitions.ToArray()),
return TypeLoader.LoadNewInstance<IProtoBufMatcher>(
() => ProtoDefinitionUtils.GetIdOrTexts(_settings, protoDefinitions.ToArray()),
matcher.ProtoBufMessageType!,
matchBehaviour ?? MatchBehaviour.AcceptOnMatch,
objectMatcher
);
}
#endif
}