Skip to content
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

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

Open
jakubozga opened this issue Sep 4, 2017 · 7 comments
Open

Comments

@jakubozga
Copy link

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
Copy link
Member

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

@lancerdima
Copy link

lancerdima commented Oct 3, 2017

Hi,

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

  • Library is used in netcoreapp2.0 test project
  • I made sure BeEquivalentTo(...) operation is provided by FluentAssertions.Json package, JTokenAssertions class
  • I am comparing two JTokens extracted from HttpRequestMessage StringContents

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
Copy link
Member

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
Copy link

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
Copy link
Member

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

@304NotModified
Copy link

304NotModified commented Dec 7, 2021

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

@dennisdoomen
Copy link
Member

Not sure. Completely lost track of this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants