@@ -33,4 +33,66 @@ public void IsValidTest()
3333
3434 stopwatch . PrintTimeTable ( ) ;
3535 }
36+
37+ [ Test ]
38+ public void IsValidArrayTest ( )
39+ {
40+ JsonRequestContent jsonRequestContent = new JsonRequestContent ( Encoding . UTF8 ) ;
41+
42+ // Test simple array
43+ string jsonArray = @"[1, 2, 3]" ;
44+ byte [ ] arrayBytes = Encoding . UTF8 . GetBytes ( jsonArray ) ;
45+ Assert . That ( jsonRequestContent . IsValid ( arrayBytes ) , Is . True ) ;
46+
47+ // Test array of objects
48+ string jsonArrayOfObjects = @"[{""id"":1,""name"":""Item1""},{""id"":2,""name"":""Item2""}]" ;
49+ byte [ ] arrayOfObjectsBytes = Encoding . UTF8 . GetBytes ( jsonArrayOfObjects ) ;
50+ Assert . That ( jsonRequestContent . IsValid ( arrayOfObjectsBytes ) , Is . True ) ;
51+
52+ // Test nested arrays
53+ string nestedArray = @"[[1,2],[3,4]]" ;
54+ byte [ ] nestedArrayBytes = Encoding . UTF8 . GetBytes ( nestedArray ) ;
55+ Assert . That ( jsonRequestContent . IsValid ( nestedArrayBytes ) , Is . True ) ;
56+
57+ // Test empty array
58+ string emptyArray = @"[]" ;
59+ byte [ ] emptyArrayBytes = Encoding . UTF8 . GetBytes ( emptyArray ) ;
60+ Assert . That ( jsonRequestContent . IsValid ( emptyArrayBytes ) , Is . True ) ;
61+
62+ Console . WriteLine ( "All JSON array validation tests passed" ) ;
63+ }
64+
65+ [ Test ]
66+ public void IsValidArrayPerformanceTest ( )
67+ {
68+ JsonRequestContent jsonRequestContent = new JsonRequestContent ( Encoding . UTF8 ) ;
69+ string jsonArray = @"[{""position"":0,""questionId"":""abc123"",""textAnswer"":{""response"":""Hello""}}]" ;
70+ byte [ ] arrayBytes = Encoding . UTF8 . GetBytes ( jsonArray ) ;
71+
72+ Stopwatch stopwatch = PenetrationTest . Run ( ( ) =>
73+ {
74+ Assert . That ( jsonRequestContent . IsValid ( arrayBytes ) , Is . True ) ;
75+ } , Count ) ;
76+
77+ Console . WriteLine ( $ "Validated json array { Count } times") ;
78+ stopwatch . PrintTimeTable ( ) ;
79+ }
80+
81+ [ Test ]
82+ public void IsInvalidJsonTest ( )
83+ {
84+ JsonRequestContent jsonRequestContent = new JsonRequestContent ( Encoding . UTF8 ) ;
85+
86+ // Test invalid JSON
87+ string invalidJson = @"not valid json" ;
88+ byte [ ] invalidBytes = Encoding . UTF8 . GetBytes ( invalidJson ) ;
89+ Assert . That ( jsonRequestContent . IsValid ( invalidBytes ) , Is . False ) ;
90+
91+ // Test malformed array
92+ string malformedArray = @"[1, 2, 3" ;
93+ byte [ ] malformedBytes = Encoding . UTF8 . GetBytes ( malformedArray ) ;
94+ Assert . That ( jsonRequestContent . IsValid ( malformedBytes ) , Is . False ) ;
95+
96+ Console . WriteLine ( "Invalid JSON detection tests passed" ) ;
97+ }
3698}
0 commit comments