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
Assertion for key-value-pair #3470
Comments
I like your last option (which doesn't exist yet) but even better, for consistency, I'd prefer one of these...
The first alternate does not yet exist, while the second exists but means something else. Both require the existing initial constraint to work in two ways, depending on whether it was followed by a further constraint. There are examples of how we already do that in the code for detecting properties and attributes. Note that for readability, you can already throw |
I looked a bit more into the code base and successfully played around with an implementation. Using the
The later part should still target That's why I tried to use another keyword ( If you still prefer to use From an implementation perspecitive, I like the |
I get what you are saying about double meanings, but that ship has sailed. 😄 We already have both For the Contains.XXX part, |
Thanks for the explanation. Then it‘s definitely best to keep it consistent with the properties and use I will give it a look on Monday and prepare a PR :) I‘m usually not afraid of depths in code ;) |
You can consider "deeper" to mean "I wish I had written it more transparently in the first place." 😄 |
@nunit/framework-team Please review what @Falco20019 says he wants to do and let him now if it seems like a reasonable syntax that won't surprise anybody. As y'all know, I kibitz here but don't make decisions these days. 😺 If you feel that modifications to what can come after
If the third form is provided, then the second may not be needed, since you could use |
I think it is a reasonable request. Personally, I feel that variant 5 reads best as it is the intention of the test. That is how I would describe the test in English. // --- Variant 5 (some API I would prefer but can't find) ---
Assert.That(result, Contains.Key("Test").WithValue(1));
Assert.That(result, Contains.Key("Test2").WithValue(42)); I think that |
You could use Assert.That(result, Contains.Item(KeyValuePair.Create("Test", 1)));
Assert.That(result, Contains.Item(KeyValuePair.Create("Test2", 42))); Alternative suggestion - allow to test equality of Assert.That(result, Does.Contain(("Key", "Value")))``` |
@Dreamescaper I like the look of the tuple option, but it isn't really discoverable through intellisense like the |
Is there an ETA for 3.13? 3.12 was a year ago. |
Not that I know of. @rprouse Is there anything in the milestone that can't wait for 3.14? |
The only thing I can think of is that it would be nice to get #2574 included. I planned to figure out its status this weekend, and will perhaps have time tomorrow. |
@Falco20019 It's always hard to say for a team of volunteers. Some of us are more affected by the current times than others. You can use https://www.myget.org/feed/nunit/package/nuget/NUnit in the meantime. |
@jnm2 I totally understand that :) I only saw that some of the fixed issues wait for over a year to be released. And if there is nothing blocking a minor release (that has been tested), I prefer to release more minors instead of wait for a year for each. Personally, I only asked to know if we should just get a build from the feed or wait for an release. |
I was looking for a good way to check key-value-pairs. I know about
DictionaryContainsKeyConstraint
andDictionaryContainsValueConstraint
, but have not found any option to combine them on the same item. Chaining it withAnd
will also operate on the asserted value and not on the item identified by the key.It would be pretty easy to implement an
DictionaryContainsKeyValueConstraint
that implements theMatches
method usingTryGet
. It's also easy to add theWithValue
method toDictionaryContainsKeyConstraint
and have it work with all notations (Contains.Key
,Does.ContainKey
, ...). But before doing a PR, I wanted to know if there already is a good way of doing it and just not finding it.The text was updated successfully, but these errors were encountered: