1
+ using System ;
1
2
using System . Collections . Generic ;
2
3
using System . Linq ;
3
4
using System . Net ;
4
5
using System . Net . Http ;
5
6
using System . Net . Http . Headers ;
6
7
using System . Threading . Tasks ;
7
8
using Bogus ;
9
+ using JsonApiDotNetCore . Models ;
8
10
using JsonApiDotNetCore . Serialization ;
9
11
using JsonApiDotNetCoreExample . Data ;
10
12
using JsonApiDotNetCoreExample . Models ;
@@ -50,27 +52,26 @@ public async Task Can_Fetch_Many_To_Many_Through_All()
50
52
51
53
var route = $ "/api/v1/articles?include=tags";
52
54
53
-
54
-
55
55
// act
56
56
var response = await _fixture . Client . GetAsync ( route ) ;
57
57
58
58
// assert
59
59
var body = await response . Content . ReadAsStringAsync ( ) ;
60
60
Assert . True ( HttpStatusCode . OK == response . StatusCode , $ "{ route } returned { response . StatusCode } status code with payload: { body } ") ;
61
61
62
- Assert . True ( body . Contains ( "include" ) ) ;
62
+ var document = JsonConvert . DeserializeObject < Documents > ( body ) ;
63
+ Assert . NotEmpty ( document . Included ) ;
63
64
64
65
var articleResponseList = _fixture . GetService < IJsonApiDeSerializer > ( ) . DeserializeList < Article > ( body ) ;
65
66
Assert . NotNull ( articleResponseList ) ;
67
+
66
68
var articleResponse = articleResponseList . FirstOrDefault ( a => a . Id == article . Id ) ;
67
69
Assert . NotNull ( articleResponse ) ;
68
70
Assert . Equal ( article . Name , articleResponse . Name ) ;
69
71
70
72
var tagResponse = Assert . Single ( articleResponse . Tags ) ;
71
73
Assert . Equal ( tag . Id , tagResponse . Id ) ;
72
74
Assert . Equal ( tag . Name , tagResponse . Name ) ;
73
-
74
75
}
75
76
76
77
[ Fact ]
@@ -96,7 +97,9 @@ public async Task Can_Fetch_Many_To_Many_Through_GetById()
96
97
// assert
97
98
var body = await response . Content . ReadAsStringAsync ( ) ;
98
99
Assert . True ( HttpStatusCode . OK == response . StatusCode , $ "{ route } returned { response . StatusCode } status code with payload: { body } ") ;
99
- Assert . True ( body . Contains ( "include" ) ) ;
100
+
101
+ var document = JsonConvert . DeserializeObject < Document > ( body ) ;
102
+ Assert . NotEmpty ( document . Included ) ;
100
103
101
104
var articleResponse = _fixture . GetService < IJsonApiDeSerializer > ( ) . Deserialize < Article > ( body ) ;
102
105
Assert . NotNull ( articleResponse ) ;
@@ -105,7 +108,6 @@ public async Task Can_Fetch_Many_To_Many_Through_GetById()
105
108
var tagResponse = Assert . Single ( articleResponse . Tags ) ;
106
109
Assert . Equal ( tag . Id , tagResponse . Id ) ;
107
110
Assert . Equal ( tag . Name , tagResponse . Name ) ;
108
-
109
111
}
110
112
111
113
[ Fact ]
0 commit comments