Skip to content

Commit 3a0a115

Browse files
committed
Fix unit tests for default DateTime serialization behavior change.
1 parent b6cfa70 commit 3a0a115

19 files changed

Lines changed: 4199 additions & 3859 deletions

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,9 @@ Release 0.9.1 2017-8-30
710710

711711
Release 1.0.0-beta1 T.B.D.
712712

713+
BREAKING CHANGES
714+
* Default DateTime, DateTimeOffset, FILETIME serialization now use msgpack timestamp type instead of native .NET representation. You can disable this behavior via setting SerializationContext.DefaultDateTimeConversionMethod to DateTimeConversionMethod.Native.
715+
713716
NEW FEATURES
714717
* .NET Standard 2.0 which supports serializer source code generation on .NET Core. Note that serializer assembly generation is not supported.
715718
* MessagePackSerializer.UnpackMessagePackObject(byte[]) utility method.

test/MsgPack.UnitTest.CodeDom/Serialization/ArrayCodeDomBasedAutoMessagePackSerializerTest.cs

Lines changed: 513 additions & 477 deletions
Large diffs are not rendered by default.

test/MsgPack.UnitTest.CodeDom/Serialization/MapCodeDomBasedAutoMessagePackSerializerTest.cs

Lines changed: 514 additions & 477 deletions
Large diffs are not rendered by default.

test/MsgPack.UnitTest/Serialization/ArrayFieldBasedAutoMessagePackSerializerTest.cs

Lines changed: 513 additions & 477 deletions
Large diffs are not rendered by default.

test/MsgPack.UnitTest/Serialization/ArrayGenerationBasedAutoMessagePackSerializerTest.cs

Lines changed: 500 additions & 465 deletions
Large diffs are not rendered by default.

test/MsgPack.UnitTest/Serialization/ArrayReflectionBasedAutoMessagePackSerializerTest.cs

Lines changed: 507 additions & 471 deletions
Large diffs are not rendered by default.

