1+ namespace SqlStreamStore . HAL . Tests
2+ {
3+ using System ;
4+ using System . Collections . Generic ;
5+ using System . Linq ;
6+ using System . Net ;
7+ using System . Net . Http ;
8+ using System . Threading . Tasks ;
9+ using Microsoft . Owin ;
10+ using Xunit ;
11+ using AppFunc = System . Func <
12+ System . Collections . Generic . IDictionary < string , object > ,
13+ System . Threading . Tasks . Task > ;
14+ using MidFunc = System . Func <
15+ System . Func <
16+ System . Collections . Generic . IDictionary < string , object > ,
17+ System . Threading . Tasks . Task > ,
18+ System . Func <
19+ System . Collections . Generic . IDictionary < string , object > ,
20+ System . Threading . Tasks . Task > > ;
21+
22+ public class OnlyReadsAreHandledTests : IDisposable
23+ {
24+ private static readonly HttpMethod [ ] s_methods =
25+ {
26+ HttpMethod . Delete ,
27+ HttpMethod . Options ,
28+ HttpMethod . Post ,
29+ HttpMethod . Put ,
30+ HttpMethod . Trace ,
31+ new HttpMethod ( "PATCH" )
32+ } ;
33+
34+ private readonly IStreamStore _streamStore ;
35+ private readonly AppFunc _methodNotAllowed ;
36+
37+ public OnlyReadsAreHandledTests ( )
38+ {
39+ _streamStore = new InMemoryStreamStore ( ) ;
40+ _methodNotAllowed = env =>
41+ {
42+ var context = new OwinContext ( env ) ;
43+ context . Response . StatusCode = 405 ;
44+
45+ return Task . CompletedTask ;
46+ } ;
47+ }
48+
49+ public static IEnumerable < object [ ] > StreamCases ( )
50+ => from method in s_methods
51+ from path in new [ ] { "" , "/1" , "/1/1" }
52+ select new object [ ] { method , path } ;
53+
54+ [ Theory , MemberData ( nameof ( StreamCases ) ) ]
55+ public async Task non_supported_method_on_stream ( HttpMethod method , string path )
56+ {
57+ using ( var fixture = new MiddlewareFixture (
58+ ReadStreamMiddleware . UseStreamStore ( _streamStore ) ( _methodNotAllowed ) ) )
59+ {
60+ var response = await fixture . HttpClient . SendAsync ( new HttpRequestMessage ( method , path ) ) ;
61+
62+ Assert . Equal ( HttpStatusCode . MethodNotAllowed , response . StatusCode ) ;
63+ }
64+ }
65+
66+ public static IEnumerable < object [ ] > AllStreamCases ( )
67+ => from method in s_methods
68+ from path in new [ ] { "" , "/1" }
69+ select new object [ ] { method , path } ;
70+
71+
72+ [ Theory , MemberData ( nameof ( AllStreamCases ) ) ]
73+ public async Task non_supported_method_on_all_stream ( HttpMethod method , string path )
74+ {
75+ using ( var fixture = new MiddlewareFixture (
76+ ReadAllStreamMiddleware . UseStreamStore ( _streamStore ) ( _methodNotAllowed ) ) )
77+ {
78+ var response = await fixture . HttpClient . SendAsync ( new HttpRequestMessage ( method , path ) ) ;
79+
80+ Assert . Equal ( HttpStatusCode . MethodNotAllowed , response . StatusCode ) ;
81+ }
82+ }
83+
84+
85+ public void Dispose ( ) => _streamStore . Dispose ( ) ;
86+ }
87+ }
0 commit comments