1
- using EdjCase . JsonRpc . Router . Abstractions ;
1
+ using EdjCase . JsonRpc . Router . Abstractions ;
2
2
using EdjCase . JsonRpc . Router . Defaults ;
3
3
using Microsoft . Extensions . DependencyInjection ;
4
4
using Microsoft . Extensions . Logging ;
@@ -19,31 +19,30 @@ namespace EdjCase.JsonRpc.Router.Tests
19
19
{
20
20
public class MethodMatcherTests
21
21
{
22
- private readonly IReadOnlyDictionary < RpcPath , IReadOnlyList < IRpcMethodInfo > > methodData ;
22
+ private readonly StaticRpcMethodDataAccessor methodDataAccessor ;
23
23
24
24
public MethodMatcherTests ( )
25
- {
26
- this . methodData = new Dictionary < RpcPath , IReadOnlyList < IRpcMethodInfo > >
27
- {
25
+ {
26
+ var baserouteData = typeof ( MethodMatcherThreeController )
27
+ . GetMethods ( BindingFlags . DeclaredOnly | BindingFlags . Public | BindingFlags . Instance )
28
+ . Select ( DefaultRpcMethodInfo . FromMethodInfo )
29
+ . ToList ( ) ;
30
+
31
+ var routeData = new Dictionary < RpcPath , IReadOnlyList < IRpcMethodInfo > >
32
+ {
28
33
[ nameof ( MethodMatcherController ) ] = typeof ( MethodMatcherController )
29
34
. GetMethods ( BindingFlags . DeclaredOnly | BindingFlags . Public | BindingFlags . Instance )
30
35
. Select ( DefaultRpcMethodInfo . FromMethodInfo )
31
- . ToList ( ) ,
36
+ . ToList ( ) ,
32
37
[ nameof ( MethodMatcherDuplicatesController ) ] = typeof ( MethodMatcherDuplicatesController )
33
38
. GetMethods ( BindingFlags . DeclaredOnly | BindingFlags . Public | BindingFlags . Instance )
34
39
. Select ( DefaultRpcMethodInfo . FromMethodInfo )
35
- . ToList ( )
36
- } ;
37
- }
38
-
39
- private StaticRpcMethodDataAccessor GetMethodDataAccessor ( )
40
- {
41
- return new StaticRpcMethodDataAccessor ( )
42
- {
43
- Value = new RpcRouteMetaData ( new List < IRpcMethodInfo > ( ) , this . methodData )
44
- } ;
40
+ . ToList ( )
41
+ } ;
42
+ this . methodDataAccessor = new StaticRpcMethodDataAccessor ( ) { Value = new RpcRouteMetaData ( baserouteData , routeData ) } ;
45
43
}
46
44
45
+
47
46
private DefaultRequestMatcher GetMatcher ( RpcPath ? path = null )
48
47
{
49
48
@@ -64,7 +63,7 @@ private DefaultRequestMatcher GetMatcher(RpcPath? path = null)
64
63
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
65
64
66
65
67
- var methodProvider = new StaticRpcMethodProvider ( this . GetMethodDataAccessor ( ) ) ;
66
+ var methodProvider = new StaticRpcMethodProvider ( this . methodDataAccessor ) ;
68
67
return new DefaultRequestMatcher ( logger . Object , methodProvider , rpcContextAccessor . Object , rpcParameterConverter ) ;
69
68
}
70
69
@@ -82,7 +81,11 @@ public void GetMatchingMethod_WithRpcRoute()
82
81
DefaultRequestMatcher path2Matcher = this . GetMatcher ( path : typeof ( MethodMatcherDuplicatesController ) . GetTypeInfo ( ) . Name ) ;
83
82
IRpcMethodInfo path2Match = path2Matcher . GetMatchingMethod ( requestSignature ) ;
84
83
Assert . NotNull ( path2Match ) ;
85
- Assert . NotSame ( path1Match , path2Match ) ;
84
+ Assert . NotSame ( path1Match , path2Match ) ;
85
+
86
+ DefaultRequestMatcher path3Matcher = this . GetMatcher ( path : null ) ;
87
+ IRpcMethodInfo path3Match = path3Matcher . GetMatchingMethod ( requestSignature ) ;
88
+ Assert . NotNull ( path2Match ) ;
86
89
}
87
90
88
91
[ Fact ]
@@ -349,6 +352,18 @@ public void GetMatchingMethod__Dictionary_Request_With_Optional_Parameters__Matc
349
352
350
353
Assert . NotNull ( methodInfo ) ;
351
354
Assert . Equal ( methodName , methodInfo . Name ) ;
355
+ }
356
+
357
+
358
+ [ Fact ]
359
+ public void GetMatchingMethod_WithoutRpcRoute ( )
360
+ {
361
+ string methodName = nameof ( MethodMatcherController . GuidTypeMethod ) ;
362
+ RpcRequestSignature requestSignature = RpcRequestSignature . Create ( methodName , new [ ] { RpcParameterType . String } ) ;
363
+
364
+ DefaultRequestMatcher path3Matcher = this . GetMatcher ( path : null ) ;
365
+ IRpcMethodInfo path3Match = path3Matcher . GetMatchingMethod ( requestSignature ) ;
366
+ Assert . NotNull ( path3Match ) ;
352
367
}
353
368
}
354
369
0 commit comments