Skip to content

Commit a2ea3d9

Browse files
authored
Merge pull request #219 from ioi-christianco/master
Fix deserialization of partial System.Version objects
2 parents 2b988c9 + 39494fb commit a2ea3d9

12 files changed

Lines changed: 1776 additions & 1279 deletions

src/MsgPack/Serialization/DefaultSerializers/System_VersionMessagePackSerializer.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ protected internal override Version UnpackFromCore( Unpacker unpacker )
7878
SerializationExceptions.ThrowMissingItem( 3, unpacker );
7979
}
8080

81+
if (build < 0 && revision < 0)
82+
{
83+
return new Version(major, minor);
84+
}
85+
else if (revision < 0)
86+
{
87+
return new Version(major, minor, build);
88+
}
89+
8190
return new Version( major, minor, build, revision );
8291
}
8392

@@ -129,6 +138,15 @@ protected internal override async Task<Version> UnpackFromAsyncCore( Unpacker un
129138
SerializationExceptions.ThrowMissingItem( 3, unpacker );
130139
}
131140

141+
if (build.Value < 0 && revision.Value < 0)
142+
{
143+
return new Version(major.Value, minor.Value);
144+
}
145+
else if (revision.Value < 0)
146+
{
147+
return new Version(major.Value, minor.Value, build.Value);
148+
}
149+
132150
return new Version( major.Value, minor.Value, build.Value, revision.Value );
133151
}
134152

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

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20768,25 +20768,73 @@ public void TestUriFieldArrayNull()
2076820768
}
2076920769

2077020770
[Test]
20771-
public void TestVersionField()
20771+
public void TestVersionConstructorMajorMinor()
20772+
{
20773+
this.TestCoreWithAutoVerify( new Version( 1, 2 ), GetSerializationContext() );
20774+
}
20775+
20776+
[Test]
20777+
public void TestVersionConstructorMajorMinorArray()
20778+
{
20779+
this.TestCoreWithAutoVerify( Enumerable.Repeat( new Version( 1, 2 ), 2 ).ToArray(), GetSerializationContext() );
20780+
}
20781+
20782+
[Test]
20783+
public void TestVersionConstructorMajorMinorNull()
20784+
{
20785+
this.TestCoreWithAutoVerify( default( Version ), GetSerializationContext() );
20786+
}
20787+
20788+
[Test]
20789+
public void TestVersionConstructorMajorMinorArrayNull()
20790+
{
20791+
this.TestCoreWithAutoVerify( default( Version[] ), GetSerializationContext() );
20792+
}
20793+
20794+
[Test]
20795+
public void TestVersionConstructorMajorMinorBuild()
20796+
{
20797+
this.TestCoreWithAutoVerify( new Version( 1, 2, 3 ), GetSerializationContext() );
20798+
}
20799+
20800+
[Test]
20801+
public void TestVersionConstructorMajorMinorBuildArray()
20802+
{
20803+
this.TestCoreWithAutoVerify( Enumerable.Repeat( new Version( 1, 2, 3 ), 2 ).ToArray(), GetSerializationContext() );
20804+
}
20805+
20806+
[Test]
20807+
public void TestVersionConstructorMajorMinorBuildNull()
20808+
{
20809+
this.TestCoreWithAutoVerify( default( Version ), GetSerializationContext() );
20810+
}
20811+
20812+
[Test]
20813+
public void TestVersionConstructorMajorMinorBuildArrayNull()
20814+
{
20815+
this.TestCoreWithAutoVerify( default( Version[] ), GetSerializationContext() );
20816+
}
20817+
20818+
[Test]
20819+
public void TestFullVersionConstructor()
2077220820
{
2077320821
this.TestCoreWithAutoVerify( new Version( 1, 2, 3, 4 ), GetSerializationContext() );
2077420822
}
2077520823

2077620824
[Test]
20777-
public void TestVersionFieldArray()
20825+
public void TestFullVersionConstructorArray()
2077820826
{
2077920827
this.TestCoreWithAutoVerify( Enumerable.Repeat( new Version( 1, 2, 3, 4 ), 2 ).ToArray(), GetSerializationContext() );
2078020828
}
2078120829

2078220830
[Test]
20783-
public void TestVersionFieldNull()
20831+
public void TestFullVersionConstructorNull()
2078420832
{
2078520833
this.TestCoreWithAutoVerify( default( Version ), GetSerializationContext() );
2078620834
}
2078720835