test/MsgPack.UnitTest/Serialization/AutoMessagePackSerializerTest.Polymorphism.ttinclude

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<#@ import namespace="System" #>
1+
<#@ import namespace="System" #>
22
<#@ import namespace="System.Collections.Generic" #>
33
<#@ import namespace="System.Globalization" #>
44
<#@ import namespace="System.Linq" #>
@@ -7,7 +7,7 @@
77
//
88
// MessagePack for CLI
99
//
10-
// Copyright (C) 2010-2015 FUJIWARA, Yusuke
10+
// Copyright (C) 2010-2017 FUJIWARA, Yusuke
1111
//
1212
// Licensed under the Apache License, Version 2.0 (the "License");
1313
// you may not use this file except in compliance with the License.
@@ -489,7 +489,7 @@ private IEnumerable<TestTargetType> GeneratePolymorphismTestPartsCore( bool gene
489489
[Category( "PolymorphicSerialization" )]
490490
public void TestGlobalNamespace()
491491
{
492-
var context = NewSerializationContext( PackerCompatibilityOptions.None );
492+
var context = NewSerializationContext();
493493
var target = new HasGlobalNamespaceType { GlobalType = new TypeInGlobalNamespace { Value = "ABC" } };
494494
var serializer = context.GetSerializer<HasGlobalNamespaceType>();
495495

@@ -512,7 +512,7 @@ private IEnumerable<TestTargetType> GeneratePolymorphismTestPartsCore( bool gene
512512
[Category( "PolymorphicSerialization" )]
513513
public async Task TestGlobalNamespaceAsync()
514514
{
515-
var context = NewSerializationContext( PackerCompatibilityOptions.None );
515+
var context = NewSerializationContext();
516516
var target = new HasGlobalNamespaceType { GlobalType = new TypeInGlobalNamespace { Value = "ABC" } };
517517
var serializer = context.GetSerializer<HasGlobalNamespaceType>();
518518

@@ -720,7 +720,7 @@ private void GeneratePolymorphicTestMethods( string targetType, TypeKind kind, M
720720
[Category( "PolymorphicSerialization" )]
721721
public void Test<#= targetType + "_" + label #>()
722722
{
723-
var context = NewSerializationContext( PackerCompatibilityOptions.None );
723+
var context = NewSerializationContext();
724724
<#+
725725
if ( ( kind & TypeKind.HasConstructor ) == TypeKind.HasConstructor )
726726
{
@@ -887,7 +887,7 @@ private void GeneratePolymorphicTestsForMixed( bool generateTypes, bool generate
887887
[Category( "PolymorphicSerialization" )]
888888
public void Test<#= typeName #>_Success()
889889
{
890-
var context = NewSerializationContext( PackerCompatibilityOptions.None );
890+
var context = NewSerializationContext();
891891
var target = new <#= typeName #>();
892892
<#+
893893
foreach ( var member in members )
@@ -947,7 +947,7 @@ private void GeneratePolymorphicTestsForMixed( bool generateTypes, bool generate
947947
[Category( "PolymorphicSerialization" )]
948948
public void Test<#= typeName #>_Null_Success()
949949
{
950-
var context = NewSerializationContext( PackerCompatibilityOptions.None );
950+
var context = NewSerializationContext();
951951
var target = new <#= typeName #>();
952952
var serializer = context.GetSerializer<#= "<" + typeName + ">" #>();
953953

@@ -1127,7 +1127,7 @@ private void GenerateErrorPatterns( bool generateTypes, bool generateMethods, IC
11271127
[Category( "PolymorphicSerialization" )]
11281128
public void TestTupleAbstractType_Success()
11291129
{
1130-
var context = NewSerializationContext( PackerCompatibilityOptions.None );
1130+
var context = NewSerializationContext();
11311131
var target = new TupleAbstractType { Value = Tuple.Create( <#= String.Join( ", ", Enumerable.Range( 1, 4 ).Select( i => String.Format( CultureInfo.InvariantCulture, "new FileEntry {{ Name = \"{0}\", Size = {0} }} as {1}FileSystemEntry", i, i % 2 == 1 ? "Abstract" : "I" ) ) ) #> ) };
11321132
var serializer = context.GetSerializer<TupleAbstractType>();
11331133

@@ -1265,7 +1265,7 @@ private void GenerateAbstractTypeTestMethod( string typeName, string initializer
12651265
[Category( "PolymorphicSerialization" )]
12661266
public void Test<#= typeName #>_<#= success ? "Success" : "Fail" #>()
12671267
{
1268-
var context = NewSerializationContext( PackerCompatibilityOptions.None );
1268+
var context = NewSerializationContext();
12691269
<#+
12701270
if ( abstractCollectionType != null && concreteCollectionType != null )
12711271
{
@@ -1357,7 +1357,7 @@ private void GenerateAttributeErrorTestMethod( string testCaseName, string type
13571357
[Category( "PolymorphicSerialization" )]
13581358
public void TestAttribute_<#= testCaseName #>_Fail()
13591359
{
1360-
var context = NewSerializationContext( PackerCompatibilityOptions.None );
1360+
var context = NewSerializationContext();
13611361
var target = new <#= typeName #>();
13621362
Assert.Throws<SerializationException>( ()=> context.GetSerializer<#= "<" + typeName + ">" #>() );
13631363
}
@@ -1671,7 +1671,7 @@ private void GeneratePolymorohismExtensionTests( bool generateTypes, bool genera
16711671
[Category( "PolymorphicSerialization" )]
16721672
public void TestPolymorphismAttributesInType()
16731673
{
1674-
var context = NewSerializationContext( PackerCompatibilityOptions.None );
1674+
var context = NewSerializationContext();
16751675
SetUpDefaultCollectionsForPolymorphism( context );
16761676
context.GetSerializer<IKnownTypePolymorphic>();
16771677
context.GetSerializer<IRuntimeTypePolymorphic>();
@@ -1691,7 +1691,7 @@ private void GeneratePolymorohismExtensionTests( bool generateTypes, bool genera
16911691
[Category( "PolymorphicSerialization" )]
16921692
public void Test<#= testCase.PolymorphismKind #>Type<#= testCase.TypeKind #>_AttributeIs<#= testCase.Result ?? "Nothing" #>_<#= suffix #>_<#= testCase.Result ?? testCase.PolymorphismKind #><#= failsOnPack ? "_Fail" : String.Empty #>()
16931693
{
1694-
var context = NewSerializationContext( PackerCompatibilityOptions.None );
1694+
var context = NewSerializationContext();
16951695
context.SerializationMethod = SerializationMethod.Map;
16961696
SetUpDefaultCollectionsForPolymorphism( context );
16971697

@@ -1772,7 +1772,7 @@ private void GeneratePolymorohismExtensionTests( bool generateTypes, bool genera
17721772
[Category( "PolymorphicSerialization" )]
17731773
public void TestTypeVerifierSelection_<#= typeSpec.IsPublicType ? "Public" : "NonPublic" #>VerifierType_<#= methodSpec.IsPublicMethod ? "Public" : "NonPublic" #><#= methodSpec.IsStaticMethod ? "Static" : "Instance" #>Method_OK()
17741774
{
1775-
var context = NewSerializationContext( PackerCompatibilityOptions.None );
1775+
var context = NewSerializationContext();
17761776
SetUpDefaultCollectionsForPolymorphism( context );
17771777
var target = new PolymorphicHolder { For<#= typeSpec.VerifierTypeName #><#= methodSpec.VerifierMethodName #> = new PolymorphicValueA { Value = "Foo" } };
17781778
var serializer = context.GetSerializer<PolymorphicHolder>();
@@ -1807,7 +1807,7 @@ private void GeneratePolymorohismExtensionTests( bool generateTypes, bool genera
18071807
[Category( "PolymorphicSerialization" )]
18081808
public void TestSpecifiedTypeVerifierIsNotFound_Because<#= reason #>_Fail()
18091809
{
1810-
var context = NewSerializationContext( PackerCompatibilityOptions.None );
1810+
var context = NewSerializationContext();
18111811
var target = new <#= typeName #> { Value = "Foo" };
18121812

18131813
var ex = Assert.Catch<SerializationException>( () => context.GetSerializer<<#= typeName #>>() );
@@ -1826,7 +1826,7 @@ private void GeneratePolymorohismExtensionTests( bool generateTypes, bool genera
18261826
[Category( "PolymorphicSerialization" )]
18271827
public void TestTypeVerifierDoesNotLoadTypeItself()
18281828
{
1829-
var context = NewSerializationContext( PackerCompatibilityOptions.None );
1829+
var context = NewSerializationContext();
18301830
var serializer = context.GetSerializer<IRuntimeTypePolymorphicWithVerification>();
18311831

18321832
using ( var buffer = new MemoryStream() )

test/MsgPack.UnitTest/Serialization/AutoMessagePackSerializerTest.Types.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-

1+
22
#region -- License Terms --
33
//
44
// MessagePack for CLI
@@ -657,7 +657,7 @@ public ComplexTypeGenerated Initialize()
657657
#endif // !SILVERLIGHT
658658
this._TimeSpanField = TimeSpan.FromMilliseconds( 123456789 );
659659
this._GuidField = Guid.NewGuid();
660-
this._CharField = ' ';
660+
this._CharField = '@';
661661
this._DecimalField = 123456789.0987654321m;
662662
#if !NET35 && !WINDOWS_PHONE
663663
this._BigIntegerField = new BigInteger( UInt64.MaxValue ) + UInt64.MaxValue;
@@ -1105,10 +1105,10 @@ internal static void Verify<T>( T expected, T actual )
11051105
if ( expected is DateTime )
11061106
{
11071107
Assert.That(
1108-
( DateTime )( object )expected == ( DateTime )( object )actual,
1108+
( ( DateTime )( object )expected ).ToUniversalTime() == ( DateTime )( object )actual,
11091109
"Expected:{1:O}({2},{3}){0}Actual :{4:O}({5},{6})",
11101110
Environment.NewLine,
1111-
expected,
1111+
expected == null ? null : ( object )( ( DateTime )( object )expected ).ToUniversalTime(),
11121112
expected == null ? "(null)" : expected.GetType().FullName,
11131113
( ( DateTime )( object )expected ).Kind,
11141114
actual,
@@ -1136,8 +1136,12 @@ internal static void Verify<T>( T expected, T actual )
11361136
var actuals = ( IDictionary )actual;
11371137
foreach ( DictionaryEntry entry in ( ( IDictionary )expected ) )
11381138
{
1139-
Assert.That( actuals.Contains( entry.Key ), "'{0}' is not in '[{1}]'", entry.Key, String.Join( ", ", actuals.Keys.OfType<object>().Select( o => o == null ? String.Empty : o.ToString() ).ToArray() ) );
1140-
Verify( entry.Value, actuals[ entry.Key ] );
1139+
var key =
1140+
entry.Key is DateTime
1141+
? ( object )( ( DateTime )entry.Key ).ToUniversalTime()
1142+
: entry.Key;
1143+
Assert.That( actuals.Contains( key ), "'{0}' is not in '[{1}]'", key, String.Join( ", ", actuals.Keys.OfType<object>().Select( o => o == null ? String.Empty : o.ToString() ).ToArray() ) );
1144+
Verify( entry.Value, actuals[ key ] );
11411145
}
11421146
return;
11431147
}
@@ -13666,7 +13670,7 @@ protected internal override DateTime UnpackFromCore( Unpacker unpacker )
1366613670
{
1366713671
var ext = unpacker.LastReadData.AsMessagePackExtendedTypeObject();
1366813672
Assert.That( ext.TypeCode, Is.EqualTo( 1 ) );
13669-
return new DateTime( BigEndianBinary.ToInt64( ext.Body, 0 ) ).ToUniversalTime();
13673+
return new DateTime( BigEndianBinary.ToInt64( ext.Body, 0 ), DateTimeKind.Utc );
1367013674
}
1367113675
}
1367213676

test/MsgPack.UnitTest/Serialization/AutoMessagePackSerializerTest.Types.tt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<#@ template debug="false" hostspecific="false" language="C#" #>
1+
<#@ template debug="false" hostspecific="false" language="C#" #>
22
<#@ output extension=".cs" #>
33
<#@ include file="AutoMessagePackSerializerTest.Polymorphism.ttinclude" #>
44
<#@ assembly name="System.Core.dll" #>
@@ -736,10 +736,10 @@ foreach( Tuple<Object, string, string, bool> item in fields )
736736
if ( expected is DateTime )
737737
{
738738
Assert.That(
739-
( DateTime )( object )expected == ( DateTime )( object )actual,
739+
( ( DateTime )( object )expected ).ToUniversalTime() == ( DateTime )( object )actual,
740740
"Expected:{1:O}({2},{3}){0}Actual :{4:O}({5},{6})",
741741
Environment.NewLine,
742-
expected,
742+
expected == null ? null : ( object )( ( DateTime )( object )expected ).ToUniversalTime(),
743743
expected == null ? "(null)" : expected.GetType().FullName,
744744
( ( DateTime )( object )expected ).Kind,
745745
actual,
@@ -767,8 +767,12 @@ foreach( Tuple<Object, string, string, bool> item in fields )
767767
var actuals = ( IDictionary )actual;
768768
foreach ( DictionaryEntry entry in ( ( IDictionary )expected ) )
769769
{
770-
Assert.That( actuals.Contains( entry.Key ), "'{0}' is not in '[{1}]'", entry.Key, String.Join( ", ", actuals.Keys.OfType<object>().Select( o => o == null ? String.Empty : o.ToString() ).ToArray() ) );
771-
Verify( entry.Value, actuals[ entry.Key ] );
770+
var key =
771+
entry.Key is DateTime
772+
? ( object )( ( DateTime )entry.Key ).ToUniversalTime()
773+
: entry.Key;
774+
Assert.That( actuals.Contains( key ), "'{0}' is not in '[{1}]'", key, String.Join( ", ", actuals.Keys.OfType<object>().Select( o => o == null ? String.Empty : o.ToString() ).ToArray() ) );
775+
Verify( entry.Value, actuals[ key ] );
772776
}
773777
return;
774778
}
@@ -1990,7 +1994,7 @@ foreach ( var item in constructorParamterSpecs )
19901994
{
19911995
var ext = unpacker.LastReadData.AsMessagePackExtendedTypeObject();
19921996
Assert.That( ext.TypeCode, Is.EqualTo( 1 ) );
1993-
return new DateTime( BigEndianBinary.ToInt64( ext.Body, 0 ) ).ToUniversalTime();
1997+
return new DateTime( BigEndianBinary.ToInt64( ext.Body, 0 ), DateTimeKind.Utc );
19941998
}
19951999
}
19962000

@@ -2590,4 +2594,4 @@ private static string GetSimpleInitializer( Tuple<Object, string, string, bool>
25902594
return tuple.Item3.Remove( index );
25912595
}
25922596
}
2593-
#>
2597+
#>

0 commit comments

Comments
 (0)