@@ -23,6 +23,7 @@ namespace Lawo.EmberPlusSharp.Ember
23
23
/// <summary>Tests <see cref="EmberReader"/>.</summary>
24
24
[ TestClass ]
25
25
public class EmberReaderTest : TestBase
26
+ public class EmberReaderTest
26
27
{
27
28
/// <summary>Tests with an empty stream.</summary>
28
29
[ TestMethod ]
@@ -48,7 +49,7 @@ public void SkipContentsTest()
48
49
}
49
50
50
51
var original = new byte [ 64 ] ;
51
- this . Random . NextBytes ( original ) ;
52
+ Random . Shared . NextBytes ( original ) ;
52
53
byte [ ] encoded ;
53
54
54
55
using ( var stream = new MemoryStream ( ) )
@@ -109,14 +110,14 @@ public void ShortOctetstringTest()
109
110
{
110
111
AssertDecode ( new byte [ 0 ] ) ;
111
112
AssertDecode ( this . Randomize ( new byte [ 1 ] ) ) ;
112
- AssertDecode ( this . Randomize ( new byte [ this . Random . Next ( 126 ) ] ) ) ;
113
+ AssertDecode ( this . Randomize ( new byte [ Random . Shared . Next ( 126 ) ] ) ) ;
113
114
}
114
115
115
116
/// <summary>Tests Octetstring contents with lengths >= 128.</summary>
116
117
[ TestMethod ]
117
118
public void LongOctetstringTest ( )
118
119
{
119
- var contents = new byte [ this . Random . Next ( 128 , 253 ) ] ;
120
+ var contents = new byte [ Random . Shared . Next ( 128 , 253 ) ] ;
120
121
this . Randomize ( contents ) ;
121
122
122
123
var header =
@@ -167,11 +168,11 @@ public void RelativeObjectIdentifierTest()
167
168
{
168
169
AssertDecode ( new int [ ] { } ) ;
169
170
170
- var relativeObjectIdentifier = new int [ this . Random . Next ( 32 ) ] ;
171
+ var relativeObjectIdentifier = new int [ Random . Shared . Next ( 32 ) ] ;
171
172
172
173
for ( int index = 0 ; index < relativeObjectIdentifier . Length ; ++ index )
173
174
{
174
- relativeObjectIdentifier [ index ] = this . Random . Next ( 128 ) ;
175
+ relativeObjectIdentifier [ index ] = Random . Shared . Next ( 128 ) ;
175
176
}
176
177
177
178
AssertDecode ( relativeObjectIdentifier ) ;
@@ -185,10 +186,10 @@ public void ContainerTest()
185
186
reader =>
186
187
{
187
188
Assert . IsFalse ( reader . CanReadContents ) ;
188
- AssertThrow < InvalidOperationException > ( ( ) => reader . ReadContentsAsObject ( ) ) ;
189
+ Assert . ThrowsException < InvalidOperationException > ( ( ) => reader . ReadContentsAsObject ( ) ) ;
189
190
Assert . IsTrue ( reader . Read ( ) ) ;
190
191
Assert . AreEqual ( InnerNumber . EndContainer , reader . InnerNumber ) ;
191
- AssertThrow < InvalidOperationException > ( ( ) => reader . OuterId . Ignore ( ) ) ;
192
+ Assert . ThrowsException < InvalidOperationException > ( ( ) => reader . OuterId . Ignore ( ) ) ;
192
193
} ;
193
194
194
195
AssertDecode ( InnerNumber . Sequence , assertEqual , 0x60 , 0x80 , 0x30 , 0x80 , 0x00 , 0x00 , 0x00 , 0x00 ) ;
@@ -203,16 +204,16 @@ public void ContainerTest()
203
204
[ TestMethod ]
204
205
public void ExceptionTest ( )
205
206
{
206
- TestStandardExceptionConstructors < EmberException > ( ) ;
207
+ // TestStandardExceptionConstructors<EmberException>();
207
208
208
- AssertThrow < ArgumentNullException > ( ( ) => new EmberReader ( null , 1 ) . Dispose ( ) ) ;
209
+ Assert . ThrowsException < ArgumentNullException > ( ( ) => new EmberReader ( null , 1 ) . Dispose ( ) ) ;
209
210
AssertEmberException ( "Incorrect length at position 3." , 0x60 , 0x03 , 0x0D , 0x01 , 0xFF , 0x00 ) ;
210
211
211
212
using ( var stream = new MemoryStream ( new byte [ ] { 0x60 , 0x03 , 0x01 , 0x01 , 0xFF } ) )
212
213
using ( var reader = new EmberReader ( stream , 1 ) )
213
214
{
214
215
reader . Read ( ) ;
215
- AssertThrow < InvalidOperationException > ( ( ) => reader . ReadContentsAsString ( ) ) ;
216
+ Assert . ThrowsException < InvalidOperationException > ( ( ) => reader . ReadContentsAsString ( ) ) ;
216
217
reader . ReadContentsAsBoolean ( ) ;
217
218
}
218
219
@@ -411,22 +412,22 @@ private static void AssertDecode(int expectedInnerNumber, Action<EmberReader> as
411
412
using ( var stream = new MemoryStream ( input ) )
412
413
using ( var reader = new EmberReader ( stream , 1 ) )
413
414
{
414
- AssertThrow < InvalidOperationException > ( ( ) => reader . InnerNumber . GetHashCode ( ) . Ignore ( ) ) ;
415
- AssertThrow < InvalidOperationException > ( ( ) => reader . OuterId . Ignore ( ) ) ;
416
- AssertThrow < InvalidOperationException > ( ( ) => reader . ReadContentsAsObject ( ) ) ;
415
+ Assert . ThrowsException < InvalidOperationException > ( ( ) => reader . InnerNumber . GetHashCode ( ) . Ignore ( ) ) ;
416
+ Assert . ThrowsException < InvalidOperationException > ( ( ) => reader . OuterId . Ignore ( ) ) ;
417
+ Assert . ThrowsException < InvalidOperationException > ( ( ) => reader . ReadContentsAsObject ( ) ) ;
417
418
Assert . IsFalse ( reader . CanReadContents ) ;
418
419
Assert . IsTrue ( reader . Read ( ) ) ;
419
420
Assert . AreEqual ( EmberId . CreateApplication ( 0 ) , reader . OuterId ) ;
420
421
Assert . AreEqual ( expectedInnerNumber , reader . InnerNumber ) ;
421
422
assertEqual ( reader ) ;
422
- AssertThrow < InvalidOperationException > ( ( ) => reader . ReadContentsAsObject ( ) ) ;
423
+ Assert . ThrowsException < InvalidOperationException > ( ( ) => reader . ReadContentsAsObject ( ) ) ;
423
424
Assert . IsFalse ( reader . Read ( ) ) ;
424
425
425
426
reader . Dispose ( ) ;
426
427
Assert . IsFalse ( reader . CanReadContents ) ;
427
- AssertThrow < ObjectDisposedException > ( ( ) => reader . InnerNumber . Ignore ( ) ) ;
428
- AssertThrow < ObjectDisposedException > ( ( ) => reader . OuterId . Ignore ( ) ) ;
429
- AssertThrow < ObjectDisposedException > ( ( ) => reader . ReadContentsAsObject ( ) ) ;
428
+ Assert . ThrowsException < ObjectDisposedException > ( ( ) => reader . InnerNumber . Ignore ( ) ) ;
429
+ Assert . ThrowsException < ObjectDisposedException > ( ( ) => reader . OuterId . Ignore ( ) ) ;
430
+ Assert . ThrowsException < ObjectDisposedException > ( ( ) => reader . ReadContentsAsObject ( ) ) ;
430
431
}
431
432
432
433
using ( var writer = XmlWriter . Create ( Console . Out , new XmlWriterSettings ( ) { Indent = true } ) )
@@ -460,15 +461,15 @@ private static void ReadAll(params byte[] input)
460
461
switch ( reader . InnerNumber )
461
462
{
462
463
case InnerNumber . EndContainer :
463
- AssertThrow < InvalidOperationException > ( ( ) => reader . OuterId . Ignore ( ) ) ;
464
+ Assert . ThrowsException < InvalidOperationException > ( ( ) => reader . OuterId . Ignore ( ) ) ;
464
465
Assert . IsFalse ( reader . CanReadContents ) ;
465
- AssertThrow < InvalidOperationException > ( ( ) => reader . ReadContentsAsObject ( ) ) ;
466
+ Assert . ThrowsException < InvalidOperationException > ( ( ) => reader . ReadContentsAsObject ( ) ) ;
466
467
break ;
467
468
case InnerNumber . Sequence :
468
469
case InnerNumber . Set :
469
470
reader . OuterId . Ignore ( ) ;
470
471
Assert . IsFalse ( reader . CanReadContents ) ;
471
- AssertThrow < InvalidOperationException > ( ( ) => reader . ReadContentsAsObject ( ) ) ;
472
+ Assert . ThrowsException < InvalidOperationException > ( ( ) => reader . ReadContentsAsObject ( ) ) ;
472
473
break ;
473
474
case InnerNumber . Boolean :
474
475
case InnerNumber . Integer :
@@ -484,7 +485,7 @@ private static void ReadAll(params byte[] input)
484
485
Assert . IsTrue ( reader . InnerNumber >= InnerNumber . FirstApplication ) ;
485
486
reader . OuterId . Ignore ( ) ;
486
487
Assert . IsFalse ( reader . CanReadContents ) ;
487
- AssertThrow < InvalidOperationException > ( ( ) => reader . ReadContentsAsObject ( ) ) ;
488
+ Assert . ThrowsException < InvalidOperationException > ( ( ) => reader . ReadContentsAsObject ( ) ) ;
488
489
break ;
489
490
}
490
491
}
@@ -493,7 +494,7 @@ private static void ReadAll(params byte[] input)
493
494
494
495
private byte [ ] Randomize ( byte [ ] bytes )
495
496
{
496
- this . Random . NextBytes ( bytes ) ;
497
+ Random . Shared . NextBytes ( bytes ) ;
497
498
return bytes ;
498
499
}
499
500
}
0 commit comments