2078820836
[Test]
20789-
public void TestVersionFieldArrayNull()
20837+
public void TestFullVersionConstructorArrayNull()
2079020838
{
2079120839
this.TestCoreWithAutoVerify( default( Version[] ), GetSerializationContext() );
2079220840
}

test/MsgPack.UnitTest/Serialization/ArrayFieldBasedAutoMessagePackSerializerTest.cs

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20768,25 +20768,73 @@ public void TestUriFieldArrayNull()
2076820768
}
2076920769

2077020770
[Test]
20771-
public void TestVersionField()
20771+
public void TestVersionConstructorMajorMinor()
20772+
{
20773+
this.TestCoreWithAutoVerify( new Version( 1, 2 ), GetSerializationContext() );
20774+
}
20775+
20776+
[Test]
20777+
public void TestVersionConstructorMajorMinorArray()
20778+
{
20779+
this.TestCoreWithAutoVerify( Enumerable.Repeat( new Version( 1, 2 ), 2 ).ToArray(), GetSerializationContext() );
20780+
}
20781+
20782+
[Test]
20783+
public void TestVersionConstructorMajorMinorNull()
20784+
{
20785+
this.TestCoreWithAutoVerify( default( Version ), GetSerializationContext() );
20786+
}
20787+
20788+
[Test]
20789+
public void TestVersionConstructorMajorMinorArrayNull()
20790+
{
20791+
this.TestCoreWithAutoVerify( default( Version[] ), GetSerializationContext() );
20792+
}
20793+
20794+
[Test]
20795+
public void TestVersionConstructorMajorMinorBuild()
20796+
{
20797+
this.TestCoreWithAutoVerify( new Version( 1, 2, 3 ), GetSerializationContext() );
20798+
}
20799+
20800+
[Test]
20801+
public void TestVersionConstructorMajorMinorBuildArray()
20802+
{
20803+
this.TestCoreWithAutoVerify( Enumerable.Repeat( new Version( 1, 2, 3 ), 2 ).ToArray(), GetSerializationContext() );
20804+
}
20805+
20806+
[Test]
20807+
public void TestVersionConstructorMajorMinorBuildNull()
20808+
{
20809+
this.TestCoreWithAutoVerify( default( Version ), GetSerializationContext() );
20810+
}
20811+
20812+
[Test]
20813+
public void TestVersionConstructorMajorMinorBuildArrayNull()
20814+
{
20815+
this.TestCoreWithAutoVerify( default( Version[] ), GetSerializationContext() );
20816+
}
20817+
20818+
[Test]
20819+
public void TestFullVersionConstructor()
2077220820
{
2077320821
this.TestCoreWithAutoVerify( new Version( 1, 2, 3, 4 ), GetSerializationContext() );
2077420822
}
2077520823

2077620824
[Test]
20777-
public void TestVersionFieldArray()
20825+
public void TestFullVersionConstructorArray()
2077820826
{
2077920827
this.TestCoreWithAutoVerify( Enumerable.Repeat( new Version( 1, 2, 3, 4 ), 2 ).ToArray(), GetSerializationContext() );
2078020828
}
2078120829

2078220830
[Test]
20783-
public void TestVersionFieldNull()
20831+
public void TestFullVersionConstructorNull()
2078420832
{
2078520833
this.TestCoreWithAutoVerify( default( Version ), GetSerializationContext() );
2078620834
}
2078720835

2078820836
[Test]
20789-
public void TestVersionFieldArrayNull()
20837+
public void TestFullVersionConstructorArrayNull()
2079020838
{
2079120839
this.TestCoreWithAutoVerify( default( Version[] ), GetSerializationContext() );
2079220840
}

test/MsgPack.UnitTest/Serialization/ArrayGenerationBasedAutoMessagePackSerializerTest.cs

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17291,25 +17291,73 @@ public void TestUriFieldArrayNull()
1729117291
}
1729217292

1729317293
[Test]
17294-
public void TestVersionField()
17294+
public void TestVersionConstructorMajorMinor()
17295+
{
17296+
this.TestCoreWithAutoVerify( new Version( 1, 2 ), GetSerializationContext() );
17297+
}
17298+
17299+
[Test]
17300+
public void TestVersionConstructorMajorMinorArray()
17301+
{
17302+
this.TestCoreWithAutoVerify( Enumerable.Repeat( new Version( 1, 2 ), 2 ).ToArray(), GetSerializationContext() );
17303+
}
17304+
17305+
[Test]
17306+
public void TestVersionConstructorMajorMinorNull()
17307+
{
17308+
this.TestCoreWithAutoVerify( default( Version ), GetSerializationContext() );
17309+
}
17310+
17311+
[Test]
17312+
public void TestVersionConstructorMajorMinorArrayNull()
17313+
{
17314+
this.TestCoreWithAutoVerify( default( Version[] ), GetSerializationContext() );
17315+
}
17316+
17317+
[Test]
17318+
public void TestVersionConstructorMajorMinorBuild()
17319+
{
17320+
this.TestCoreWithAutoVerify( new Version( 1, 2, 3 ), GetSerializationContext() );
17321+
}
17322+
17323+
[Test]
17324+
public void TestVersionConstructorMajorMinorBuildArray()
17325+
{
17326+
this.TestCoreWithAutoVerify( Enumerable.Repeat( new Version( 1, 2, 3 ), 2 ).ToArray(), GetSerializationContext() );
17327+
}
17328+
17329+
[Test]
17330+
public void TestVersionConstructorMajorMinorBuildNull()
17331+
{
17332+
this.TestCoreWithAutoVerify( default( Version ), GetSerializationContext() );
17333+
}
17334+
17335+
[Test]
17336+
public void TestVersionConstructorMajorMinorBuildArrayNull()
17337+
{
17338+
this.TestCoreWithAutoVerify( default( Version[] ), GetSerializationContext() );
17339+
}
17340+
17341+
[Test]
17342+
public void TestFullVersionConstructor()
1729517343
{
1729617344
this.TestCoreWithAutoVerify( new Version( 1, 2, 3, 4 ), GetSerializationContext() );
1729717345
}
1729817346

1729917347
[Test]
17300-
public void TestVersionFieldArray()
17348+
public void TestFullVersionConstructorArray()
1730117349
{
1730217350
this.TestCoreWithAutoVerify( Enumerable.Repeat( new Version( 1, 2, 3, 4 ), 2 ).ToArray(), GetSerializationContext() );
1730317351
}
1730417352

1730517353
[Test]
17306-
public void TestVersionFieldNull()
17354+
public void TestFullVersionConstructorNull()
1730717355
{
1730817356
this.TestCoreWithAutoVerify( default( Version ), GetSerializationContext() );
1730917357
}
1731017358

1731117359
[Test]
17312-
public void TestVersionFieldArrayNull()
17360+
public void TestFullVersionConstructorArrayNull()
1731317361
{
1731417362
this.TestCoreWithAutoVerify( default( Version[] ), GetSerializationContext() );
1731517363
}

test/MsgPack.UnitTest/Serialization/ArrayReflectionBasedAutoMessagePackSerializerTest.cs

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20669,25 +20669,73 @@ public void TestUriFieldArrayNull()
2066920669
}
2067020670

2067120671
[Test]
20672-
public void TestVersionField()
20672+
public void TestVersionConstructorMajorMinor()
20673+
{
20674+
this.TestCoreWithAutoVerify( new Version( 1, 2 ), GetSerializationContext() );
20675+
}
20676+
20677+
[Test]
20678+
public void TestVersionConstructorMajorMinorArray()
20679+
{
20680+
this.TestCoreWithAutoVerify( Enumerable.Repeat( new Version( 1, 2 ), 2 ).ToArray(), GetSerializationContext() );
20681+
}
20682+
20683+
[Test]
20684+
public void TestVersionConstructorMajorMinorNull()
20685+
{
20686+
this.TestCoreWithAutoVerify( default( Version ), GetSerializationContext() );
20687+
}
20688+
20689+
[Test]
20690+
public void TestVersionConstructorMajorMinorArrayNull()
20691+
{
20692+
this.TestCoreWithAutoVerify( default( Version[] ), GetSerializationContext() );
20693+
}
20694+
20695+
[Test]
20696+
public void TestVersionConstructorMajorMinorBuild()
20697+
{
20698+
this.TestCoreWithAutoVerify( new Version( 1, 2, 3 ), GetSerializationContext() );
20699+
}
20700+
20701+
[Test]
20702+
public void TestVersionConstructorMajorMinorBuildArray()
20703+
{
20704+
this.TestCoreWithAutoVerify( Enumerable.Repeat( new Version( 1, 2, 3 ), 2 ).ToArray(), GetSerializationContext() );
20705+
}
20706+
20707+
[Test]
20708+
public void TestVersionConstructorMajorMinorBuildNull()
20709+
{
20710+
this.TestCoreWithAutoVerify( default( Version ), GetSerializationContext() );
20711+
}
20712+
20713+
[Test]
20714+
public void TestVersionConstructorMajorMinorBuildArrayNull()
20715+
{
20716+
this.TestCoreWithAutoVerify( default( Version[] ), GetSerializationContext() );
20717+
}
20718+
20719+
[Test]
20720+
public void TestFullVersionConstructor()
2067320721
{
2067420722
this.TestCoreWithAutoVerify( new Version( 1, 2, 3, 4 ), GetSerializationContext() );
2067520723
}
2067620724

