Comments (21)
WIKI --> https://github.com/WireMock-Net/WireMock.Net/wiki/Scenarios-and-States
from wiremock.net.
No plans, until your question ;-)
I'll take a look at the idea and check if this can be implemented in WireMock.net
from wiremock.net.
I have implemented this functionality for in-process solution. but I can't create PR as have no permissions.
Could you give me permissions to push a new branch?
from wiremock.net.
Mostly the idea is simply to add such syntax:
_server .Given(Request.Create() .WithPath("/foo") .UsingGet()) .WillSetStateTo("Test state") .RespondWith(Response.Create() .WithStatusCode(200) .WithBody(@"No state msg"));
_server .Given(Request.Create() .WithPath("/foo") .UsingGet()) .WhenStateIs("Test state") .RespondWith(Response.Create() .WithStatusCode(200) .WithBody(@"Test state msg"));
from wiremock.net.
What you can do is fork this project, and then build your changes there and then make a PR to this project. Or what you also can do, is zip your changes and provide this code to me.
from wiremock.net.
Created a PR #49
from wiremock.net.
I see, currently reviewing and testing.
from wiremock.net.
had to add 1 update: in case the next state is not specified - the current will not be changed (will not be set to NULL)
from wiremock.net.
I will look, however I'm also looking to build in support for multiple states or scenarios.
from wiremock.net.
multiple states
what do you mean by multiple states? do you have any examples?
scenarios
are you talking about something similar to inScenario("To do list")
?
Do you want to keep backward compatibility?
from wiremock.net.
Multiple states : Be able to define multiple states which will behave.
Scenarios : I think I like the original idea from wiremock.org I'm building the code based on your PR.
from wiremock.net.
Multiple states : Be able to define multiple states which will behave.
I see. something like WhenState(params object[] states)
?
I think I like the original idea from wiremock.org
do you plan to keep backward compatibility?
from wiremock.net.
in case you decided what is the expected semantic and contract I can update PR
from wiremock.net.
Thanks for the offer, but currently I'm trying to build it according to my idea, I'll let you know if I need help.
Multiple states means ; multiple parallel states should be supported, like unit-test as defined below should be fine:
[Fact]
public async Task Should_process_request_if_equals_state_and_multiple_state_defined()
{
// given
_server = FluentMockServer.Start();
_server
.Given(Request.Create()
.WithPath("/state1")
.UsingGet())
.InScenario("s1")
.WillSetStateTo("Test state 1")
.RespondWith(Response.Create()
.WithBody("No state msg 1"));
_server
.Given(Request.Create()
.WithPath("/foo")
.UsingGet())
.InScenario("s1")
.WhenStateIs("Test state 1")
.RespondWith(Response.Create()
.WithBody("Test state msg 1"));
_server
.Given(Request.Create()
.WithPath("/state2")
.UsingGet())
.InScenario("s2")
.WillSetStateTo("Test state 2")
.RespondWith(Response.Create()
.WithBody("No state msg 2"));
_server
.Given(Request.Create()
.WithPath("/foo")
.UsingGet())
.InScenario("s2")
.WhenStateIs("Test state 2")
.RespondWith(Response.Create()
.WithBody("Test state msg 2"));
// when
string url = "http://localhost:" + _server.Ports[0];
var responseNoState1 = await new HttpClient().GetStringAsync(url + "/state1");
var responseNoState2 = await new HttpClient().GetStringAsync(url + "/state2");
var responseWithState1 = await new HttpClient().GetStringAsync(url + "/foo");
var responseWithState2 = await new HttpClient().GetStringAsync(url + "/foo");
// then
Check.That(responseNoState1).Equals("No state msg 1");
Check.That(responseWithState1).Equals("Test state msg 1");
Check.That(responseNoState2).Equals("No state msg 2");
Check.That(responseWithState2).Equals("Test state msg 2");
}
from wiremock.net.
looks good. will use this syntax meanwhile.
thank you
from wiremock.net.
See my code at https://github.com/WireMock-Net/WireMock.Net/tree/stateful-behavior
I'll extend this code to also support the JSON for this...
from wiremock.net.
Code merged to master, still need to add some text to wiki...
from wiremock.net.
looks great!
do you have any plans to update the package on nuget.org?
from wiremock.net.
Yes, I think I can release version 1.0.2.4 on NuGet. I keep you informed here when.
from wiremock.net.
Done
from wiremock.net.
thanks a lot!
from wiremock.net.
Related Issues (20)
- Use mocked response data in Webhook body data HOT 3
- Compilation Error due to 'MessageOptions' Type Conflict between 'Google.Protobuf' and 'WireMock.Net' HOT 4
- FluentAssertions - Actual body is not displayed in error message when using Json Body HOT 6
- Did the ThrowExceptionWhenMatcherFails option got removed from 1.5.16 to 1.5.51? HOT 4
- Regex support for JsonMatcher HOT 10
- Wiremock not working with NUnit3 in .Net Framework 4.6.1 after Wiremock 1.5.47 HOT 3
- Feature: support multipart body in `IRequestMessage` HOT 6
- FindLogEntries present in WireMockServer but not IWireMockServer HOT 1
- Is there a way to record API calls in the file format required for WireMock Testcontainers? HOT 1
- When using C# code generation WithBody() matcher is not generated for POST Request HOT 3
- GUIDs generated by WireMock.NET differ between instances when deployed to Azure with multiple instances. HOT 6
- Encoded url path parameter decoded via proxy
- Multiple Matchers MatchOperator HOT 5
- Should my URL be replaced with 'localhost' HOT 8
- WireMock standalone and Linqpad HOT 2
- Master branch doesn't build HOT 1
- C# Unit test: Wiremock Server runs but does not deliver response HOT 2
- Docs: Documentation is misleading/incomplete for BodyAsFile HOT 1
- Response Templating complex objects HOT 11
- Connection prematurely closed BEFORE response HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wiremock.net.