This commit is contained in:
Stef Heyenrath
2018-08-08 08:20:52 +02:00
parent 36866d9fc3
commit 5ee25fb1e7
7 changed files with 336 additions and 284 deletions

View File

@@ -6,16 +6,12 @@
<ApplicationIcon>../../WireMock.Net-Logo.ico</ApplicationIcon> <ApplicationIcon>../../WireMock.Net-Logo.ico</ApplicationIcon>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<None Remove="__admin\mappings\826aff7c-6208-4a3c-923d-575248907db4.json" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="..\WireMock.Net.ConsoleApplication\MainApp.cs" Link="MainApp.cs" /> <Compile Include="..\WireMock.Net.ConsoleApplication\MainApp.cs" Link="MainApp.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="__admin\mappings\11111110-a633-40e8-a244-5cb80bc0ab66.json"> <Content Include="__admin\mappings\*.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
</ItemGroup> </ItemGroup>

View File

@@ -0,0 +1,19 @@
{
"Guid": "873d495f-940e-4b86-a1f4-4f0fc7be8b8b",
"Priority": 4,
"Request": {
"Path": {},
"Methods": [
"get"
]
},
"Response": {
"StatusCode": 200,
"BodyDestination": "SameAsSource",
"Body": "NO PATH OR URL",
"UseTransformer": false,
"Headers": {
"Content-Type": "application/json"
}
}
}

View File

@@ -39,300 +39,300 @@ namespace WireMock.Net.ConsoleApplication
server.AllowPartialMapping(); server.AllowPartialMapping();
server server
.Given(Request.Create() .Given(Request.Create().WithPath(p => p.Contains("x")).UsingGet())
.UsingGet() .AtPriority(4)
.WithPath("/proxy-test-keep-alive")
)
.RespondWith(Response.Create()
.WithHeader("Keep-Alive", "timeout=1, max=1")
);
server
.Given(Request.Create()
.UsingGet()
.WithPath("/proxy-execute-keep-alive")
)
.RespondWith(Response.Create()
.WithProxy(new ProxyAndRecordSettings { Url = "http://localhost:9999", BlackListedHeaders = new[] { "Keep-Alive" } })
.WithHeader("Keep-Alive-Test", "stef")
);
server
.Given(Request.Create()
.WithPath("/xpath").UsingPost()
.WithBody(new XPathMatcher("/todo-list[count(todo-item) = 3]"))
)
.RespondWith(Response.Create().WithBody("XPathMatcher!"));
server
.Given(Request
.Create()
.WithPath("/jsonthings")
.WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]"))
.UsingPut())
.RespondWith(Response.Create()
.WithBody(@"{ ""result"": ""JsonPathMatcher !!!""}"));
server
.Given(Request
.Create()
.WithPath("/jsonbodytest1")
.WithBody(new JsonMatcher("{ \"x\": 42, \"s\": \"s\" }"))
.UsingPost())
.WithGuid("debaf408-3b23-4c04-9d18-ef1c020e79f2")
.RespondWith(Response.Create()
.WithBody(@"{ ""result"": ""jsonbodytest1"" }"));
server
.Given(Request
.Create()
.WithPath("/jsonbodytest2")
.WithBody(new JsonMatcher(new { x = 42, s = "s" }))
.UsingPost())
.WithGuid("debaf408-3b23-4c04-9d18-ef1c020e79f3")
.RespondWith(Response.Create()
.WithBody(@"{ ""result"": ""jsonbodytest2"" }"));
server
.Given(Request
.Create()
.WithPath(new WildcardMatcher("/navision/OData/Company('My Company')/School*", true))
.WithParam("$filter", "(substringof(Code, 'WA')")
.UsingGet())
.RespondWith(Response.Create()
.WithHeader("Content-Type", "application/json")
.WithBody(@"{ ""result"": ""odata""}"));
server
.Given(Request
.Create()
.WithPath(new WildcardMatcher("/param2", true))
.WithParam("key", "test")
.UsingGet())
.RespondWith(Response.Create()
.WithHeader("Content-Type", "application/json")
.WithBodyAsJson(new { result = "param2" }));
server
.Given(Request
.Create()
.WithPath(new WildcardMatcher("/param3", true))
.WithParam("key", new WildcardMatcher("t*"))
.UsingGet())
.RespondWith(Response.Create()
.WithHeader("Content-Type", "application/json")
.WithBodyAsJson(new { result = "param3" }));
server
.Given(Request.Create().WithPath("/headers", "/headers_test").UsingPost().WithHeader("Content-Type", "application/json*"))
.RespondWith(Response.Create()
.WithStatusCode(201)
.WithHeader("Content-Type", "application/json")
.WithBodyAsJson(new { result = "data:headers posted with 201" }));
server
.Given(Request.Create().WithPath("/file").UsingGet())
.RespondWith(Response.Create()
.WithBodyFromFile(@"c:\temp\x.json", false)
);
server
.Given(Request.Create().WithPath("/filecache").UsingGet())
.RespondWith(Response.Create()
.WithBodyFromFile(@"c:\temp\x.json")
);
server
.Given(Request.Create().WithPath("/file_rel").UsingGet())
.WithGuid("0000aaaa-fcf4-4256-a0d3-1c76e4862947")
.RespondWith(Response.Create()
.WithHeader("Content-Type", "application/xml")
.WithBodyFromFile("WireMock.Net.xml", false)
);
server
.Given(Request.Create().WithHeader("ProxyThis", "true")
.UsingGet())
.RespondWith(Response.Create()
.WithProxy("http://www.google.com")
);
server
.Given(Request.Create().WithPath("/bodyasbytes.png")
.UsingGet())
.RespondWith(Response.Create()
.WithHeader("Content-Type", "image/png")
.WithBody(Convert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAZdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuMTczbp9jAAAAJ0lEQVQoU2NgUPuPD6Hz0RCEAtJoiAxpCCBXGgmRIo0TofORkdp/AMiMdRVnV6O0AAAAAElFTkSuQmCC"))
);
server
.Given(Request.Create().WithPath("/oauth2/access").UsingPost().WithBody("grant_type=password;username=u;password=p"))
.RespondWith(Response.Create() .RespondWith(Response.Create()
.WithStatusCode(200) .WithStatusCode(200)
.WithHeader("Content-Type", "application/json") .WithHeader("Content-Type", "application/json")
.WithBodyAsJson(new { access_token = "AT", refresh_token = "RT" })); .WithBody(@"{ ""result"": ""Contains x with FUNC 200""}"));
server
.Given(Request.Create().WithPath("/helloworld").UsingGet().WithHeader("Authorization", new RegexMatcher("^(?i)Bearer AT$")))
.RespondWith(Response.Create()
.WithStatusCode(200)
.WithBody("hi"));
//server //server
// .Given(Request.Create().WithPath(p => p.Contains("x")).UsingGet()) // .Given(Request.Create()
// .AtPriority(4) // .UsingGet()
// .WithPath("/proxy-test-keep-alive")
// )
// .RespondWith(Response.Create()
// .WithHeader("Keep-Alive", "timeout=1, max=1")
// );
//server
// .Given(Request.Create()
// .UsingGet()
// .WithPath("/proxy-execute-keep-alive")
// )
// .RespondWith(Response.Create()
// .WithProxy(new ProxyAndRecordSettings { Url = "http://localhost:9999", BlackListedHeaders = new[] { "Keep-Alive" } })
// .WithHeader("Keep-Alive-Test", "stef")
// );
//server
// .Given(Request.Create()
// .WithPath("/xpath").UsingPost()
// .WithBody(new XPathMatcher("/todo-list[count(todo-item) = 3]"))
// )
// .RespondWith(Response.Create().WithBody("XPathMatcher!"));
//server
// .Given(Request
// .Create()
// .WithPath("/jsonthings")
// .WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]"))
// .UsingPut())
// .RespondWith(Response.Create()
// .WithBody(@"{ ""result"": ""JsonPathMatcher !!!""}"));
//server
// .Given(Request
// .Create()
// .WithPath("/jsonbodytest1")
// .WithBody(new JsonMatcher("{ \"x\": 42, \"s\": \"s\" }"))
// .UsingPost())
// .WithGuid("debaf408-3b23-4c04-9d18-ef1c020e79f2")
// .RespondWith(Response.Create()
// .WithBody(@"{ ""result"": ""jsonbodytest1"" }"));
//server
// .Given(Request
// .Create()
// .WithPath("/jsonbodytest2")
// .WithBody(new JsonMatcher(new { x = 42, s = "s" }))
// .UsingPost())
// .WithGuid("debaf408-3b23-4c04-9d18-ef1c020e79f3")
// .RespondWith(Response.Create()
// .WithBody(@"{ ""result"": ""jsonbodytest2"" }"));
//server
// .Given(Request
// .Create()
// .WithPath(new WildcardMatcher("/navision/OData/Company('My Company')/School*", true))
// .WithParam("$filter", "(substringof(Code, 'WA')")
// .UsingGet())
// .RespondWith(Response.Create()
// .WithHeader("Content-Type", "application/json")
// .WithBody(@"{ ""result"": ""odata""}"));
//server
// .Given(Request
// .Create()
// .WithPath(new WildcardMatcher("/param2", true))
// .WithParam("key", "test")
// .UsingGet())
// .RespondWith(Response.Create()
// .WithHeader("Content-Type", "application/json")
// .WithBodyAsJson(new { result = "param2" }));
//server
// .Given(Request
// .Create()
// .WithPath(new WildcardMatcher("/param3", true))
// .WithParam("key", new WildcardMatcher("t*"))
// .UsingGet())
// .RespondWith(Response.Create()
// .WithHeader("Content-Type", "application/json")
// .WithBodyAsJson(new { result = "param3" }));
//server
// .Given(Request.Create().WithPath("/headers", "/headers_test").UsingPost().WithHeader("Content-Type", "application/json*"))
// .RespondWith(Response.Create()
// .WithStatusCode(201)
// .WithHeader("Content-Type", "application/json")
// .WithBodyAsJson(new { result = "data:headers posted with 201" }));
//server
// .Given(Request.Create().WithPath("/file").UsingGet())
// .RespondWith(Response.Create()
// .WithBodyFromFile(@"c:\temp\x.json", false)
// );
//server
// .Given(Request.Create().WithPath("/filecache").UsingGet())
// .RespondWith(Response.Create()
// .WithBodyFromFile(@"c:\temp\x.json")
// );
//server
// .Given(Request.Create().WithPath("/file_rel").UsingGet())
// .WithGuid("0000aaaa-fcf4-4256-a0d3-1c76e4862947")
// .RespondWith(Response.Create()
// .WithHeader("Content-Type", "application/xml")
// .WithBodyFromFile("WireMock.Net.xml", false)
// );
//server
// .Given(Request.Create().WithHeader("ProxyThis", "true")
// .UsingGet())
// .RespondWith(Response.Create()
// .WithProxy("http://www.google.com")
//);
//server
// .Given(Request.Create().WithPath("/bodyasbytes.png")
// .UsingGet())
// .RespondWith(Response.Create()
// .WithHeader("Content-Type", "image/png")
// .WithBody(Convert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAZdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuMTczbp9jAAAAJ0lEQVQoU2NgUPuPD6Hz0RCEAtJoiAxpCCBXGgmRIo0TofORkdp/AMiMdRVnV6O0AAAAAElFTkSuQmCC"))
// );
//server
// .Given(Request.Create().WithPath("/oauth2/access").UsingPost().WithBody("grant_type=password;username=u;password=p"))
// .RespondWith(Response.Create() // .RespondWith(Response.Create()
// .WithStatusCode(200) // .WithStatusCode(200)
// .WithHeader("Content-Type", "application/json") // .WithHeader("Content-Type", "application/json")
// .WithBody(@"{ ""result"": ""Contains x with FUNC 200""}")); // .WithBodyAsJson(new { access_token = "AT", refresh_token = "RT" }));
server //server
.Given(Request.Create().WithPath("/data").UsingPost().WithBody(b => b.Contains("e"))) // .Given(Request.Create().WithPath("/helloworld").UsingGet().WithHeader("Authorization", new RegexMatcher("^(?i)Bearer AT$")))
.AtPriority(999) // .RespondWith(Response.Create()
.RespondWith(Response.Create() // .WithStatusCode(200)
.WithStatusCode(201) // .WithBody("hi"));
.WithHeader("Content-Type", "application/json")
.WithBodyAsJson(new { result = "data posted with FUNC 201" }));
server //server
.Given(Request.Create().WithPath("/json").UsingPost().WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]"))) // .Given(Request.Create().WithPath("/data").UsingPost().WithBody(b => b.Contains("e")))
.RespondWith(Response.Create() // .AtPriority(999)
.WithStatusCode(201) // .RespondWith(Response.Create()
.WithHeader("Content-Type", "application/json") // .WithStatusCode(201)
.WithBody(@"{ ""result"": ""json posted with 201""}")); // .WithHeader("Content-Type", "application/json")
// .WithBodyAsJson(new { result = "data posted with FUNC 201" }));
server //server
.Given(Request.Create().WithPath("/json2").UsingPost().WithBody("x")) // .Given(Request.Create().WithPath("/json").UsingPost().WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]")))
.RespondWith(Response.Create() // .RespondWith(Response.Create()
.WithStatusCode(201) // .WithStatusCode(201)
.WithHeader("Content-Type", "application/json") // .WithHeader("Content-Type", "application/json")
.WithBody(@"{ ""result"": ""json posted with x - 201""}")); // .WithBody(@"{ ""result"": ""json posted with 201""}"));
server //server
.Given(Request.Create().WithPath("/data").UsingDelete()) // .Given(Request.Create().WithPath("/json2").UsingPost().WithBody("x"))
.RespondWith(Response.Create() // .RespondWith(Response.Create()
.WithStatusCode(200) // .WithStatusCode(201)
.WithHeader("Content-Type", "application/json") // .WithHeader("Content-Type", "application/json")
.WithBody(@"{ ""result"": ""data deleted with 200""}")); // .WithBody(@"{ ""result"": ""json posted with x - 201""}"));
server //server
.Given(Request.Create() // .Given(Request.Create().WithPath("/data").UsingDelete())
.WithPath("/needs-a-key") // .RespondWith(Response.Create()
.UsingGet() // .WithStatusCode(200)
.WithHeader("api-key", "*", MatchBehaviour.AcceptOnMatch) // .WithHeader("Content-Type", "application/json")
.UsingAnyMethod()) // .WithBody(@"{ ""result"": ""data deleted with 200""}"));
.RespondWith(Response.Create()
.WithStatusCode(HttpStatusCode.OK)
.WithBody(@"{ ""result"": ""api-key found""}"));
server //server
.Given(Request.Create() // .Given(Request.Create()
.WithPath("/needs-a-key") // .WithPath("/needs-a-key")
.UsingGet() // .UsingGet()
.WithHeader("api-key", "*", MatchBehaviour.RejectOnMatch) // .WithHeader("api-key", "*", MatchBehaviour.AcceptOnMatch)
.UsingAnyMethod()) // .UsingAnyMethod())
.RespondWith(Response.Create() // .RespondWith(Response.Create()
.WithStatusCode(HttpStatusCode.Unauthorized) // .WithStatusCode(HttpStatusCode.OK)
.WithBody(@"{ ""result"": ""api-key missing""}")); // .WithBody(@"{ ""result"": ""api-key found""}"));
server //server
.Given(Request.Create().WithPath("/nobody").UsingGet()) // .Given(Request.Create()
.RespondWith(Response.Create().WithDelay(TimeSpan.FromSeconds(1)) // .WithPath("/needs-a-key")
.WithStatusCode(200)); // .UsingGet()
// .WithHeader("api-key", "*", MatchBehaviour.RejectOnMatch)
// .UsingAnyMethod())
// .RespondWith(Response.Create()
// .WithStatusCode(HttpStatusCode.Unauthorized)
// .WithBody(@"{ ""result"": ""api-key missing""}"));
server //server
.Given(Request.Create().WithPath("/partial").UsingPost().WithBody(new SimMetricsMatcher(new[] { "cat", "dog" }))) // .Given(Request.Create().WithPath("/nobody").UsingGet())
.RespondWith(Response.Create().WithStatusCode(200).WithBody("partial = 200")); // .RespondWith(Response.Create().WithDelay(TimeSpan.FromSeconds(1))
// .WithStatusCode(200));
// http://localhost:8080/trans?start=1000&stop=1&stop=2 //server
server // .Given(Request.Create().WithPath("/partial").UsingPost().WithBody(new SimMetricsMatcher(new[] { "cat", "dog" })))
.Given(Request.Create().WithPath("/trans").UsingGet()) // .RespondWith(Response.Create().WithStatusCode(200).WithBody("partial = 200"));
.WithGuid("90356dba-b36c-469a-a17e-669cd84f1f05")
.RespondWith(Response.Create()
.WithStatusCode(200)
.WithHeader("Content-Type", "application/json")
.WithHeader("Transformed-Postman-Token", "token is {{request.headers.Postman-Token}}")
.WithHeader("xyz_{{request.headers.Postman-Token}}", "token is {{request.headers.Postman-Token}}")
.WithBody(@"{""msg"": ""Hello world CATCH-ALL on /*, {{request.path}}, bykey={{request.query.start}}, bykey={{request.query.stop}}, byidx0={{request.query.stop.[0]}}, byidx1={{request.query.stop.[1]}}"" }")
.WithTransformer()
.WithDelay(TimeSpan.FromMilliseconds(100))
);
server //// http://localhost:8080/trans?start=1000&stop=1&stop=2
.Given(Request.Create().WithPath("/jsonpathtestToken").UsingPost()) //server
.RespondWith(Response.Create() // .Given(Request.Create().WithPath("/trans").UsingGet())
.WithHeader("Content-Type", "application/json") // .WithGuid("90356dba-b36c-469a-a17e-669cd84f1f05")
.WithBody("{{JsonPath.SelectToken request.body \"$.Manufacturers[?(@.Name == 'Acme Co')]\"}}") // .RespondWith(Response.Create()
.WithTransformer() // .WithStatusCode(200)
); // .WithHeader("Content-Type", "application/json")
// .WithHeader("Transformed-Postman-Token", "token is {{request.headers.Postman-Token}}")
// .WithHeader("xyz_{{request.headers.Postman-Token}}", "token is {{request.headers.Postman-Token}}")
// .WithBody(@"{""msg"": ""Hello world CATCH-ALL on /*, {{request.path}}, bykey={{request.query.start}}, bykey={{request.query.stop}}, byidx0={{request.query.stop.[0]}}, byidx1={{request.query.stop.[1]}}"" }")
// .WithTransformer()
// .WithDelay(TimeSpan.FromMilliseconds(100))
// );
server //server
.Given(Request.Create().WithPath("/zubinix").UsingPost()) // .Given(Request.Create().WithPath("/jsonpathtestToken").UsingPost())
.RespondWith(Response.Create() // .RespondWith(Response.Create()
.WithHeader("Content-Type", "application/json") // .WithHeader("Content-Type", "application/json")
.WithBody("{ \"result\": \"{{JsonPath.SelectToken request.bodyAsJson \"username\"}}\" }") // .WithBody("{{JsonPath.SelectToken request.body \"$.Manufacturers[?(@.Name == 'Acme Co')]\"}}")
.WithTransformer() // .WithTransformer()
); // );
server //server
.Given(Request.Create().WithPath("/zubinix2").UsingPost()) // .Given(Request.Create().WithPath("/zubinix").UsingPost())
.RespondWith(Response.Create() // .RespondWith(Response.Create()
.WithHeader("Content-Type", "application/json") // .WithHeader("Content-Type", "application/json")
.WithBodyAsJson(new { path = "{{request.path}}", result = "{{JsonPath.SelectToken request.bodyAsJson \"username\"}}" }) // .WithBody("{ \"result\": \"{{JsonPath.SelectToken request.bodyAsJson \"username\"}}\" }")
.WithTransformer() // .WithTransformer()
); // );
server //server
.Given(Request.Create().WithPath("/jsonpathtestTokenJson").UsingPost()) // .Given(Request.Create().WithPath("/zubinix2").UsingPost())
.RespondWith(Response.Create() // .RespondWith(Response.Create()
.WithHeader("Content-Type", "application/json") // .WithHeader("Content-Type", "application/json")
.WithBodyAsJson(new { status = "OK", url = "{{request.url}}", transformed = "{{JsonPath.SelectToken request.body \"$.Manufacturers[?(@.Name == 'Acme Co')]\"}}" }) // .WithBodyAsJson(new { path = "{{request.path}}", result = "{{JsonPath.SelectToken request.bodyAsJson \"username\"}}" })
.WithTransformer() // .WithTransformer()
); // );
server //server
.Given(Request.Create().WithPath("/jsonpathtestTokens").UsingPost()) // .Given(Request.Create().WithPath("/jsonpathtestTokenJson").UsingPost())
.RespondWith(Response.Create() // .RespondWith(Response.Create()
.WithHeader("Content-Type", "application/json") // .WithHeader("Content-Type", "application/json")
.WithBody("[{{#JsonPath.SelectTokens request.body \"$..Products[?(@.Price >= 50)].Name\"}} { \"idx\":{{id}}, \"value\":\"{{value}}\" }, {{/JsonPath.SelectTokens}} {} ]") // .WithBodyAsJson(new { status = "OK", url = "{{request.url}}", transformed = "{{JsonPath.SelectToken request.body \"$.Manufacturers[?(@.Name == 'Acme Co')]\"}}" })
.WithTransformer() // .WithTransformer()
); // );
server //server
.Given(Request.Create() // .Given(Request.Create().WithPath("/jsonpathtestTokens").UsingPost())
.WithPath("/state1") // .RespondWith(Response.Create()
.UsingGet()) // .WithHeader("Content-Type", "application/json")
.InScenario("s1") // .WithBody("[{{#JsonPath.SelectTokens request.body \"$..Products[?(@.Price >= 50)].Name\"}} { \"idx\":{{id}}, \"value\":\"{{value}}\" }, {{/JsonPath.SelectTokens}} {} ]")
.WillSetStateTo("Test state 1") // .WithTransformer()
.RespondWith(Response.Create() // );
.WithBody("No state msg 1"));
server //server
.Given(Request.Create() // .Given(Request.Create()
.WithPath("/foostate1") // .WithPath("/state1")
.UsingGet()) // .UsingGet())
.InScenario("s1") // .InScenario("s1")
.WhenStateIs("Test state 1") // .WillSetStateTo("Test state 1")
.RespondWith(Response.Create() // .RespondWith(Response.Create()
.WithBody("Test state msg 1")); // .WithBody("No state msg 1"));
server //server
.Given(Request.Create() // .Given(Request.Create()
.WithPath("/state2") // .WithPath("/foostate1")
.UsingGet()) // .UsingGet())
.InScenario("s2") // .InScenario("s1")
.WillSetStateTo("Test state 2") // .WhenStateIs("Test state 1")
.RespondWith(Response.Create() // .RespondWith(Response.Create()
.WithBody("No state msg 2")); // .WithBody("Test state msg 1"));
server //server
.Given(Request.Create() // .Given(Request.Create()
.WithPath("/foostate2") // .WithPath("/state2")
.UsingGet()) // .UsingGet())
.InScenario("s2") // .InScenario("s2")
.WhenStateIs("Test state 2") // .WillSetStateTo("Test state 2")
.RespondWith(Response.Create() // .RespondWith(Response.Create()
.WithBody("Test state msg 2")); // .WithBody("No state msg 2"));
//server
// .Given(Request.Create()
// .WithPath("/foostate2")
// .UsingGet())
// .InScenario("s2")
// .WhenStateIs("Test state 2")
// .RespondWith(Response.Create()
// .WithBody("Test state msg 2"));
System.Console.WriteLine("Press any key to stop the server"); System.Console.WriteLine("Press any key to stop the server");
System.Console.ReadKey(); System.Console.ReadKey();

View File

@@ -71,6 +71,9 @@
<Content Include="__admin\mappings\11111110-a633-40e8-a244-5cb80bc0ab66.json"> <Content Include="__admin\mappings\11111110-a633-40e8-a244-5cb80bc0ab66.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<None Include="__admin\mappings\873d495f-940e-4b86-a1f4-4f0fc7be8b8b.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\src\WireMock.Net.StandAlone\WireMock.Net.StandAlone.csproj"> <ProjectReference Include="..\..\src\WireMock.Net.StandAlone\WireMock.Net.StandAlone.csproj">

View File

@@ -0,0 +1,19 @@
{
"Guid": "873d495f-940e-4b86-a1f4-4f0fc7be8b8b",
"Priority": 4,
"Request": {
"Path": {},
"Methods": [
"get"
]
},
"Response": {
"StatusCode": 200,
"BodyDestination": "SameAsSource",
"Body": "NO PATH OR URL",
"UseTransformer": false,
"Headers": {
"Content-Type": "application/json"
}
}
}

View File

@@ -21,7 +21,7 @@ namespace WireMock.Serialization
string matcherName = parts[0]; string matcherName = parts[0];
string matcherType = parts.Length > 1 ? parts[1] : null; string matcherType = parts.Length > 1 ? parts[1] : null;
string[] stringPatterns = matcher.Patterns != null ? matcher.Patterns.Cast<string>().ToArray() : new [] { matcher.Pattern as string }; string[] stringPatterns = matcher.Patterns != null ? matcher.Patterns.Cast<string>().ToArray() : new[] { matcher.Pattern as string };
MatchBehaviour matchBehaviour = matcher.RejectOnMatch == true ? MatchBehaviour.RejectOnMatch : MatchBehaviour.AcceptOnMatch; MatchBehaviour matchBehaviour = matcher.RejectOnMatch == true ? MatchBehaviour.RejectOnMatch : MatchBehaviour.AcceptOnMatch;
switch (matcherName) switch (matcherName)
@@ -39,7 +39,7 @@ namespace WireMock.Serialization
return new JsonPathMatcher(matchBehaviour, stringPatterns); return new JsonPathMatcher(matchBehaviour, stringPatterns);
case "XPathMatcher": case "XPathMatcher":
return new XPathMatcher(matchBehaviour, (string) matcher.Pattern); return new XPathMatcher(matchBehaviour, (string)matcher.Pattern);
case "WildcardMatcher": case "WildcardMatcher":
return new WildcardMatcher(matchBehaviour, stringPatterns, matcher.IgnoreCase == true); return new WildcardMatcher(matchBehaviour, stringPatterns, matcher.IgnoreCase == true);
@@ -51,7 +51,7 @@ namespace WireMock.Serialization
throw new NotSupportedException($"Matcher '{matcherName}' with Type '{matcherType}' is not supported."); throw new NotSupportedException($"Matcher '{matcherName}' with Type '{matcherType}' is not supported.");
} }
return new SimMetricsMatcher(matchBehaviour, (string) matcher.Pattern, type); return new SimMetricsMatcher(matchBehaviour, (string)matcher.Pattern, type);
default: default:
throw new NotSupportedException($"Matcher '{matcherName}' is not supported."); throw new NotSupportedException($"Matcher '{matcherName}' is not supported.");

View File

@@ -316,9 +316,9 @@ namespace WireMock.Server
Guid guid = Guid.Parse(requestMessage.Path.TrimStart(AdminMappings.ToCharArray())); Guid guid = Guid.Parse(requestMessage.Path.TrimStart(AdminMappings.ToCharArray()));
var mappingModel = DeserializeObject<MappingModel>(requestMessage); var mappingModel = DeserializeObject<MappingModel>(requestMessage);
DeserializeAndAddOrUpdateMapping(mappingModel, guid); Guid? guidFromPut = DeserializeAndAddOrUpdateMapping(mappingModel, guid);
return ResponseMessageBuilder.Create("Mapping added or updated", 200, guid); return ResponseMessageBuilder.Create("Mapping added or updated", 200, guidFromPut);
} }
private ResponseMessage MappingDelete(RequestMessage requestMessage) private ResponseMessage MappingDelete(RequestMessage requestMessage)
@@ -401,13 +401,18 @@ namespace WireMock.Server
return ResponseMessageBuilder.Create("Mapping added", 201, guid); return ResponseMessageBuilder.Create("Mapping added", 201, guid);
} }
private Guid DeserializeAndAddOrUpdateMapping(MappingModel mappingModel, Guid? guid = null, string path = null) private Guid? DeserializeAndAddOrUpdateMapping(MappingModel mappingModel, Guid? guid = null, string path = null)
{ {
Check.NotNull(mappingModel, nameof(mappingModel)); Check.NotNull(mappingModel, nameof(mappingModel));
Check.NotNull(mappingModel.Request, nameof(mappingModel.Request)); Check.NotNull(mappingModel.Request, nameof(mappingModel.Request));
Check.NotNull(mappingModel.Response, nameof(mappingModel.Response)); Check.NotNull(mappingModel.Response, nameof(mappingModel.Response));
var requestBuilder = InitRequestBuilder(mappingModel.Request); var requestBuilder = InitRequestBuilder(mappingModel.Request, true);
if (requestBuilder == null)
{
return null;
}
var responseBuilder = InitResponseBuilder(mappingModel.Response); var responseBuilder = InitResponseBuilder(mappingModel.Response);
var respondProvider = Given(requestBuilder); var respondProvider = Given(requestBuilder);
@@ -511,7 +516,7 @@ namespace WireMock.Server
{ {
var requestModel = DeserializeObject<RequestModel>(requestMessage); var requestModel = DeserializeObject<RequestModel>(requestMessage);
var request = (Request)InitRequestBuilder(requestModel); var request = (Request)InitRequestBuilder(requestModel, false);
var dict = new Dictionary<LogEntry, RequestMatchResult>(); var dict = new Dictionary<LogEntry, RequestMatchResult>();
foreach (var logEntry in LogEntries.Where(le => !le.RequestMessage.Path.StartsWith("/__admin/"))) foreach (var logEntry in LogEntries.Where(le => !le.RequestMessage.Path.StartsWith("/__admin/")))
@@ -551,7 +556,7 @@ namespace WireMock.Server
} }
#endregion #endregion
private IRequestBuilder InitRequestBuilder(RequestModel requestModel) private IRequestBuilder InitRequestBuilder(RequestModel requestModel, bool pathOrUrlRequired)
{ {
IRequestBuilder requestBuilder = Request.Create(); IRequestBuilder requestBuilder = Request.Create();
@@ -571,11 +576,13 @@ namespace WireMock.Server
} }
} }
bool pathOrUrlmatchersValid = false;
if (requestModel.Path != null) if (requestModel.Path != null)
{ {
if (requestModel.Path is string path) if (requestModel.Path is string path)
{ {
requestBuilder = requestBuilder.WithPath(path); requestBuilder = requestBuilder.WithPath(path);
pathOrUrlmatchersValid = true;
} }
else else
{ {
@@ -583,15 +590,16 @@ namespace WireMock.Server
if (pathModel?.Matchers != null) if (pathModel?.Matchers != null)
{ {
requestBuilder = requestBuilder.WithPath(pathModel.Matchers.Select(MatcherMapper.Map).Cast<IStringMatcher>().ToArray()); requestBuilder = requestBuilder.WithPath(pathModel.Matchers.Select(MatcherMapper.Map).Cast<IStringMatcher>().ToArray());
pathOrUrlmatchersValid = true;
} }
} }
} }
else if (requestModel.Url != null)
if (requestModel.Url != null)
{ {
if (requestModel.Url is string url) if (requestModel.Url is string url)
{ {
requestBuilder = requestBuilder.WithUrl(url); requestBuilder = requestBuilder.WithUrl(url);
pathOrUrlmatchersValid = true;
} }
else else
{ {
@@ -599,10 +607,17 @@ namespace WireMock.Server
if (urlModel?.Matchers != null) if (urlModel?.Matchers != null)
{ {
requestBuilder = requestBuilder.WithUrl(urlModel.Matchers.Select(MatcherMapper.Map).Cast<IStringMatcher>().ToArray()); requestBuilder = requestBuilder.WithUrl(urlModel.Matchers.Select(MatcherMapper.Map).Cast<IStringMatcher>().ToArray());
pathOrUrlmatchersValid = true;
} }
} }
} }
if (pathOrUrlRequired && !pathOrUrlmatchersValid)
{
_logger.Error("Path or Url matcher is missing for this mapping, this mapping will not be added.");
return null;
}
if (requestModel.Methods != null) if (requestModel.Methods != null)
{ {
requestBuilder = requestBuilder.UsingMethod(requestModel.Methods); requestBuilder = requestBuilder.UsingMethod(requestModel.Methods);