2067720725
[Test]
20678-
public void TestVersionFieldArray()
20726+
public void TestFullVersionConstructorArray()
2067920727
{
2068020728
this.TestCoreWithAutoVerify( Enumerable.Repeat( new Version( 1, 2, 3, 4 ), 2 ).ToArray(), GetSerializationContext() );
2068120729
}
2068220730

2068320731
[Test]
20684-
public void TestVersionFieldNull()
20732+
public void TestFullVersionConstructorNull()
2068520733
{
2068620734
this.TestCoreWithAutoVerify( default( Version ), GetSerializationContext() );
2068720735
}
2068820736

2068920737
[Test]
20690-
public void TestVersionFieldArrayNull()
20738+
public void TestFullVersionConstructorArrayNull()
2069120739
{
2069220740
this.TestCoreWithAutoVerify( default( Version[] ), GetSerializationContext() );
2069320741
}

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

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,26 @@ public Uri UriField
202202
get { return this._UriField; }
203203
set { this._UriField = value; }
204204
}
205-
private Version _VersionField;
205+
private Version _VersionConstructorMajorMinor;
206206

207-
public Version VersionField
207+
public Version VersionConstructorMajorMinor
208208
{
209-
get { return this._VersionField; }
210-
set { this._VersionField = value; }
209+
get { return this._VersionConstructorMajorMinor; }
210+
set { this._VersionConstructorMajorMinor = value; }
211+
}
212+
private Version _VersionConstructorMajorMinorBuild;
213+
214+
public Version VersionConstructorMajorMinorBuild
215+
{
216+
get { return this._VersionConstructorMajorMinorBuild; }
217+
set { this._VersionConstructorMajorMinorBuild = value; }
218+
}
219+
private Version _FullVersionConstructor;
220+
221+
public Version FullVersionConstructor
222+
{
223+
get { return this._FullVersionConstructor; }
224+
set { this._FullVersionConstructor = value; }
211225
}
212226
private CultureInfo _InvariantCultureField;
213227

@@ -633,7 +647,9 @@ public ComplexTypeGenerated Initialize()
633647
this._DateTimeField = DateTime.UtcNow;
634648
this._DateTimeOffsetField = DateTimeOffset.UtcNow;
635649
this._UriField = new Uri( "http://example.com/" );
636-
this._VersionField = new Version( 1, 2, 3, 4 );
650+
this._VersionConstructorMajorMinor = new Version( 1, 2 );
651+
this._VersionConstructorMajorMinorBuild = new Version( 1, 2, 3 );
652+
this._FullVersionConstructor = new Version( 1, 2, 3, 4 );
637653
this._InvariantCultureField = CultureInfo.InvariantCulture;
638654
this._CurrentCultureField = CultureInfo.CurrentCulture;
639655
#if !SILVERLIGHT
@@ -751,7 +767,9 @@ public void Verify( ComplexTypeGenerated expected )
751767
AutoMessagePackSerializerTest.Verify( expected._DateTimeField, this._DateTimeField );
752768
AutoMessagePackSerializerTest.Verify( expected._DateTimeOffsetField, this._DateTimeOffsetField );
753769
AutoMessagePackSerializerTest.Verify( expected._UriField, this._UriField );
754-
AutoMessagePackSerializerTest.Verify( expected._VersionField, this._VersionField );
770+
AutoMessagePackSerializerTest.Verify( expected._VersionConstructorMajorMinor, this._VersionConstructorMajorMinor );
771+
AutoMessagePackSerializerTest.Verify( expected._VersionConstructorMajorMinorBuild, this._VersionConstructorMajorMinorBuild );
772+
AutoMessagePackSerializerTest.Verify( expected._FullVersionConstructor, this._FullVersionConstructor );
755773
AutoMessagePackSerializerTest.Verify( expected._InvariantCultureField, this._InvariantCultureField );
756774
AutoMessagePackSerializerTest.Verify( expected._CurrentCultureField, this._CurrentCultureField );
757775
#if !SILVERLIGHT

0 commit comments

Comments
 (0)