mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 21:10:32 +01:00
Aspire: Add WithProtoDefinition to support proto definition at server level (#1383)
* Add property UseHttp2 to WireMockServerArguments * . * additionalUrls * ok? * WireMockServerArguments * fx * AddProtoDefinition * ... * FIX * Always add the lifecycle hook to support dynamic mappings and proto definitions
This commit is contained in:
@@ -21,4 +21,13 @@
|
||||
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
<ItemGroup>
|
||||
<None Update="__admin\mappings\*.proto">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="__admin\mappings\*.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -4,12 +4,25 @@ var builder = DistributedApplication.CreateBuilder(args);
|
||||
|
||||
// IResourceBuilder<ProjectResource> apiService = builder.AddProject<Projects.AspireApp1_ApiService>("apiservice");
|
||||
|
||||
var mappingsPath = Path.Combine(Directory.GetCurrentDirectory(), "WireMockMappings");
|
||||
var mappingsPath = Path.Combine(Directory.GetCurrentDirectory(), "__admin", "mappings");
|
||||
|
||||
IResourceBuilder<WireMockServerResource> apiService = builder
|
||||
.AddWireMock("apiservice", WireMockServerArguments.DefaultPort)
|
||||
//IResourceBuilder<WireMockServerResource> apiService1 = builder
|
||||
// //.AddWireMock("apiservice", WireMockServerArguments.DefaultPort)
|
||||
// .AddWireMock("apiservice1", "http://*:8081", "grpc://*:9091")
|
||||
// .AsHttp2Service()
|
||||
// .WithMappingsPath(mappingsPath)
|
||||
// .WithReadStaticMappings()
|
||||
// .WithWatchStaticMappings()
|
||||
// .WithApiMappingBuilder(WeatherForecastApiMock.BuildAsync);
|
||||
|
||||
IResourceBuilder<WireMockServerResource> apiService2 = builder
|
||||
.AddWireMock("apiservice", async args =>
|
||||
{
|
||||
args.WithAdditionalUrls("http://*:8081", "grpc://*:9093");
|
||||
args.WithProtoDefinition("my-greeter", await File.ReadAllTextAsync(Path.Combine(mappingsPath, "greet.proto")));
|
||||
})
|
||||
.AsHttp2Service()
|
||||
.WithMappingsPath(mappingsPath)
|
||||
.WithReadStaticMappings()
|
||||
.WithWatchStaticMappings()
|
||||
.WithApiMappingBuilder(WeatherForecastApiMock.BuildAsync);
|
||||
|
||||
@@ -45,7 +58,7 @@ IResourceBuilder<WireMockServerResource> apiService = builder
|
||||
|
||||
builder.AddProject<Projects.AspireApp1_Web>("webfrontend")
|
||||
.WithExternalHttpEndpoints()
|
||||
.WithReference(apiService)
|
||||
.WaitFor(apiService);
|
||||
.WithReference(apiService2)
|
||||
.WaitFor(apiService2);
|
||||
|
||||
builder.Build().Run();
|
||||
await builder.Build().RunAsync();
|
||||
@@ -0,0 +1,21 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package greet;
|
||||
|
||||
service Greeter {
|
||||
rpc SayHello (HelloRequest) returns (HelloReply);
|
||||
}
|
||||
|
||||
message HelloRequest {
|
||||
string name = 1;
|
||||
}
|
||||
|
||||
message HelloReply {
|
||||
string message = 1;
|
||||
enum PhoneType {
|
||||
none = 0;
|
||||
mobile = 1;
|
||||
home = 2;
|
||||
}
|
||||
PhoneType phoneType = 2;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"Guid": "351f0240-bba0-4bcb-93c6-1feba0fe0004",
|
||||
"Title": "ProtoBuf Mapping 4",
|
||||
"Request": {
|
||||
"Path": {
|
||||
"Matchers": [
|
||||
{
|
||||
"Name": "WildcardMatcher",
|
||||
"Pattern": "/greet.Greeter/SayHello",
|
||||
"IgnoreCase": false
|
||||
}
|
||||
]
|
||||
},
|
||||
"Methods": [
|
||||
"POST"
|
||||
],
|
||||
"Body": {
|
||||
"Matcher": {
|
||||
"Name": "ProtoBufMatcher",
|
||||
"ProtoBufMessageType": "greet.HelloRequest"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Response": {
|
||||
"BodyAsJson": {
|
||||
"message": "hello {{request.BodyAsJson.name}} {{request.method}}"
|
||||
},
|
||||
"UseTransformer": true,
|
||||
"TransformerType": "Handlebars",
|
||||
"TransformerReplaceNodeOptions": "EvaluateAndTryToConvert",
|
||||
"Headers": {
|
||||
"Content-Type": "application/grpc"
|
||||
},
|
||||
"TrailingHeaders": {
|
||||
"grpc-status": "0"
|
||||
},
|
||||
"ProtoBufMessageType": "greet.HelloReply"
|
||||
},
|
||||
"ProtoDefinition": "my-greeter"
|
||||
}
|
||||
Reference in New Issue
Block a user