FluentAssertions.Web icon indicating copy to clipboard operation
FluentAssertions.Web copied to clipboard

Showing binary requests in test logs causes issues in Visual Studio

Open Reikooters opened this issue 2 years ago • 1 comments

Firstly, thanks for your work on the library - has made testing web APIs very easy.

I've encountered an issue with logs when sending binary requests. I'm testing an image upload endpoint and in my test I'm uploading a high resolution jpg file which is 900kb (testing that the server downscales large images to a specified max resolution correctly and such before storing the file).

When the test passes everything is good, but if it fails,

  1. the test log tries to show the binary as text and produces weird characters, eventually truncates the body in the log - this one doesn't bother me, although I don't know what potential issues there are in trying to display binary as text
  2. the real issue is when you try to view the test explorer panel in Visual Studio, Visual Studio becomes unresponsive - for 20 sec or so - until I guess it gives up on showing the tree of tests. It'll draw all the tests in the list up until the failed test. At that point, the status icon next to the failed test, and everything that should appear below that test (i.e. other tests), aren't drawn.

image

And VS as a whole is largely unusable unless you change the panel to something other than the test explorer.

If you go to a test in code, click on "Show in test explorer", then wait out the 20+ sec, it then becomes possible to read the log message (as per my point 1) to try to resolve it to get the test to pass. But yeah - if the log can be improved to not show binary data or perhaps show it as a hex string, this might help the problem, or perhaps it's to do with how it tries to find the point to truncate the body that has an issue when reading binary.

I have attached a sample project which reproduces the issue. If you go into the test project, under /Controllers/MyApiControllerTests.cs, the first test should return 200 OK but I've made the test assert for 400 bad request just to force the test to fail - you can comment this and uncomment the check for 200 OK to get the test to pass. I also added a 2nd test just to demonstrate that VS stops drawing tests below as per screenshot above, but I realise this is to do with the VS GUI and not the library.

TestAPIWithBinary.zip

Let me know if there is any more information I can provide.

Reikooters avatar Aug 10 '22 20:08 Reikooters

@Reikooters I will take a look and thanks for the zip

adrianiftode avatar Aug 23 '22 14:08 adrianiftode

This issue has been fixed in the 1.2.2 release, thanks again for reporting it.

Just a note, the ReSharper runner did not freeze when running these tests. I guess there is a problem with Visual Studio too, as it shouldn't really crash and handle it gracefully.

adrianiftode avatar Sep 11 '22 14:09 adrianiftode