|
1 | 1 | using System; |
2 | 2 | using System.Data.Common; |
| 3 | +using System.Globalization; |
3 | 4 | using System.IO; |
4 | 5 | using System.Net; |
5 | 6 | using System.Net.Http; |
| 7 | +using System.Net.Http.Formatting; |
6 | 8 | using System.Text; |
7 | 9 | using System.Text.RegularExpressions; |
8 | 10 | using System.Threading.Tasks; |
|
11 | 13 | using JSONAPI.Json; |
12 | 14 | using Microsoft.Owin.Testing; |
13 | 15 | using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 16 | +using Newtonsoft.Json; |
| 17 | +using Newtonsoft.Json.Converters; |
| 18 | +using Newtonsoft.Json.Linq; |
14 | 19 | using Owin; |
15 | 20 |
|
16 | 21 | namespace JSONAPI.AcceptanceTests.EntityFrameworkTestWebApp.Tests |
@@ -39,13 +44,28 @@ protected virtual async Task AssertResponseContent(HttpResponseMessage response, |
39 | 44 | { |
40 | 45 | var redactedResponse = GuidRegex.Replace(responseContent, "{{SOME_GUID}}"); |
41 | 46 | actualResponse = StackTraceRegex.Replace(redactedResponse, "\"stackTrace\":\"{{STACK_TRACE}}\""); |
| 47 | + actualResponse.Should().Be(expectedResponse); |
42 | 48 | } |
43 | 49 | else |
44 | 50 | { |
45 | 51 | actualResponse = responseContent; |
| 52 | + JsonSerializerSettings settings = new JsonSerializerSettings |
| 53 | + { |
| 54 | + DateTimeZoneHandling = DateTimeZoneHandling.Utc, |
| 55 | + DateFormatString = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffff+00:00", |
| 56 | + Culture = CultureInfo.InvariantCulture, |
| 57 | + Formatting = Formatting.Indented |
| 58 | + }; |
| 59 | + |
| 60 | + var actualResponseJObject = JsonConvert.DeserializeObject(actualResponse) as JObject; |
| 61 | + var expectedResponseJObject = JsonConvert.DeserializeObject(expectedResponse) as JObject; |
| 62 | + var equals = JToken.DeepEquals(actualResponseJObject, expectedResponseJObject); |
| 63 | + if (!equals) |
| 64 | + { |
| 65 | + Assert.Fail("should be: " + JsonConvert.SerializeObject(expectedResponseJObject, settings) + "\n but was: " + JsonConvert.SerializeObject(actualResponseJObject, settings)); |
| 66 | + } |
46 | 67 | } |
47 | 68 |
|
48 | | - actualResponse.Should().Be(expectedResponse); |
49 | 69 | response.Content.Headers.ContentType.MediaType.Should().Be(JsonApiContentType); |
50 | 70 | response.Content.Headers.ContentType.CharSet.Should().Be("utf-8"); |
51 | 71 |
|
|
0 commit comments