mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-20 16:01:39 +02:00
mm
This commit is contained in:
@@ -190,5 +190,92 @@
|
||||
BodyDestination: SameAsSource,
|
||||
Body: Buy milk
|
||||
}
|
||||
},
|
||||
{
|
||||
Guid: 98fae52e-76df-47d9-876f-2ee32e931006,
|
||||
UpdatedAt: 2023-01-14 15:16:17,
|
||||
Request: {
|
||||
Path: {
|
||||
Matchers: [
|
||||
{
|
||||
Name: WildcardMatcher,
|
||||
Pattern: /delay,
|
||||
IgnoreCase: false
|
||||
}
|
||||
]
|
||||
},
|
||||
Methods: [
|
||||
GET
|
||||
]
|
||||
},
|
||||
Response: {
|
||||
Delay: 1000
|
||||
}
|
||||
},
|
||||
{
|
||||
Guid: 98fae52e-76df-47d9-876f-2ee32e931007,
|
||||
UpdatedAt: 2023-01-14 15:16:17,
|
||||
Request: {
|
||||
Path: {
|
||||
Matchers: [
|
||||
{
|
||||
Name: WildcardMatcher,
|
||||
Pattern: /random-delay,
|
||||
IgnoreCase: false
|
||||
}
|
||||
]
|
||||
},
|
||||
Methods: [
|
||||
GET
|
||||
]
|
||||
},
|
||||
Response: {
|
||||
MinimumRandomDelay: 1234,
|
||||
MaximumRandomDelay: 60000
|
||||
}
|
||||
},
|
||||
{
|
||||
Guid: 98fae52e-76df-47d9-876f-2ee32e931008,
|
||||
UpdatedAt: 2023-01-14 15:16:17,
|
||||
Request: {
|
||||
Path: {
|
||||
Matchers: [
|
||||
{
|
||||
Name: WildcardMatcher,
|
||||
Pattern: /prob,
|
||||
IgnoreCase: false
|
||||
}
|
||||
]
|
||||
},
|
||||
Methods: [
|
||||
GET
|
||||
]
|
||||
},
|
||||
Response: {
|
||||
StatusCode: 300
|
||||
},
|
||||
Probability: 0.1
|
||||
},
|
||||
{
|
||||
Guid: 98fae52e-76df-47d9-876f-2ee32e931009,
|
||||
UpdatedAt: 2023-01-14 15:16:17,
|
||||
Request: {
|
||||
Path: {
|
||||
Matchers: [
|
||||
{
|
||||
Name: WildcardMatcher,
|
||||
Pattern: /prob,
|
||||
IgnoreCase: false
|
||||
}
|
||||
]
|
||||
},
|
||||
Methods: [
|
||||
GET
|
||||
]
|
||||
},
|
||||
Response: {
|
||||
StatusCode: 201
|
||||
},
|
||||
Probability: 0.9
|
||||
}
|
||||
]
|
||||
@@ -78,3 +78,45 @@ builder
|
||||
.WithBody("Buy milk")
|
||||
);
|
||||
|
||||
builder
|
||||
.Given(Request.Create()
|
||||
.UsingMethod("GET")
|
||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/delay", false, WireMock.Matchers.MatchOperator.Or))
|
||||
)
|
||||
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931006")
|
||||
.RespondWith(Response.Create()
|
||||
.WithDelay(1000)
|
||||
);
|
||||
|
||||
builder
|
||||
.Given(Request.Create()
|
||||
.UsingMethod("GET")
|
||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/random-delay", false, WireMock.Matchers.MatchOperator.Or))
|
||||
)
|
||||
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931007")
|
||||
.RespondWith(Response.Create()
|
||||
.WithRandomDelay(1234, 60000)
|
||||
);
|
||||
|
||||
builder
|
||||
.Given(Request.Create()
|
||||
.UsingMethod("GET")
|
||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/prob", false, WireMock.Matchers.MatchOperator.Or))
|
||||
)
|
||||
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931008")
|
||||
.WithProbability(0.1)
|
||||
.RespondWith(Response.Create()
|
||||
.WithStatusCode(300)
|
||||
);
|
||||
|
||||
builder
|
||||
.Given(Request.Create()
|
||||
.UsingMethod("GET")
|
||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/prob", false, WireMock.Matchers.MatchOperator.Or))
|
||||
)
|
||||
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931009")
|
||||
.WithProbability(0.9)
|
||||
.RespondWith(Response.Create()
|
||||
.WithStatusCode(201)
|
||||
);
|
||||
|
||||
|
||||
@@ -78,3 +78,45 @@ server
|
||||
.WithBody("Buy milk")
|
||||
);
|
||||
|
||||
server
|
||||
.Given(Request.Create()
|
||||
.UsingMethod("GET")
|
||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/delay", false, WireMock.Matchers.MatchOperator.Or))
|
||||
)
|
||||
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931006")
|
||||
.RespondWith(Response.Create()
|
||||
.WithDelay(1000)
|
||||
);
|
||||
|
||||
server
|
||||
.Given(Request.Create()
|
||||
.UsingMethod("GET")
|
||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/random-delay", false, WireMock.Matchers.MatchOperator.Or))
|
||||
)
|
||||
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931007")
|
||||
.RespondWith(Response.Create()
|
||||
.WithRandomDelay(1234, 60000)
|
||||
);
|
||||
|
||||
server
|
||||
.Given(Request.Create()
|
||||
.UsingMethod("GET")
|
||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/prob", false, WireMock.Matchers.MatchOperator.Or))
|
||||
)
|
||||
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931008")
|
||||
.WithProbability(0.1)
|
||||
.RespondWith(Response.Create()
|
||||
.WithStatusCode(300)
|
||||
);
|
||||
|
||||
server
|
||||
.Given(Request.Create()
|
||||
.UsingMethod("GET")
|
||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/prob", false, WireMock.Matchers.MatchOperator.Or))
|
||||
)
|
||||
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931009")
|
||||
.WithProbability(0.9)
|
||||
.RespondWith(Response.Create()
|
||||
.WithStatusCode(201)
|
||||
);
|
||||
|
||||
|
||||
@@ -186,5 +186,92 @@
|
||||
BodyDestination: SameAsSource,
|
||||
Body: Buy milk
|
||||
}
|
||||
},
|
||||
{
|
||||
Guid: 98fae52e-76df-47d9-876f-2ee32e931006,
|
||||
UpdatedAt: 2023-01-14T15:16:17,
|
||||
Request: {
|
||||
Path: {
|
||||
Matchers: [
|
||||
{
|
||||
Name: WildcardMatcher,
|
||||
Pattern: /delay,
|
||||
IgnoreCase: false
|
||||
}
|
||||
]
|
||||
},
|
||||
Methods: [
|
||||
GET
|
||||
]
|
||||
},
|
||||
Response: {
|
||||
Delay: 1000
|
||||
}
|
||||
},
|
||||
{
|
||||
Guid: 98fae52e-76df-47d9-876f-2ee32e931007,
|
||||
UpdatedAt: 2023-01-14T15:16:17,
|
||||
Request: {
|
||||
Path: {
|
||||
Matchers: [
|
||||
{
|
||||
Name: WildcardMatcher,
|
||||
Pattern: /random-delay,
|
||||
IgnoreCase: false
|
||||
}
|
||||
]
|
||||
},
|
||||
Methods: [
|
||||
GET
|
||||
]
|
||||
},
|
||||
Response: {
|
||||
MinimumRandomDelay: 1234,
|
||||
MaximumRandomDelay: 60000
|
||||
}
|
||||
},
|
||||
{
|
||||
Guid: 98fae52e-76df-47d9-876f-2ee32e931008,
|
||||
UpdatedAt: 2023-01-14T15:16:17,
|
||||
Request: {
|
||||
Path: {
|
||||
Matchers: [
|
||||
{
|
||||
Name: WildcardMatcher,
|
||||
Pattern: /prob,
|
||||
IgnoreCase: false
|
||||
}
|
||||
]
|
||||
},
|
||||
Methods: [
|
||||
GET
|
||||
]
|
||||
},
|
||||
Response: {
|
||||
StatusCode: 300
|
||||
},
|
||||
Probability: 0.1
|
||||
},
|
||||
{
|
||||
Guid: 98fae52e-76df-47d9-876f-2ee32e931009,
|
||||
UpdatedAt: 2023-01-14T15:16:17,
|
||||
Request: {
|
||||
Path: {
|
||||
Matchers: [
|
||||
{
|
||||
Name: WildcardMatcher,
|
||||
Pattern: /prob,
|
||||
IgnoreCase: false
|
||||
}
|
||||
]
|
||||
},
|
||||
Methods: [
|
||||
GET
|
||||
]
|
||||
},
|
||||
Response: {
|
||||
StatusCode: 201
|
||||
},
|
||||
Probability: 0.9
|
||||
}
|
||||
]
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#if !(NET452 || NET461 || NETCOREAPP3_1)
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using VerifyTests;
|
||||
@@ -118,6 +119,35 @@ public class MappingBuilderTests
|
||||
.RespondWith(Response.Create()
|
||||
.WithBody("Buy milk"));
|
||||
|
||||
_sut.Given(Request.Create()
|
||||
.WithPath("/delay")
|
||||
.UsingGet()
|
||||
).RespondWith(Response.Create()
|
||||
.WithDelay(1000)
|
||||
);
|
||||
|
||||
_sut.Given(Request.Create()
|
||||
.WithPath("/random-delay")
|
||||
.UsingGet()
|
||||
).RespondWith(Response.Create()
|
||||
.WithRandomDelay(1234)
|
||||
);
|
||||
|
||||
_sut.Given(Request.Create()
|
||||
.WithPath("/prob")
|
||||
.UsingGet()
|
||||
).WithProbability(0.1)
|
||||
.RespondWith(Response.Create()
|
||||
.WithStatusCode(HttpStatusCode.Ambiguous)
|
||||
);
|
||||
_sut.Given(Request.Create()
|
||||
.WithPath("/prob")
|
||||
.UsingGet()
|
||||
).WithProbability(0.9)
|
||||
.RespondWith(Response.Create()
|
||||
.WithStatusCode(HttpStatusCode.Created)
|
||||
);
|
||||
|
||||
_numMappings = _sut.GetMappings().Length;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ public partial class TestcontainersTests
|
||||
var grpcPort = wireMockContainer.GetMappedPublicPort(9090);
|
||||
grpcPort.Should().BeGreaterThan(0);
|
||||
|
||||
var grpcUrl = wireMockContainer.GetMappedPublicUrl(80);
|
||||
var grpcUrl = wireMockContainer.GetMappedPublicUrl(9090);
|
||||
grpcUrl.Should().StartWith("http://");
|
||||
|
||||
var adminClient = wireMockContainer.CreateWireMockAdminClient();
|
||||
@@ -149,6 +149,18 @@ public partial class TestcontainersTests
|
||||
await StopAsync(wireMockContainer);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WireMockContainer_Build_Grpc_ProtoDefinitionAtServerLevel_UsingGrpcGeneratedClient_AndWithWatchStaticMappings()
|
||||
{
|
||||
var wireMockContainer = await Given_WireMockContainerWithProtoDefinitionAtServerLevelWithWatchStaticMappingsIsStartedForHttpAndGrpcAsync();
|
||||
|
||||
var reply = await When_GrpcClient_Calls_SayHelloAsync(wireMockContainer);
|
||||
|
||||
Then_ReplyMessage_Should_BeCorrect(reply);
|
||||
|
||||
await StopAsync(wireMockContainer);
|
||||
}
|
||||
|
||||
private static async Task<WireMockContainer> Given_WireMockContainerIsStartedForHttpAndGrpcAsync()
|
||||
{
|
||||
var wireMockContainer = new WireMockContainerBuilder()
|
||||
@@ -172,6 +184,19 @@ public partial class TestcontainersTests
|
||||
return wireMockContainer;
|
||||
}
|
||||
|
||||
private static async Task<WireMockContainer> Given_WireMockContainerWithProtoDefinitionAtServerLevelWithWatchStaticMappingsIsStartedForHttpAndGrpcAsync()
|
||||
{
|
||||
var wireMockContainer = new WireMockContainerBuilder()
|
||||
.AddUrl("grpc://*:9090")
|
||||
.AddProtoDefinition("my-greeter", ReadFile("greet.proto"))
|
||||
.WithMappings(Path.Combine(Directory.GetCurrentDirectory(), "__admin", "mappings"))
|
||||
.Build();
|
||||
|
||||
await wireMockContainer.StartAsync();
|
||||
|
||||
return wireMockContainer;
|
||||
}
|
||||
|
||||
private static async Task Given_ProtoBufMappingIsAddedViaAdminInterfaceAsync(WireMockContainer wireMockContainer, string filename)
|
||||
{
|
||||
var mappingsJson = ReadFile(filename);
|
||||
|
||||
@@ -15,13 +15,13 @@ public class PortUtilsTests
|
||||
var url = "test";
|
||||
|
||||
// Act
|
||||
var result = PortUtils.TryExtract(url, out var isHttps, out var isGrpc, out var proto, out var host, out var port);
|
||||
var result = PortUtils.TryExtract(url, out var isHttps, out var isGrpc, out var scheme, out var host, out var port);
|
||||
|
||||
// Assert
|
||||
result.Should().BeFalse();
|
||||
isHttps.Should().BeFalse();
|
||||
isGrpc.Should().BeFalse();
|
||||
proto.Should().BeNull();
|
||||
scheme.Should().BeNull();
|
||||
host.Should().BeNull();
|
||||
port.Should().Be(default(int));
|
||||
}
|
||||
@@ -33,13 +33,13 @@ public class PortUtilsTests
|
||||
var url = "http://0.0.0.0";
|
||||
|
||||
// Act
|
||||
var result = PortUtils.TryExtract(url, out var isHttps, out var isGrpc, out var proto, out var host, out var port);
|
||||
var result = PortUtils.TryExtract(url, out var isHttps, out var isGrpc, out var scheme, out var host, out var port);
|
||||
|
||||
// Assert
|
||||
result.Should().BeFalse();
|
||||
isHttps.Should().BeFalse();
|
||||
isGrpc.Should().BeFalse();
|
||||
proto.Should().BeNull();
|
||||
scheme.Should().BeNull();
|
||||
host.Should().BeNull();
|
||||
port.Should().Be(default(int));
|
||||
}
|
||||
@@ -51,13 +51,13 @@ public class PortUtilsTests
|
||||
var url = "http://wiremock.net:1234";
|
||||
|
||||
// Act
|
||||
var result = PortUtils.TryExtract(url, out var isHttps, out var isGrpc, out var proto, out var host, out var port);
|
||||
var result = PortUtils.TryExtract(url, out var isHttps, out var isGrpc, out var scheme, out var host, out var port);
|
||||
|
||||
// Assert
|
||||
result.Should().BeTrue();
|
||||
isHttps.Should().BeFalse();
|
||||
isGrpc.Should().BeFalse();
|
||||
proto.Should().Be("http");
|
||||
scheme.Should().Be("http");
|
||||
host.Should().Be("wiremock.net");
|
||||
port.Should().Be(1234);
|
||||
}
|
||||
@@ -69,13 +69,13 @@ public class PortUtilsTests
|
||||
var url = "https://wiremock.net:5000";
|
||||
|
||||
// Act
|
||||
var result = PortUtils.TryExtract(url, out var isHttps, out var isGrpc, out var proto, out var host, out var port);
|
||||
var result = PortUtils.TryExtract(url, out var isHttps, out var isGrpc, out var scheme, out var host, out var port);
|
||||
|
||||
// Assert
|
||||
result.Should().BeTrue();
|
||||
isHttps.Should().BeTrue();
|
||||
isGrpc.Should().BeFalse();
|
||||
proto.Should().Be("https");
|
||||
scheme.Should().Be("https");
|
||||
host.Should().Be("wiremock.net");
|
||||
port.Should().Be(5000);
|
||||
}
|
||||
@@ -87,13 +87,13 @@ public class PortUtilsTests
|
||||
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);
|
||||
var result = PortUtils.TryExtract(url, out var isHttps, out var isGrpc, out var scheme, out var host, out var port);
|
||||
|
||||
// Assert
|
||||
result.Should().BeTrue();
|
||||
isHttps.Should().BeFalse();
|
||||
isGrpc.Should().BeTrue();
|
||||
proto.Should().Be("grpc");
|
||||
scheme.Should().Be("grpc");
|
||||
host.Should().Be("wiremock.net");
|
||||
port.Should().Be(1234);
|
||||
}
|
||||
@@ -105,13 +105,13 @@ public class PortUtilsTests
|
||||
var url = "https://0.0.0.0:5000";
|
||||
|
||||
// Act
|
||||
var result = PortUtils.TryExtract(url, out var isHttps, out var isGrpc, out var proto, out var host, out var port);
|
||||
var result = PortUtils.TryExtract(url, out var isHttps, out var isGrpc, out var scheme, out var host, out var port);
|
||||
|
||||
// Assert
|
||||
result.Should().BeTrue();
|
||||
isHttps.Should().BeTrue();
|
||||
isGrpc.Should().BeFalse();
|
||||
proto.Should().Be("https");
|
||||
scheme.Should().Be("https");
|
||||
host.Should().Be("0.0.0.0");
|
||||
port.Should().Be(5000);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user