-
-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#70 Added the "Exists" predicate functionality #72
Conversation
Thanks! I'll try to find time to take a look at this and #73 sometime in the next day or so. Don't worry about the failing build, I'll take care of that later and just run the tests locally for now. |
I'm not sure your solution will work for all of the use cases of the exists predicate. It works for
You wouldn't be able to do this with the current I had added the The only other option that comes to mind right now is updating Do you have any other ideas? |
I was also able to fix the build so I re-ran it on both your PRs. |
Thought about this a little more today and I'm fine with the That change will not be backwards-compatible though so it will need to be part of the next major version (v5) of the package that I'm currently working on. I'm not sure when 5.0.0 will be published since I have quite a few changes I'd like to add before that, but I've been publishing pre-release versions of that package for a while. I will probably just push another pre-release after this is merged. |
Ah I see what you mean. Looks like I've not used that I believe the move to I've experimented with this in the past and I think the correct way to specify multiple headers with the same name in mountebank is like so: "headers": {
"testHeader": ["123", "456"]
} Run through Postman, I get the following in the response: As such, it may need to support collections too, and |
Just for fun's sake and throwing out ideas: if we really wanted to restrict the types of values users can set, we could write a custom The [JsonConverter(typeof(BoolOrStringJsonConverter))]
public class BoolOrString
{
private readonly object _value;
private BoolOrString(object value)
{
_value = value;
}
public static implicit operator BoolOrString(bool input)
{
return new BoolOrString(input);
}
public static implicit operator BoolOrString(string input)
{
return new BoolOrString(input);
}
public object GetValue()
{
return _value;
}
} The custom JSON Converter: public class BoolOrStringJsonConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return true;
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var boolOrStringValue = value as BoolOrString;
writer.WriteValue(boolOrStringValue.GetValue());
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
throw new NotImplementedException();
}
} The usage: var myDictionary = new Dictionary<string, BoolOrString>();
myDictionary["boolType"] = true;
myDictionary["stringType"] = "hello world";
Console.WriteLine(JsonConvert.SerializeObject(myDictionary)); Which would ultimately result in the following JSON: {
"boolType": true,
"stringType": "hello world"
} But perhaps it's slightly ugly. |
Alternatively, have you considered using a different HttpPredicateFields class specific to the It's also possible to leave full control in the hands of the user and to use the I'm still a fan of the |
I had considered both of those options as well. I really don't care for the added complexity of a custom |
I'm going to go ahead and merge this and just fix the other types in a subsequent commit. |
Exists predicate works like matches/equals/etc. with HttpPredicateFields. The difference as far as Mountebank is concerned, is that exists expects boolean values to indicate whether a parameter exists or not. E.g, if we apply an equals predicate on the request body as such:
Then the request body of an http request will need an
id
of '1234' andcontent.title
of 'Hello World'.If instead we used an exists predicate, it may look like:
Which specifies that the request body of an http request must have
id
andcontent.title
values regardless of what the values actually are.