-
Notifications
You must be signed in to change notification settings - Fork 26
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
HaveElementWithValue? #39
Comments
No, but we do accept contributions ;-) |
In the FluentAssertions core library I can only think of dictionary.Should().Contain(1, "One"); which could also be written as dictionary.Should().ContainKey(1)
.WhichValue.Should().Be("One"); In FluentAssertions.Json the proposed var subject = JToken.Parse("{ 'id': 42 }");
subject.Should().HaveElementAndValue("id", "42"); can also be written as either var subject = JToken.Parse("{ 'id': 42 }");
subject.Should().HaveElement("id")
.Which.Should().HaveValue("42"); or var subject = JToken.Parse("{ 'id': 42 }");
subject.Should().HaveElement("id")
.Which.Value<string>().Should().Be("42"); Using the existing
var subject = JToken.Parse("{ 'id': [42] }");
subject.Should().HaveElement("id")
.Which.Values<int>().Should().ContainSingle()
.Which.Should().Be(42); |
Not only do I like it, but I wasn't even aware of the Thank you 💐 |
Related: fluentassertions/fluentassertions#1355. |
But does that mean we still see value in #39? |
I haven't really used FA.Json that much, but I'm not seeing cases for |
The use case I encountered is just like you described with the dictionary value. |
But would |
It actually would. A syntax sugar would be nice tho. Like in dictionary, as Jonas mentioned. |
I haven't dug into the history of
To be clear, the existence of |
But I don't mind it either. Having a useful shortcut is fine by me. |
Then we're left with the naming to be decided. Let's continue this conversation in #40. |
The naming is fine by me. |
I'm a bit confused whether we're agreeing on |
I think there's two discussions:
I know that we can accomplish the same with a combination of |
After a nights sleep, I'm fine adding it. Regarding the method signature, I'm looking at https://en.wikipedia.org/wiki/JSON#Data_types_and_syntax to get a picture of possible scenarios.
|
Json is text only, so why don't we stick to a string and a Jtoken overload? |
I like this.
Eventho JSON is text only, |
Hi,
I wish there was a way to assert a
JObject
contains an element with a value as specified.Is there another better way for that I'm unaware of?
The text was updated successfully, but these errors were encountered: