fluentassertions / fluentassertions.json

NewtonSoft.Json extensions for FluentAssertions
Apache License 2.0
72 stars 26 forks source link

JToken.Should().BeEquivalentTo(differentJToken) returns exception #7

Open jakubozga opened 7 years ago

jakubozga commented 7 years ago

Hello,

Lately I found that if you have 2 different JTokens and call Should().BeEquivalentTo(...) you will get: "System.FormatException: Input string was not in a correct format." instead of error message.

My guess is that this exception is caused because code is trying to call string.Format(JToken). JToken contains characters like { and } which should be escaped to {{ and }}

dennisdoomen commented 7 years ago

Was that BeEquivalentTo(...) provided by the FluentAssertions.Json package or the core library?

lancerdima commented 7 years ago

Hi,

Decided to try out your library, and hit the same issue reported by @jakubozga . In my case:

Stack Trace:

at System.Text.StringBuilder.FormatError() at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args) at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args) at System.String.Format(String format, Object[] args) at FluentAssertions.Execution.MessageBuilder.FormatArgumentPlaceholders(String failureMessage, Object[] failureArgs) at FluentAssertions.Execution.MessageBuilder.Build(String message, Object[] messageArgs, String reason, ContextDataItems contextData) at FluentAssertions.Execution.AssertionScope.FailWith(String message, Object[] args) at FluentAssertions.Json.JTokenAssertions.BeEquivalentTo(JToken expected, String because, Object[] becauseArgs)

Could it be that your MessageBuilder class in the original FluentAssertions app is not handling well messages without placeholders? JSON's BeEquivalentTo is the only extension method that use FailWith message without placeholders.

dennisdoomen commented 7 years ago

Could it be that your MessageBuilder class in the original FluentAssertions app is not handling well messages without placeholders?

Yes, there was a problem in 4.19.3. See https://github.com/fluentassertions/fluentassertions/releases/tag/4.19.3

lancerdima commented 7 years ago

Using versions: FluentAssertions - v4.19.4 FluentAssertions.Json - v4.20.0

Issue seems to be away with pre-release 5.0.0-beta0002 and 5.0.0-beta0003.

dennisdoomen commented 7 years ago

Hmm, I found the fix. Unfortunately, I can't resolve this issue on 4.x. You'll have to wait for 5.0.

304NotModified commented 2 years ago

@dennisdoomen Guess this could be closed? (V6 is released)

dennisdoomen commented 2 years ago

Not sure. Completely lost track of this one.