Skip to content

Commit b3f8dec

Browse files
author
Bart Koelman
committed
Fix cibuild
1 parent e9dc639 commit b3f8dec

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

test/JsonApiDotNetCoreExampleTests/Acceptance/SerializationTests.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Threading.Tasks;
44
using JsonApiDotNetCoreExample.Models;
55
using JsonApiDotNetCoreExampleTests.Acceptance.Spec;
6+
using JsonApiDotNetCoreExampleTests.Helpers.Extensions;
67
using Newtonsoft.Json;
78
using Newtonsoft.Json.Linq;
89
using Xunit;
@@ -43,10 +44,9 @@ public async Task When_getting_person_it_must_match_JSON_text()
4344
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
4445

4546
var bodyText = await response.Content.ReadAsStringAsync();
46-
var token = JsonConvert.DeserializeObject<JToken>(bodyText);
47-
var bodyFormatted = NormalizeLineEndings(token.ToString());
47+
var json = JsonConvert.DeserializeObject<JToken>(bodyText).ToString();
4848

49-
var expectedText = NormalizeLineEndings(@"{
49+
var expected = @"{
5050
""meta"": {
5151
""copyright"": ""Copyright 2015 Example Corp."",
5252
""authors"": [
@@ -123,13 +123,8 @@ public async Task When_getting_person_it_must_match_JSON_text()
123123
""self"": ""http://localhost/api/v1/people/123""
124124
}
125125
}
126-
}");
127-
Assert.Equal(expectedText, bodyFormatted);
128-
}
129-
130-
private static string NormalizeLineEndings(string text)
131-
{
132-
return text.Replace("\r\n", "\n").Replace("\r", "\n");
126+
}";
127+
Assert.Equal(expected.NormalizeLineEndings(), json.NormalizeLineEndings());
133128
}
134129
}
135130
}

test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/FetchingRelationshipsTests.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using JsonApiDotNetCoreExample;
99
using JsonApiDotNetCoreExample.Data;
1010
using JsonApiDotNetCoreExample.Models;
11+
using JsonApiDotNetCoreExampleTests.Helpers.Extensions;
1112
using Microsoft.AspNetCore;
1213
using Microsoft.AspNetCore.Hosting;
1314
using Microsoft.AspNetCore.TestHost;
@@ -60,7 +61,7 @@ public async Task When_getting_existing_ToOne_relationship_it_should_succeed()
6061

6162
var json = JsonConvert.DeserializeObject<JObject>(body).ToString();
6263

63-
Assert.Equal(@"{
64+
string expected = @"{
6465
""links"": {
6566
""self"": ""http://localhost/api/v1/todoItems/" + todoItem.StringId + @"/relationships/owner"",
6667
""related"": ""http://localhost/api/v1/todoItems/" + todoItem.StringId + @"/owner""
@@ -69,7 +70,8 @@ public async Task When_getting_existing_ToOne_relationship_it_should_succeed()
6970
""type"": ""people"",
7071
""id"": """ + todoItem.Owner.StringId + @"""
7172
}
72-
}", json);
73+
}";
74+
Assert.Equal(expected.NormalizeLineEndings(), json.NormalizeLineEndings());
7375
}
7476

7577
[Fact]
@@ -112,7 +114,7 @@ public async Task When_getting_existing_ToMany_relationship_it_should_succeed()
112114

113115
var json = JsonConvert.DeserializeObject<JObject>(body).ToString();
114116

115-
Assert.Equal(@"{
117+
var expected = @"{
116118
""links"": {
117119
""self"": ""http://localhost/api/v1/authors/" + author.StringId + @"/relationships/articles"",
118120
""related"": ""http://localhost/api/v1/authors/" + author.StringId + @"/articles""
@@ -127,7 +129,9 @@ public async Task When_getting_existing_ToMany_relationship_it_should_succeed()
127129
""id"": """ + author.Articles[1].StringId + @"""
128130
}
129131
]
130-
}", json);
132+
}";
133+
134+
Assert.Equal(expected.NormalizeLineEndings(), json.NormalizeLineEndings());
131135
}
132136

133137
[Fact]
@@ -156,7 +160,8 @@ public async Task When_getting_related_missing_to_one_resource_it_should_succeed
156160
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
157161

158162
var json = JsonConvert.DeserializeObject<JObject>(body).ToString();
159-
Assert.Equal(@"{
163+
164+
var expected = @"{
160165
""meta"": {
161166
""copyright"": ""Copyright 2015 Example Corp."",
162167
""authors"": [
@@ -169,7 +174,9 @@ public async Task When_getting_related_missing_to_one_resource_it_should_succeed
169174
""self"": ""http://localhost/api/v1/todoItems/" + todoItem.StringId + @"/owner""
170175
},
171176
""data"": null
172-
}", json);
177+
}";
178+
179+
Assert.Equal(expected.NormalizeLineEndings(), json.NormalizeLineEndings());
173180
}
174181

175182
[Fact]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace JsonApiDotNetCoreExampleTests.Helpers.Extensions
2+
{
3+
public static class StringExtensions
4+
{
5+
public static string NormalizeLineEndings(this string text)
6+
{
7+
return text.Replace("\r\n", "\n").Replace("\r", "\n");
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)