@@ -17,6 +17,10 @@ public async void Invoke_CallsHandleJsonApiRequest_OnRouter()
17
17
var httpRequestMock = new Mock < HttpRequest > ( ) ;
18
18
httpRequestMock . Setup ( r => r . Path ) . Returns ( new PathString ( "" ) ) ;
19
19
httpRequestMock . Setup ( r => r . ContentType ) . Returns ( "application/vnd.api+json" ) ;
20
+ httpRequestMock . Setup ( r => r . ContentLength ) . Returns ( 0 ) ;
21
+ var headers = new HeaderDictionary ( ) ;
22
+ headers . Add ( "Accept" , "application/vnd.api+json" ) ;
23
+ httpRequestMock . Setup ( r => r . Headers ) . Returns ( headers ) ;
20
24
21
25
var httpContextMock = new Mock < HttpContext > ( ) ;
22
26
httpContextMock . Setup ( c => c . Request ) . Returns ( httpRequestMock . Object ) ;
@@ -32,13 +36,50 @@ public async void Invoke_CallsHandleJsonApiRequest_OnRouter()
32
36
Assert . True ( router . DidHandleRoute ) ;
33
37
}
34
38
39
+ [ Fact ]
40
+ public async void Invoke_SetsStatusCode_To415_ForInvalidAcceptType ( )
41
+ {
42
+ // arrange
43
+ var httpRequestMock = new Mock < HttpRequest > ( ) ;
44
+ httpRequestMock . Setup ( r => r . Path ) . Returns ( new PathString ( "" ) ) ;
45
+ httpRequestMock . Setup ( r => r . ContentType ) . Returns ( "application/vnd.api+json" ) ;
46
+ httpRequestMock . Setup ( r => r . ContentLength ) . Returns ( 0 ) ;
47
+ var headers = new HeaderDictionary ( ) ;
48
+ headers . Add ( "Accept" , "" ) ;
49
+ httpRequestMock . Setup ( r => r . Headers ) . Returns ( headers ) ;
50
+
51
+ var httpResponsMock = new Mock < HttpResponse > ( ) ;
52
+ httpResponsMock . SetupAllProperties ( ) ;
53
+ httpResponsMock . Setup ( r => r . Body ) . Returns ( new MemoryStream ( ) ) ;
54
+
55
+ var httpContextMock = new Mock < HttpContext > ( ) ;
56
+ httpContextMock . Setup ( c => c . Request ) . Returns ( httpRequestMock . Object ) ;
57
+ httpContextMock . Setup ( c => c . Response ) . Returns ( httpResponsMock . Object ) ;
58
+
59
+ var requestDelegateMock = new Mock < RequestDelegate > ( ) ;
60
+
61
+ var router = new TestRouter ( ) ;
62
+ var loggerMock = new Mock < ILogger < JsonApiMiddleware > > ( ) ;
63
+ var middleware = new JsonApiMiddleware ( requestDelegateMock . Object , loggerMock . Object , router , null ) ;
64
+
65
+ // act
66
+ await middleware . Invoke ( httpContextMock . Object ) ;
67
+
68
+ // assert
69
+ Assert . Equal ( 415 , httpResponsMock . Object . StatusCode ) ;
70
+ }
71
+
35
72
[ Fact ]
36
73
public async void Invoke_SetsStatusCode_To415_ForInvalidContentType ( )
37
74
{
38
75
// arrange
39
76
var httpRequestMock = new Mock < HttpRequest > ( ) ;
40
77
httpRequestMock . Setup ( r => r . Path ) . Returns ( new PathString ( "" ) ) ;
41
78
httpRequestMock . Setup ( r => r . ContentType ) . Returns ( "" ) ;
79
+ httpRequestMock . Setup ( r => r . ContentLength ) . Returns ( 1 ) ;
80
+ var headers = new HeaderDictionary ( ) ;
81
+ headers . Add ( "Accept" , "application/vnd.api+json" ) ;
82
+ httpRequestMock . Setup ( r => r . Headers ) . Returns ( headers ) ;
42
83
43
84
var httpResponsMock = new Mock < HttpResponse > ( ) ;
44
85
httpResponsMock . SetupAllProperties ( ) ;
0 commit comments