1
- using System . Linq ;
1
+ using System ;
2
+ using System . Linq ;
2
3
using System . Net ;
3
4
using System . Net . Http ;
4
5
using System . Threading . Tasks ;
8
9
using JsonApiDotNetCoreExample ;
9
10
using JsonApiDotNetCoreExample . Data ;
10
11
using JsonApiDotNetCoreExample . Models ;
11
- using Microsoft . AspNetCore . Hosting ;
12
- using Microsoft . AspNetCore . TestHost ;
13
12
using Newtonsoft . Json ;
14
13
using Xunit ;
15
14
using Person = JsonApiDotNetCoreExample . Models . Person ;
@@ -44,17 +43,13 @@ public async Task Can_Filter_On_Guid_Properties()
44
43
var todoItem = _todoItemFaker . Generate ( ) ;
45
44
context . TodoItems . Add ( todoItem ) ;
46
45
await context . SaveChangesAsync ( ) ;
47
-
48
- var builder = new WebHostBuilder ( )
49
- . UseStartup < Startup > ( ) ;
46
+
50
47
var httpMethod = new HttpMethod ( "GET" ) ;
51
48
var route = $ "/api/v1/todo-items?filter[guid-property]={ todoItem . GuidProperty } ";
52
- var server = new TestServer ( builder ) ;
53
- var client = server . CreateClient ( ) ;
54
49
var request = new HttpRequestMessage ( httpMethod , route ) ;
55
50
56
51
// act
57
- var response = await client . SendAsync ( request ) ;
52
+ var response = await _fixture . Client . SendAsync ( request ) ;
58
53
var body = await response . Content . ReadAsStringAsync ( ) ;
59
54
var deserializedBody = _fixture
60
55
. GetService < IJsonApiDeSerializer > ( )
@@ -68,7 +63,6 @@ public async Task Can_Filter_On_Guid_Properties()
68
63
Assert . Equal ( todoItem . GuidProperty , todoItemResponse . GuidProperty ) ;
69
64
}
70
65
71
-
72
66
[ Fact ]
73
67
public async Task Can_Filter_On_Related_Attrs ( )
74
68
{
@@ -79,17 +73,13 @@ public async Task Can_Filter_On_Related_Attrs()
79
73
todoItem . Owner = person ;
80
74
context . TodoItems . Add ( todoItem ) ;
81
75
await context . SaveChangesAsync ( ) ;
82
-
83
- var builder = new WebHostBuilder ( )
84
- . UseStartup < Startup > ( ) ;
76
+
85
77
var httpMethod = new HttpMethod ( "GET" ) ;
86
78
var route = $ "/api/v1/todo-items?include=owner&filter[owner.first-name]={ person . FirstName } ";
87
- var server = new TestServer ( builder ) ;
88
- var client = server . CreateClient ( ) ;
89
79
var request = new HttpRequestMessage ( httpMethod , route ) ;
90
80
91
81
// act
92
- var response = await client . SendAsync ( request ) ;
82
+ var response = await _fixture . Client . SendAsync ( request ) ;
93
83
var body = await response . Content . ReadAsStringAsync ( ) ;
94
84
var documents = JsonConvert . DeserializeObject < Documents > ( await response . Content . ReadAsStringAsync ( ) ) ;
95
85
var included = documents . Included ;
@@ -101,5 +91,20 @@ public async Task Can_Filter_On_Related_Attrs()
101
91
foreach ( var item in included )
102
92
Assert . Equal ( person . FirstName , item . Attributes [ "first-name" ] ) ;
103
93
}
94
+
95
+ [ Fact ]
96
+ public async Task Cannot_Filter_If_Explicitly_Forbidden ( )
97
+ {
98
+ // arrange
99
+ var httpMethod = new HttpMethod ( "GET" ) ;
100
+ var route = $ "/api/v1/todo-items?include=owner&filter[achieved-date]={ DateTime . UtcNow . Date } ";
101
+ var request = new HttpRequestMessage ( httpMethod , route ) ;
102
+
103
+ // act
104
+ var response = await _fixture . Client . SendAsync ( request ) ;
105
+
106
+ // assert
107
+ Assert . Equal ( HttpStatusCode . BadRequest , response . StatusCode ) ;
108
+ }
104
109
}
105
110
}
0 commit comments