Skip to content

Instantly share code, notes, and snippets.

@jsclayton
Created May 16, 2012 15:16
Show Gist options
  • Save jsclayton/2711131 to your computer and use it in GitHub Desktop.
Save jsclayton/2711131 to your computer and use it in GitHub Desktop.
Protobuf-net Serialization
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