Skip to content

Commit 52c15ab

Browse files
committed
Add unit test cases for issue #270
1 parent a36d4b2 commit 52c15ab

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

test/MsgPack.UnitTest/Serialization/RegressionTests.cs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,18 @@
2727
using System.Diagnostics;
2828
using System.IO;
2929
using System.Linq;
30+
#if !WINDOWS_PHONE
31+
#if !NET35 && !UNITY
32+
#if !UNITY || MSGPACK_UNITY_FULL
33+
using System.Numerics;
34+
#endif // !UNITY || MSGPACK_UNITY_FULL
35+
#endif // !NET35 && !UNITY
36+
#endif // !WINDOWS_PHONE
3037
using System.Runtime.Serialization;
38+
#if FEATURE_TAP
39+
using System.Threading;
40+
using System.Threading.Tasks;
41+
#endif // FEATURE_TAP
3142
#if !MSTEST
3243
using NUnit.Framework;
3344
#else
@@ -462,5 +473,63 @@ public class Issue252Class
462473
public byte[] ByteArray = new byte[ MessagePackSerializer.BufferSize - sizeof( int ) - sizeof( byte ) - 1 - 1 ];
463474
public int Int32 = Int32.MaxValue;
464475
}
476+
477+
[Test]
478+
public void TestIssue270_Default()
479+
{
480+
var context = new SerializationContext();
481+
var guidBytes = context.GetSerializer<Guid>().PackSingleObject( Guid.NewGuid() );
482+
Assert.That( guidBytes[ 0 ], Is.EqualTo( MessagePackCode.Bin8 ) );
483+
#if !WINDOWS_PHONE
484+
#if !NET35 && !UNITY
485+
#if !UNITY || MSGPACK_UNITY_FULL
486+
var bigIntBytes = context.GetSerializer<BigInteger>().PackSingleObject( new BigInteger( 123 ) );
487+
Assert.That( bigIntBytes[ 0 ], Is.EqualTo( MessagePackCode.Bin8 ) );
488+
#endif // !UNITY || MSGPACK_UNITY_FULL
489+
#endif // !NET35 && !UNITY
490+
#endif // !WINDOWS_PHONE
491+
}
492+
493+
[Test]
494+
public void TestIssue270_AsRaw()
495+
{
496+
var context = new SerializationContext();
497+
context.CompatibilityOptions.PackerCompatibilityOptions = PackerCompatibilityOptions.PackBinaryAsRaw;
498+
var guidBytes = context.GetSerializer<Guid>().PackSingleObject( Guid.NewGuid() );
499+
Assert.That( guidBytes[ 0 ], Is.EqualTo( 0xB0 ) );
500+
#if !WINDOWS_PHONE
501+
#if !NET35 && !UNITY
502+
#if !UNITY || MSGPACK_UNITY_FULL
503+
var bigIntBytes = context.GetSerializer<BigInteger>().PackSingleObject( new BigInteger( 123 ) );
504+
Assert.That( bigIntBytes[ 0 ], Is.EqualTo( 0xA1 ) );
505+
#endif // !UNITY || MSGPACK_UNITY_FULL
506+
#endif // !NET35 && !UNITY
507+
#endif // !WINDOWS_PHONE
508+
}
509+
510+
#if FEATURE_TAP
511+
512+
[Test]
513+
public async Task TestIssue270Async_Default()
514+
{
515+
var context = new SerializationContext();
516+
var guidBytes = await context.GetSerializer<Guid>().PackSingleObjectAsync( Guid.NewGuid() );
517+
Assert.That( guidBytes[ 0 ], Is.EqualTo( MessagePackCode.Bin8 ) );
518+
var bigIntBytes = await context.GetSerializer<BigInteger>().PackSingleObjectAsync( new BigInteger( 123 ) );
519+
Assert.That( bigIntBytes[ 0 ], Is.EqualTo( MessagePackCode.Bin8 ) );
520+
}
521+
522+
[Test]
523+
public async Task TestIssue270Async_AsRaw()
524+
{
525+
var context = new SerializationContext();
526+
context.CompatibilityOptions.PackerCompatibilityOptions = PackerCompatibilityOptions.PackBinaryAsRaw;
527+
var guidBytes = await context.GetSerializer<Guid>().PackSingleObjectAsync( Guid.NewGuid() );
528+
Assert.That( guidBytes[ 0 ], Is.EqualTo( 0xB0 ) );
529+
var bigIntBytes = await context.GetSerializer<BigInteger>().PackSingleObjectAsync( new BigInteger( 123 ) );
530+
Assert.That( bigIntBytes[ 0 ], Is.EqualTo( 0xA1 ) );
531+
}
532+
533+
#endif // FEATURE_TAP
465534
}
466535
}

0 commit comments

Comments
 (0)