@@ -224,6 +224,79 @@ public void AllowsEncodingAndDecodingEmptyGroupAndVariableLengthFieldsInSchemaDe
224
224
Assert . IsTrue ( decoder . ToString ( ) . Contains ( "A=42|B=[]|D='abc'" ) ) ;
225
225
}
226
226
227
+ [ TestMethod ]
228
+ public void AllowsEncoderToResetZeroGroupLengthToZero ( )
229
+ {
230
+ var encoder = new GroupAndVarLength ( ) ;
231
+ encoder . WrapForEncodeAndApplyHeader ( _buffer , Offset , _messageHeader ) ;
232
+ encoder . A = 42 ;
233
+ encoder . BCount ( 0 ) . ResetCountToIndex ( ) ;
234
+ encoder . SetD ( "abc" ) ;
235
+ encoder . CheckEncodingIsComplete ( ) ;
236
+
237
+ var decoder = new GroupAndVarLength ( ) ;
238
+ decoder . WrapForDecodeAndApplyHeader ( _buffer , Offset , _messageHeader ) ;
239
+ Assert . AreEqual ( 42 , decoder . A ) ;
240
+ var bDecoder = decoder . B ;
241
+ Assert . AreEqual ( 0 , bDecoder . Count ) ;
242
+ Assert . AreEqual ( "abc" , decoder . GetD ( ) ) ;
243
+ Assert . IsTrue ( decoder . ToString ( ) . Contains ( "A=42|B=[]|D='abc'" ) ) ;
244
+ }
245
+
246
+ [ TestMethod ]
247
+ public void AllowsEncoderToResetNonZeroGroupLengthToZeroBeforeCallingNext ( )
248
+ {
249
+ var encoder = new GroupAndVarLength ( ) ;
250
+ encoder . WrapForEncodeAndApplyHeader ( _buffer , Offset , _messageHeader ) ;
251
+ encoder . A = 42 ;
252
+ encoder . BCount ( 2 ) . ResetCountToIndex ( ) ;
253
+ encoder . SetD ( "abc" ) ;
254
+ encoder . CheckEncodingIsComplete ( ) ;
255
+
256
+ var decoder = new GroupAndVarLength ( ) ;
257
+ decoder . WrapForDecodeAndApplyHeader ( _buffer , Offset , _messageHeader ) ;
258
+ Assert . AreEqual ( 42 , decoder . A ) ;
259
+ var bDecoder = decoder . B ;
260
+ Assert . AreEqual ( 0 , bDecoder . Count ) ;
261
+ Assert . AreEqual ( "abc" , decoder . GetD ( ) ) ;
262
+ Assert . IsTrue ( decoder . ToString ( ) . Contains ( "A=42|B=[]|D='abc'" ) ) ;
263
+ }
264
+
265
+ [ TestMethod ]
266
+ public void AllowsEncoderToResetNonZeroGroupLengthToNonZero ( )
267
+ {
268
+ var encoder = new GroupAndVarLength ( ) ;
269
+ encoder . WrapForEncodeAndApplyHeader ( _buffer , Offset , _messageHeader ) ;
270
+ encoder . A = 42 ;
271
+ var bEncoder = encoder . BCount ( 2 ) ;
272
+ bEncoder . Next ( ) . C = 43 ;
273
+ bEncoder . ResetCountToIndex ( ) ;
274
+ encoder . SetD ( "abc" ) ;
275
+ encoder . CheckEncodingIsComplete ( ) ;
276
+
277
+ var decoder = new GroupAndVarLength ( ) ;
278
+ decoder . WrapForDecodeAndApplyHeader ( _buffer , Offset , _messageHeader ) ;
279
+ Assert . AreEqual ( 42 , decoder . A ) ;
280
+ var bDecoder = decoder . B ;
281
+ Assert . AreEqual ( 1 , bDecoder . Count ) ;
282
+ Assert . AreEqual ( 43 , bDecoder . Next ( ) . C ) ;
283
+ Assert . AreEqual ( "abc" , decoder . GetD ( ) ) ;
284
+ Assert . IsTrue ( decoder . ToString ( ) . Contains ( "A=42|B=[(C=43)]|D='abc'" ) ) ;
285
+ }
286
+
287
+ [ TestMethod ]
288
+ public void DisallowsEncoderToResetGroupLengthMidGroupElement ( )
289
+ {
290
+ var encoder = new NestedGroups ( ) ;
291
+ encoder . WrapForEncodeAndApplyHeader ( _buffer , Offset , _messageHeader ) ;
292
+ encoder . A = 42 ;
293
+ var bEncoder = encoder . BCount ( 2 ) . Next ( ) ;
294
+ bEncoder . C = 43 ;
295
+ var exception = Assert . ThrowsException < InvalidOperationException > ( ( ) => bEncoder . ResetCountToIndex ( ) ) ;
296
+ Assert . IsTrue ( exception . Message . Contains (
297
+ "Cannot reset count of repeating group \" b\" in state: V0_B_N_BLOCK" ) ) ;
298
+ }
299
+
227
300
[ TestMethod ]
228
301
public void DisallowsEncodingGroupElementBeforeCallingNext ( )
229
302
{
@@ -2311,7 +2384,7 @@ public void DisallowsEncodingAsciiInsideGroupBeforeCallingNext5()
2311
2384
{
2312
2385
var bEncoder = EncodeUntilGroupWithAsciiInside ( ) ;
2313
2386
2314
- Exception exception = Assert . ThrowsException < InvalidOperationException > ( ( ) =>
2387
+ Exception exception = Assert . ThrowsException < InvalidOperationException > ( ( ) =>
2315
2388
bEncoder . SetC ( Encoding . ASCII . GetBytes ( "EURUSD" ) , 0 ) ) ;
2316
2389
2317
2390
Assert . IsTrue ( exception . Message . Contains ( "Cannot access field \" b.c\" in state: V0_B_N" ) ) ;
@@ -2322,7 +2395,7 @@ public void DisallowsEncodingAsciiInsideGroupBeforeCallingNext6()
2322
2395
{
2323
2396
var bEncoder = EncodeUntilGroupWithAsciiInside ( ) ;
2324
2397
2325
- Exception exception = Assert . ThrowsException < InvalidOperationException > ( ( ) =>
2398
+ Exception exception = Assert . ThrowsException < InvalidOperationException > ( ( ) =>
2326
2399
bEncoder . SetC ( Encoding . ASCII . GetBytes ( "EURUSD" ) ) ) ;
2327
2400
2328
2401
Assert . IsTrue ( exception . Message . Contains ( "Cannot access field \" b.c\" in state: V0_B_N" ) ) ;
@@ -2693,7 +2766,7 @@ public void DisallowsEncodingElementOfEmptyGroup2()
2693
2766
encoder . HCount ( 0 ) ;
2694
2767
2695
2768
var ex = Assert . ThrowsException < InvalidOperationException > ( ( ) => dEncoder . E = 44 ) ;
2696
- Assert . IsTrue ( ex . Message . Contains ( "Cannot access field \" b.d.e\" in state: V0_H_0 " ) ) ;
2769
+ Assert . IsTrue ( ex . Message . Contains ( "Cannot access field \" b.d.e\" in state: V0_H_DONE " ) ) ;
2697
2770
}
2698
2771
2699
2772
[ TestMethod ]
@@ -2710,7 +2783,7 @@ public void DisallowsEncodingElementOfEmptyGroup3()
2710
2783
encoder . HCount ( 0 ) ;
2711
2784
2712
2785
var ex = Assert . ThrowsException < InvalidOperationException > ( ( ) => dEncoder . E = 44 ) ;
2713
- Assert . IsTrue ( ex . Message . Contains ( "Cannot access field \" b.d.e\" in state: V0_H_0 " ) ) ;
2786
+ Assert . IsTrue ( ex . Message . Contains ( "Cannot access field \" b.d.e\" in state: V0_H_DONE " ) ) ;
2714
2787
}
2715
2788
2716
2789
[ TestMethod ]
@@ -2726,7 +2799,7 @@ public void DisallowsEncodingElementOfEmptyGroup4()
2726
2799
bEncoder . FCount ( 0 ) ;
2727
2800
2728
2801
var ex = Assert . ThrowsException < InvalidOperationException > ( ( ) => dEncoder . E = 44 ) ;
2729
- Assert . IsTrue ( ex . Message . Contains ( "Cannot access field \" b.d.e\" in state: V0_B_1_F_0 " ) ) ;
2802
+ Assert . IsTrue ( ex . Message . Contains ( "Cannot access field \" b.d.e\" in state: V0_B_1_F_DONE " ) ) ;
2730
2803
}
2731
2804
2732
2805
@@ -2738,7 +2811,7 @@ public void DisallowsEncodingElementOfEmptyGroup5()
2738
2811
encoder . A = 42 ;
2739
2812
var bEncoder = encoder . BCount ( 0 ) ;
2740
2813
var exception = Assert . ThrowsException < InvalidOperationException > ( ( ) => bEncoder . C = 43 ) ;
2741
- Assert . IsTrue ( exception . Message . Contains ( "Cannot access field \" b.c\" in state: V1_B_0 " ) ) ;
2814
+ Assert . IsTrue ( exception . Message . Contains ( "Cannot access field \" b.c\" in state: V1_B_DONE " ) ) ;
2742
2815
}
2743
2816
2744
2817
[ TestMethod ]
@@ -3003,7 +3076,8 @@ public void DisallowsIncompleteMessagesDueToMissingTopLevelGroup1()
3003
3076
encoder . BCount ( 0 ) ;
3004
3077
var exception = Assert . ThrowsException < InvalidOperationException > ( encoder . CheckEncodingIsComplete ) ;
3005
3078
StringAssert . Contains ( exception . Message ,
3006
- "Not fully encoded, current state: V0_B_0, allowed transitions: \" dCount(0)\" , \" dCount(>0)\" " ) ;
3079
+ "Not fully encoded, current state: V0_B_DONE, allowed transitions: " +
3080
+ "\" b.resetCountToIndex()\" , \" dCount(0)\" , \" dCount(>0)\" " ) ;
3007
3081
}
3008
3082
3009
3083
[ TestMethod ]
@@ -3016,7 +3090,8 @@ public void DisallowsIncompleteMessagesDueToMissingTopLevelGroup2()
3016
3090
bEncoder . C = 2 ;
3017
3091
var exception = Assert . ThrowsException < InvalidOperationException > ( encoder . CheckEncodingIsComplete ) ;
3018
3092
StringAssert . Contains ( exception . Message ,
3019
- "Not fully encoded, current state: V0_B_1_BLOCK, allowed transitions: \" b.c(?)\" , \" dCount(0)\" , \" dCount(>0)\" " ) ;
3093
+ "Not fully encoded, current state: V0_B_1_BLOCK, allowed transitions:" +
3094
+ " \" b.c(?)\" , \" b.resetCountToIndex()\" , \" dCount(0)\" , \" dCount(>0)\" " ) ;
3020
3095
}
3021
3096
3022
3097
[ TestMethod ]
@@ -3047,7 +3122,7 @@ public void DisallowsIncompleteMessagesDueToMissingNestedGroup1(int bCount, stri
3047
3122
[ DataTestMethod ]
3048
3123
[ DataRow ( 1 , 1 , "V0_B_1_D_N" ) ]
3049
3124
[ DataRow ( 1 , 2 , "V0_B_1_D_N" ) ]
3050
- [ DataRow ( 2 , 0 , "V0_B_N_D_0 " ) ]
3125
+ [ DataRow ( 2 , 0 , "V0_B_N_D_DONE " ) ]
3051
3126
[ DataRow ( 2 , 1 , "V0_B_N_D_N" ) ]
3052
3127
[ DataRow ( 2 , 2 , "V0_B_N_D_N" ) ]
3053
3128
public void DisallowsIncompleteMessagesDueToMissingNestedGroup2 (
0 commit comments