mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-11 03:37:11 +02:00
Add Grpc ProtoBuf support (request-response) (#1047)
* ProtoBuf
* .
* x
* ---
* x
* fx
* ...
* sc
* ...
* .
* groen
* x
* fix tests
* ok!?
* fix tests
* fix tests
* !
* x
* 6
* .
* x
* ivaluematcher
* transformer
* .
* sc
* .
* mapping
* x
* tra
* com
* ...
* .
* .
* .
* AddProtoDefinition
* .
* set
* grpahj
* .
* .
* IdOrText
* ...
* async
* async2
* .
* t
* nuget
* <PackageReference Include="ProtoBufJsonConverter" Version="0.2.0-preview-04" />
* http version
* tests
* .WithHttpVersion("2")
* <PackageReference Include="ProtoBufJsonConverter" Version="0.2.0" />
* HttpVersionParser
This commit is contained in:
@@ -27,7 +27,7 @@ public class MatcherMapperTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MatcherMapper_Map_IMatcher_Null()
|
||||
public void MatcherMapper_Map_Matcher_IMatcher_Null()
|
||||
{
|
||||
// Act
|
||||
var model = _sut.Map((IMatcher?)null);
|
||||
@@ -37,7 +37,7 @@ public class MatcherMapperTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MatcherMapper_Map_IMatchers_Null()
|
||||
public void MatcherMapper_Map_Matcher_IMatchers_Null()
|
||||
{
|
||||
// Act
|
||||
var model = _sut.Map((IMatcher[]?)null);
|
||||
@@ -47,7 +47,7 @@ public class MatcherMapperTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MatcherMapper_Map_IMatchers()
|
||||
public void MatcherMapper_Map_Matcher_IMatchers()
|
||||
{
|
||||
// Assign
|
||||
var matcherMock1 = new Mock<IStringMatcher>();
|
||||
@@ -62,7 +62,7 @@ public class MatcherMapperTests
|
||||
|
||||
#if MIMEKIT
|
||||
[Fact]
|
||||
public void MatcherMapper_Map_MimePartMatcher()
|
||||
public void MatcherMapper_Map_Matcher_MimePartMatcher()
|
||||
{
|
||||
// Arrange
|
||||
var bytes = Convert.FromBase64String("c3RlZg==");
|
||||
@@ -95,7 +95,7 @@ public class MatcherMapperTests
|
||||
#endif
|
||||
|
||||
[Fact]
|
||||
public void MatcherMapper_Map_IStringMatcher()
|
||||
public void MatcherMapper_Map_Matcher_IStringMatcher()
|
||||
{
|
||||
// Assign
|
||||
var matcherMock = new Mock<IStringMatcher>();
|
||||
@@ -115,7 +115,7 @@ public class MatcherMapperTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MatcherMapper_Map_IStringMatcher_With_PatternAsFile()
|
||||
public void MatcherMapper_Map_Matcher_IStringMatcher_With_PatternAsFile()
|
||||
{
|
||||
// Arrange
|
||||
var pattern = new StringPattern { Pattern = "p", PatternAsFile = "pf" };
|
||||
@@ -136,7 +136,7 @@ public class MatcherMapperTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MatcherMapper_Map_IIgnoreCaseMatcher()
|
||||
public void MatcherMapper_Map_Matcher_IIgnoreCaseMatcher()
|
||||
{
|
||||
// Assign
|
||||
var matcherMock = new Mock<IIgnoreCaseMatcher>();
|
||||
@@ -150,7 +150,7 @@ public class MatcherMapperTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MatcherMapper_Map_XPathMatcher()
|
||||
public void MatcherMapper_Map_Matcher_XPathMatcher()
|
||||
{
|
||||
// Assign
|
||||
var xmlNamespaceMap = new[]
|
||||
@@ -171,7 +171,7 @@ public class MatcherMapperTests
|
||||
|
||||
#if GRAPHQL
|
||||
[Fact]
|
||||
public void MatcherMapper_Map_GraphQLMatcher()
|
||||
public void MatcherMapper_Map_Matcher_GraphQLMatcher()
|
||||
{
|
||||
// Assign
|
||||
const string testSchema = @"
|
||||
@@ -199,6 +199,87 @@ public class MatcherMapperTests
|
||||
}
|
||||
#endif
|
||||
|
||||
#if PROTOBUF
|
||||
[Fact]
|
||||
public void MatcherMapper_Map_Matcher_ProtoBufMatcher()
|
||||
{
|
||||
// Arrange
|
||||
IdOrText protoDefinition = new(null, @"
|
||||
syntax = ""proto3"";
|
||||
|
||||
package greet;
|
||||
|
||||
service Greeter {
|
||||
rpc SayHello (HelloRequest) returns (HelloReply);
|
||||
}
|
||||
|
||||
message HelloRequest {
|
||||
string name = 1;
|
||||
}
|
||||
|
||||
message HelloReply {
|
||||
string message = 1;
|
||||
}
|
||||
");
|
||||
const string messageType = "greet.HelloRequest";
|
||||
|
||||
var jsonPattern = new { name = "stef" };
|
||||
var jsonMatcher = new JsonMatcher(jsonPattern);
|
||||
|
||||
var matcher = new ProtoBufMatcher(() => protoDefinition, messageType, matcher: jsonMatcher);
|
||||
|
||||
// Act
|
||||
var model = _sut.Map(matcher)!;
|
||||
|
||||
// Assert
|
||||
model.Name.Should().Be(nameof(ProtoBufMatcher));
|
||||
model.Pattern.Should().Be(protoDefinition.Text);
|
||||
model.ProtoBufMessageType.Should().Be(messageType);
|
||||
model.ContentMatcher?.Name.Should().Be("JsonMatcher");
|
||||
model.ContentMatcher?.Pattern.Should().Be(jsonPattern);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MatcherMapper_Map_Matcher_ProtoBufMatcher_WithId()
|
||||
{
|
||||
// Arrange
|
||||
string id = "abc123";
|
||||
IdOrText protoDefinition = new(id, @"
|
||||
syntax = ""proto3"";
|
||||
|
||||
package greet;
|
||||
|
||||
service Greeter {
|
||||
rpc SayHello (HelloRequest) returns (HelloReply);
|
||||
}
|
||||
|
||||
message HelloRequest {
|
||||
string name = 1;
|
||||
}
|
||||
|
||||
message HelloReply {
|
||||
string message = 1;
|
||||
}
|
||||
");
|
||||
const string messageType = "greet.HelloRequest";
|
||||
|
||||
var jsonPattern = new { name = "stef" };
|
||||
var jsonMatcher = new JsonMatcher(jsonPattern);
|
||||
|
||||
var matcher = new ProtoBufMatcher(() => protoDefinition, messageType, matcher: jsonMatcher);
|
||||
|
||||
// Act
|
||||
var model = _sut.Map(matcher)!;
|
||||
|
||||
// Assert
|
||||
model.Name.Should().Be(nameof(ProtoBufMatcher));
|
||||
model.Pattern.Should().Be(id);
|
||||
model.ProtoBufMessageType.Should().Be(messageType);
|
||||
model.ContentMatcher?.Name.Should().Be("JsonMatcher");
|
||||
model.ContentMatcher?.Pattern.Should().Be(jsonPattern);
|
||||
}
|
||||
#endif
|
||||
|
||||
[Fact]
|
||||
public void MatcherMapper_Map_MatcherModel_Null()
|
||||
{
|
||||
@@ -736,7 +817,7 @@ public class MatcherMapperTests
|
||||
var matcher = (ExactObjectMatcher)_sut.Map(model)!;
|
||||
|
||||
// Assert
|
||||
Check.That(matcher.ValueAsBytes).ContainsExactly(new byte[] { 115, 116, 101, 102 });
|
||||
Check.That((byte[])matcher.Value).ContainsExactly(new byte[] { 115, 116, 101, 102 });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1001,4 +1082,53 @@ public class MatcherMapperTests
|
||||
matcher.CustomScalars.Should().BeEquivalentTo(customScalars);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if PROTOBUF
|
||||
[Fact]
|
||||
public void MatcherMapper_Map_MatcherModel_ProtoBufMatcher()
|
||||
{
|
||||
// Arrange
|
||||
const string protoDefinition = @"
|
||||
syntax = ""proto3"";
|
||||
|
||||
package greet;
|
||||
|
||||
service Greeter {
|
||||
rpc SayHello (HelloRequest) returns (HelloReply);
|
||||
}
|
||||
|
||||
message HelloRequest {
|
||||
string name = 1;
|
||||
}
|
||||
|
||||
message HelloReply {
|
||||
string message = 1;
|
||||
}
|
||||
";
|
||||
const string messageType = "greet.HelloRequest";
|
||||
|
||||
var jsonMatcherPattern = new { name = "stef" };
|
||||
|
||||
var model = new MatcherModel
|
||||
{
|
||||
Name = nameof(ProtoBufMatcher),
|
||||
Pattern = protoDefinition,
|
||||
ProtoBufMessageType = messageType,
|
||||
ContentMatcher = new MatcherModel
|
||||
{
|
||||
Name = nameof(JsonMatcher),
|
||||
Pattern = jsonMatcherPattern
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
var matcher = (ProtoBufMatcher)_sut.Map(model)!;
|
||||
|
||||
// Assert
|
||||
matcher.ProtoDefinition().Text.Should().Be(protoDefinition);
|
||||
matcher.Name.Should().Be(nameof(ProtoBufMatcher));
|
||||
matcher.MessageType.Should().Be(messageType);
|
||||
matcher.Matcher?.Value.Should().Be(jsonMatcherPattern);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user