-
Notifications
You must be signed in to change notification settings - Fork 51
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
Is there a possibility to control the checked values? #326
Comments
Hello |
That is indeed what I ended up doing, however it forced me to re-implement the checks and I couldn't use some extension methods I have to check that specific the specific key is actually in there. So instead of saying: .FailWhen(sut => !sut.ContainsKey(expectedKey), "Key not found.")
.DefineCheckedValues(sut => sut.Select(x => x.Key)) I had to do: .CheckSutAttributes(sut => sut.Select(x => x.Key).ToArray(), "keys")
.FailWhen(sut => !sut.Any(x => x == expectedKey), "Key not found.") The advantage of the first version is that you can expand the check to also check the values, which is not as easy as the second version. |
Thanks for your input. I am still considering how to properly address this. I must say I have yet to come with a more convenient solution. Based on your example, you can achieve this with .Analyze((sut, context) =>
{
if (!sut.ContainsKey(x))
{
context.Fails($"Key {x} not found. Existing keys:{string.Join(',', sut.Select( t => t.Key))}.");
}
if (sut[x] != xValue)
{
context.Fails("The entry does not have the expected value: {sut[x]} instead of {xValue}."):
}
}).EndCheck(); What do you think? |
Expected Behavior
I am writing some custom checks where I would like to have more control over the checked values. This might be benifitial for the
ContainsKey
checks as well, so I use that as an example.When I write the following check:
I want to have the following message:
Current Behavior
Currently I get the following error message:
Possible Solution
For the expected value I can already use the method
DefineExpectedResult
.Would it be possible to get a
DefineCheckedValues
, or a way to add a formatter for the checked value?Context
As said, I am writing some custom checks. These checks are around the HttpResponseMessage where I want to check for specific header names, but I don't want to show the value of the header. However, in other tests I do want to show the header value, but now I only see "{[Header, System.String[]]} (1 item)"
Your Environment
The text was updated successfully, but these errors were encountered: