Skip to content

Commit

Permalink
Removed re-indent of response body on HTTP status code mismatch in te…
Browse files Browse the repository at this point in the history
…sts, because we already use indenting in TestableStartup, so this is no longer needed.
  • Loading branch information
Bart Koelman committed Sep 7, 2021
1 parent 4156990 commit 572a521
Showing 1 changed file with 1 addition and 25 deletions.
26 changes: 1 addition & 25 deletions test/TestBuildingBlocks/HttpResponseMessageExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using FluentAssertions;
using FluentAssertions.Primitives;
using JetBrains.Annotations;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace TestBuildingBlocks
{
Expand All @@ -32,33 +29,12 @@ public AndConstraint<HttpResponseMessageAssertions> HaveStatusCode(HttpStatusCod
{
if (Subject.StatusCode != statusCode)
{
string responseText = GetFormattedContentAsync(Subject).Result;
string responseText = Subject.Content.ReadAsStringAsync().Result;
Subject.StatusCode.Should().Be(statusCode, $"response body returned was:\n{responseText}");
}

return new AndConstraint<HttpResponseMessageAssertions>(this);
}

private static async Task<string> GetFormattedContentAsync(HttpResponseMessage responseMessage)
{
string text = await responseMessage.Content.ReadAsStringAsync();

try
{
if (text.Length > 0)
{
return JsonConvert.DeserializeObject<JObject>(text)?.ToString();
}
}
#pragma warning disable AV1210 // Catch a specific exception instead of Exception, SystemException or ApplicationException
catch
#pragma warning restore AV1210 // Catch a specific exception instead of Exception, SystemException or ApplicationException
{
// ignored
}

return text;
}
}
}
}

0 comments on commit 572a521

Please sign in to comment.