mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-23 17:28:55 +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:
39
test/WireMock.Net.Tests/Util/HttpVersionParserTests.cs
Normal file
39
test/WireMock.Net.Tests/Util/HttpVersionParserTests.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using FluentAssertions;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Util;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class HttpVersionParserTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("HTTP/1.1", "1.1")]
|
||||
[InlineData("HTTP/2", "2")]
|
||||
[InlineData("http/1.0", "1.0")]
|
||||
[InlineData("HTTP/3", "3")]
|
||||
public void Parse_ValidHttpVersion_ReturnsCorrectVersion(string protocol, string expectedVersion)
|
||||
{
|
||||
// Act
|
||||
var version = HttpVersionParser.Parse(protocol);
|
||||
|
||||
// Assert
|
||||
version.Should().Be(expectedVersion, "the input string is a valid HTTP protocol version");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("HTP/2")]
|
||||
[InlineData("HTTP/2.2.2")]
|
||||
[InlineData("HTTP/")]
|
||||
[InlineData("http//1.1")]
|
||||
[InlineData("")]
|
||||
public void Parse_InvalidHttpVersion_ReturnsEmptyString(string protocol)
|
||||
{
|
||||
// Act
|
||||
var version = HttpVersionParser.Parse(protocol);
|
||||
|
||||
// Assert
|
||||
version.Should().BeEmpty("the input string is not a valid HTTP protocol version");
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using FluentAssertions;
|
||||
using NFluent;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
@@ -11,14 +10,15 @@ public class PortUtilsTests
|
||||
public void PortUtils_TryExtract_InvalidUrl_Returns_False()
|
||||
{
|
||||
// Assign
|
||||
string url = "test";
|
||||
var url = "test";
|
||||
|
||||
// Act
|
||||
bool result = PortUtils.TryExtract(url, out bool isHttps, out string proto, out string host, out int port);
|
||||
var result = PortUtils.TryExtract(url, out var isHttps, out var isGrpc, out var proto, out var host, out var port);
|
||||
|
||||
// Assert
|
||||
result.Should().BeFalse();
|
||||
isHttps.Should().BeFalse();
|
||||
isGrpc.Should().BeFalse();
|
||||
proto.Should().BeNull();
|
||||
host.Should().BeNull();
|
||||
port.Should().Be(default(int));
|
||||
@@ -28,14 +28,15 @@ public class PortUtilsTests
|
||||
public void PortUtils_TryExtract_UrlIsMissingPort_Returns_False()
|
||||
{
|
||||
// Assign
|
||||
string url = "http://0.0.0.0";
|
||||
var url = "http://0.0.0.0";
|
||||
|
||||
// Act
|
||||
bool result = PortUtils.TryExtract(url, out bool isHttps, out string proto, out string host, out int port);
|
||||
var result = PortUtils.TryExtract(url, out var isHttps, out var isGrpc, out var proto, out var host, out var port);
|
||||
|
||||
// Assert
|
||||
result.Should().BeFalse();
|
||||
isHttps.Should().BeFalse();
|
||||
isGrpc.Should().BeFalse();
|
||||
proto.Should().BeNull();
|
||||
host.Should().BeNull();
|
||||
port.Should().Be(default(int));
|
||||
@@ -45,14 +46,15 @@ public class PortUtilsTests
|
||||
public void PortUtils_TryExtract_Http_Returns_True()
|
||||
{
|
||||
// Assign
|
||||
string url = "http://wiremock.net:1234";
|
||||
var url = "http://wiremock.net:1234";
|
||||
|
||||
// Act
|
||||
bool result = PortUtils.TryExtract(url, out bool isHttps, out string proto, out string host, out int port);
|
||||
var result = PortUtils.TryExtract(url, out var isHttps, out var isGrpc, out var proto, out var host, out var port);
|
||||
|
||||
// Assert
|
||||
result.Should().BeTrue();
|
||||
isHttps.Should().BeFalse();
|
||||
isGrpc.Should().BeFalse();
|
||||
proto.Should().Be("http");
|
||||
host.Should().Be("wiremock.net");
|
||||
port.Should().Be(1234);
|
||||
@@ -62,31 +64,51 @@ public class PortUtilsTests
|
||||
public void PortUtils_TryExtract_Https_Returns_True()
|
||||
{
|
||||
// Assign
|
||||
string url = "https://wiremock.net:5000";
|
||||
var url = "https://wiremock.net:5000";
|
||||
|
||||
// Act
|
||||
bool result = PortUtils.TryExtract(url, out bool isHttps, out string proto, out string host, out int port);
|
||||
var result = PortUtils.TryExtract(url, out var isHttps, out var isGrpc, out var proto, out var host, out var port);
|
||||
|
||||
// Assert
|
||||
result.Should().BeTrue();
|
||||
isHttps.Should().BeTrue();
|
||||
isGrpc.Should().BeFalse();
|
||||
proto.Should().Be("https");
|
||||
host.Should().Be("wiremock.net");
|
||||
port.Should().Be(5000);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PortUtils_TryExtract_Grpc_Returns_True()
|
||||
{
|
||||
// Assign
|
||||
var url = "grpc://wiremock.net:1234";
|
||||
|
||||
// Act
|
||||
var result = PortUtils.TryExtract(url, out var isHttps, out var isGrpc, out var proto, out var host, out var port);
|
||||
|
||||
// Assert
|
||||
result.Should().BeTrue();
|
||||
isHttps.Should().BeFalse();
|
||||
isGrpc.Should().BeTrue();
|
||||
proto.Should().Be("grpc");
|
||||
host.Should().Be("wiremock.net");
|
||||
port.Should().Be(1234);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PortUtils_TryExtract_Https0_0_0_0_Returns_True()
|
||||
{
|
||||
// Assign
|
||||
string url = "https://0.0.0.0:5000";
|
||||
var url = "https://0.0.0.0:5000";
|
||||
|
||||
// Act
|
||||
bool result = PortUtils.TryExtract(url, out bool isHttps, out string proto, out string host, out int port);
|
||||
var result = PortUtils.TryExtract(url, out var isHttps, out var isGrpc, out var proto, out var host, out var port);
|
||||
|
||||
// Assert
|
||||
result.Should().BeTrue();
|
||||
isHttps.Should().BeTrue();
|
||||
isGrpc.Should().BeFalse();
|
||||
proto.Should().Be("https");
|
||||
host.Should().Be("0.0.0.0");
|
||||
port.Should().Be(5000);
|
||||
|
||||
Reference in New Issue
Block a user