mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-15 14:53:37 +01:00
* 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
67 lines
2.0 KiB
C#
67 lines
2.0 KiB
C#
// Copyright © WireMock.Net
|
|
|
|
#if PROTOBUF
|
|
using System.Collections.Generic;
|
|
using FluentAssertions;
|
|
using WireMock.Matchers;
|
|
using WireMock.Matchers.Request;
|
|
using WireMock.RequestBuilders;
|
|
using Xunit;
|
|
|
|
namespace WireMock.Net.Tests.RequestBuilders;
|
|
|
|
public class RequestBuilderWithProtoBufTests
|
|
{
|
|
private const string MessageType = "greet.HelloRequest";
|
|
private const string TestProtoDefinition = @"
|
|
syntax = ""proto3"";
|
|
|
|
package greet;
|
|
|
|
service Greeter {
|
|
rpc SayHello (HelloRequest) returns (HelloReply);
|
|
}
|
|
|
|
message HelloRequest {
|
|
string name = 1;
|
|
}
|
|
|
|
message HelloReply {
|
|
string message = 1;
|
|
}
|
|
";
|
|
|
|
[Fact]
|
|
public void RequestBuilder_WithGrpcProto_Without_JsonMatcher()
|
|
{
|
|
// Act
|
|
var requestBuilder = (Request)Request.Create().WithBodyAsProtoBuf(TestProtoDefinition, MessageType);
|
|
|
|
// Assert
|
|
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
|
matchers.Should().HaveCount(1);
|
|
|
|
var protoBufMatcher = (ProtoBufMatcher)((RequestMessageProtoBufMatcher)matchers[0]).Matcher!;
|
|
protoBufMatcher.ProtoDefinition().Texts.Should().Contain(TestProtoDefinition);
|
|
protoBufMatcher.MessageType.Should().Be(MessageType);
|
|
protoBufMatcher.Matcher.Should().BeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public void RequestBuilder_WithGrpcProto_With_JsonMatcher()
|
|
{
|
|
// Act
|
|
var jsonMatcher = new JsonMatcher(new { name = "stef" });
|
|
var requestBuilder = (Request)Request.Create().WithBodyAsProtoBuf(TestProtoDefinition, MessageType, jsonMatcher);
|
|
|
|
// Assert
|
|
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
|
matchers.Should().HaveCount(1);
|
|
|
|
var protoBufMatcher = (ProtoBufMatcher)((RequestMessageProtoBufMatcher)matchers[0]).Matcher!;
|
|
protoBufMatcher.ProtoDefinition().Texts.Should().Contain(TestProtoDefinition);
|
|
protoBufMatcher.MessageType.Should().Be(MessageType);
|
|
protoBufMatcher.Matcher.Should().BeOfType<JsonMatcher>();
|
|
}
|
|
}
|
|
#endif |