mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-18 07:24:34 +01:00
* Version 2.x * Setup .NET 9 * 12 * cleanup some #if for NETSTANDARD1_3 * cleanup + fix tests for net8 * openapi * NO ConfigureAwait(false) + cleanup * . * #endif * HashSet * WireMock.Net.NUnit * HttpContext * Add WebSockets (#1423) * Add WebSockets * Add tests * fix * more tests * Add tests * ... * remove IOwin * - * tests * fluent * ok * match * . * byte[] * x * func * func * byte * trans * ... * frameworks......... * jmes * xxx * sc * using var httpClient = new HttpClient(); * usings * maxRetries * up * xunit v3 * ct * --- * ct * ct2 * T Unit * WireMock.Net.TUnitTests / 10 * t unit first * --project * no tunit * t2 * --project * --project * ci - --project * publish ./test/wiremock-coverage.xml * windows * . * log * ... * log * goed * BodyType * . * . * --scenario * ... * pact * ct * . * WireMock.Net.RestClient.AwesomeAssertions (#1427) * WireMock.Net.RestClient.AwesomeAssertions * ok * atpath * fix test * sonar fixes * ports * proxy test * FIX? * --- * await Task.Delay(100, _ct); * ? * --project * Aspire: use IDistributedApplicationEventingSubscriber (#1428) * broadcast * ok * more tsts * . * Collection * up * . * 2 * remove nfluent * <VersionPrefix>2.0.0-preview-02</VersionPrefix> * ... * . * nuget icon * . * <PackageReference Include="JmesPath.Net" Version="1.1.0" /> * x * 500 * . * fix some warnings * ws
149 lines
4.8 KiB
C#
149 lines
4.8 KiB
C#
// Copyright © WireMock.Net
|
|
|
|
using System.Net.Http;
|
|
using RestEase;
|
|
using WireMock.Client;
|
|
using WireMock.Matchers;
|
|
using WireMock.RequestBuilders;
|
|
using WireMock.ResponseBuilders;
|
|
using WireMock.Server;
|
|
|
|
namespace WireMock.Net.Tests.AdminApi;
|
|
|
|
public partial class WireMockAdminApiTests
|
|
{
|
|
private const string ProtoDefinition = @"
|
|
syntax = ""proto3"";
|
|
|
|
package greet;
|
|
|
|
service Greeter {
|
|
rpc SayHello (HelloRequest) returns (HelloReply);
|
|
}
|
|
|
|
message HelloRequest {
|
|
string name = 1;
|
|
}
|
|
|
|
message HelloReply {
|
|
string message = 1;
|
|
}
|
|
";
|
|
|
|
[Fact]
|
|
public async Task IWireMockAdminApi_GetMappingsAsync_WithBodyAsProtoBuf_ShouldReturnCorrectMappingModels()
|
|
{
|
|
// Arrange
|
|
using var server = Given_WithBodyAsProtoBuf_AddedToServer();
|
|
|
|
// Act
|
|
var api = RestClient.For<IWireMockAdminApi>(server.Url);
|
|
var getMappingsResult = await api.GetMappingsAsync(TestContext.Current.CancellationToken);
|
|
|
|
await Verify(getMappingsResult, VerifySettings);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task HttpClient_GetMappingsAsync_WithBodyAsProtoBuf_ShouldReturnCorrectMappingModels()
|
|
{
|
|
// Arrange
|
|
using var server = Given_WithBodyAsProtoBuf_AddedToServer();
|
|
|
|
// Act
|
|
var client = server.CreateClient();
|
|
var getMappingsResult = await client.GetStringAsync("/__admin/mappings", TestContext.Current.CancellationToken);
|
|
|
|
await VerifyJson(getMappingsResult, VerifySettings);
|
|
}
|
|
|
|
public WireMockServer Given_WithBodyAsProtoBuf_AddedToServer()
|
|
{
|
|
// Arrange
|
|
var server = WireMockServer.StartWithAdminInterface();
|
|
|
|
var protoBufJsonMatcher = new JsonPartialWildcardMatcher(new { name = "*" });
|
|
|
|
server
|
|
.Given(Request.Create()
|
|
.UsingPost()
|
|
.WithPath("/grpc/greet.Greeter/SayHello")
|
|
.WithBodyAsProtoBuf(ProtoDefinition, "greet.HelloRequest", protoBufJsonMatcher)
|
|
)
|
|
.WithGuid(_guidUtilsMock.Object.NewGuid())
|
|
.RespondWith(Response.Create()
|
|
.WithHeader("Content-Type", "application/grpc")
|
|
.WithBodyAsProtoBuf(ProtoDefinition, "greet.HelloReply",
|
|
new
|
|
{
|
|
message = "hello {{request.BodyAsJson.name}}"
|
|
}
|
|
)
|
|
.WithTrailingHeader("grpc-status", "0")
|
|
.WithTransformer()
|
|
);
|
|
|
|
server
|
|
.Given(Request.Create()
|
|
.UsingPost()
|
|
.WithPath("/grpc2/greet.Greeter/SayHello")
|
|
.WithBodyAsProtoBuf("greet.HelloRequest", protoBufJsonMatcher)
|
|
)
|
|
.WithProtoDefinition(ProtoDefinition)
|
|
.WithGuid(_guidUtilsMock.Object.NewGuid())
|
|
.RespondWith(Response.Create()
|
|
.WithHeader("Content-Type", "application/grpc")
|
|
.WithBodyAsProtoBuf("greet.HelloReply",
|
|
new
|
|
{
|
|
message = "hello {{request.BodyAsJson.name}}"
|
|
}
|
|
)
|
|
.WithTrailingHeader("grpc-status", "0")
|
|
.WithTransformer()
|
|
);
|
|
|
|
server
|
|
.AddProtoDefinition("my-greeter", ProtoDefinition)
|
|
.Given(Request.Create()
|
|
.UsingPost()
|
|
.WithPath("/grpc3/greet.Greeter/SayHello")
|
|
.WithBodyAsProtoBuf("greet.HelloRequest", protoBufJsonMatcher)
|
|
)
|
|
.WithProtoDefinition("my-greeter")
|
|
.WithGuid(_guidUtilsMock.Object.NewGuid())
|
|
.RespondWith(Response.Create()
|
|
.WithHeader("Content-Type", "application/grpc")
|
|
.WithBodyAsProtoBuf("greet.HelloReply",
|
|
new
|
|
{
|
|
message = "hello {{request.BodyAsJson.name}}"
|
|
}
|
|
)
|
|
.WithTrailingHeader("grpc-status", "0")
|
|
.WithTransformer()
|
|
);
|
|
|
|
server
|
|
.AddProtoDefinition("my-greeter", ProtoDefinition)
|
|
.Given(Request.Create()
|
|
.UsingPost()
|
|
.WithPath("/grpc4/greet.Greeter/SayHello")
|
|
.WithBodyAsProtoBuf("greet.HelloRequest")
|
|
)
|
|
.WithProtoDefinition("my-greeter")
|
|
.WithGuid(_guidUtilsMock.Object.NewGuid())
|
|
.RespondWith(Response.Create()
|
|
.WithHeader("Content-Type", "application/grpc")
|
|
.WithBodyAsProtoBuf("greet.HelloReply",
|
|
new
|
|
{
|
|
message = "hello {{request.BodyAsJson.name}}"
|
|
}
|
|
)
|
|
.WithTrailingHeader("grpc-status", "0")
|
|
.WithTransformer()
|
|
);
|
|
|
|
return server;
|
|
}
|
|
} |