Created
May 16, 2012 15:16
-
-
Save jsclayton/2711131 to your computer and use it in GitHub Desktop.
Protobuf-net Serialization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using FluentAssertions; | |
using NUnit.Framework; | |
using ProtoBuf; | |
namespace ProtoBuffs | |
{ | |
[ProtoContract] | |
public class AccessTokenV1 | |
{ | |
[ProtoMember(1)] | |
public string AccessToken { get; set; } | |
} | |
[ProtoContract] | |
public class AccessTokenV2 | |
{ | |
[ProtoMember(1)] | |
public string AccessToken { get; set; } | |
[ProtoMember(2)] | |
public string RefreshToken { get; set; } | |
} | |
[TestFixture] | |
public class SerializationTests | |
{ | |
[Test] | |
public void CanDeserializeIntoSomethingDifferent() | |
{ | |
using (var stream = new MemoryStream()) | |
{ | |
var token1 = new AccessTokenV1 { AccessToken = Guid.NewGuid().ToString() }; | |
Serializer.Serialize(stream, token1); | |
stream.Position = 0; | |
var token2 = Serializer.Deserialize<AccessTokenV2>(stream); | |
token2.AccessToken.Should().Be(token1.AccessToken); | |
token2.RefreshToken.Should().BeNullOrEmpty(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment