11using System ;
2+ using System . Security . Cryptography . X509Certificates ;
3+ using System . Text . RegularExpressions ;
4+ using System . Threading . Tasks ;
25using AustinHarris . JsonRpc ;
36using Microsoft . VisualStudio . TestTools . UnitTesting ;
47
@@ -1335,15 +1338,37 @@ public void TestOptionalParametersBoolsAndStrings()
13351338 }
13361339
13371340 [ TestMethod ]
1338- public void TestBatchResult ( )
1341+ public void TestBatchResultWrongRequests ( )
1342+ {
1343+ string request = @"[{},{""jsonrpc"":""2.0"",""id"":4}]" ;
1344+
1345+ var result = JsonRpcProcessor . Process ( request ) ;
1346+ result . Wait ( ) ;
1347+
1348+ Assert . IsTrue ( Regex . IsMatch ( result . Result , @"\[(\{.*""error"":.*?,""id"":.*?\}),(\{.*""error"":.*?,""id"":.*?\})\]" ) , "Should have two errors." ) ;
1349+ }
1350+
1351+ [ TestMethod ]
1352+ public void TestBatchResultMultipleMethodCallsNotificationAtLast ( )
13391353 {
13401354 string request =
1341- @"[{},{""jsonrpc"":""2.0"",""id"":4},{ ""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1},{""jsonrpc"":""2.0"",""method"":""Notify"",""params"":[""Hello World!""]}]" ;
1355+ @"[{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1},{""jsonrpc"":""2.0"",""method"":""Notify"",""params"":[""Hello World!""]}]" ;
13421356
13431357 var result = JsonRpcProcessor . Process ( request ) ;
13441358 result . Wait ( ) ;
13451359
13461360 Assert . IsFalse ( result . Result . EndsWith ( @",]" ) , "result.Result.EndsWith(@',]')" ) ;
1361+
1362+ }
1363+
1364+ [ TestMethod ]
1365+ public void TestEmptyBatchResult ( )
1366+ {
1367+ var secondRequest = @"{""jsonrpc"":""2.0"",""method"":""Notify"",""params"":[""Hello World!""]}" ;
1368+ var result = JsonRpcProcessor . Process ( secondRequest ) ;
1369+ result . Wait ( ) ;
1370+
1371+ Assert . IsTrue ( string . IsNullOrEmpty ( result . Result ) ) ;
13471372 }
13481373
13491374 [ TestMethod ]
@@ -1357,5 +1382,26 @@ public void TestLeftOutParams()
13571382
13581383 Assert . IsFalse ( result . Result . Contains ( @"error"":{""code"":-32602" ) , @"According to JSON-RPC 2.0 the ""params"" member MAY be omitted." ) ;
13591384 }
1385+
1386+ [ TestMethod ]
1387+ public void TestMultipleResults ( )
1388+ {
1389+ var result =
1390+ JsonRpcProcessor . Process (
1391+ @"[{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1},{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1}]" ) ;
1392+ result . Wait ( ) ;
1393+
1394+ Assert . IsTrue ( result . Result . EndsWith ( "]" ) ) ;
1395+ }
1396+
1397+ [ TestMethod ]
1398+ public void TestSingleResultBatch ( )
1399+ {
1400+ var result =
1401+ JsonRpcProcessor . Process ( @"[{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1}]" ) ;
1402+ result . Wait ( ) ;
1403+ Assert . IsFalse ( result . Result . EndsWith ( "]" ) ) ;
1404+ }
13601405 }
13611406}
1407+
0 commit comments