Skip to content

Instantly share code, notes, and snippets.

@AlexandrYZ
Created October 5, 2011 05:39
Show Gist options
  • Save AlexandrYZ/1263732 to your computer and use it in GitHub Desktop.
Save AlexandrYZ/1263732 to your computer and use it in GitHub Desktop.
Protobuf DateTimeKind serialization fail
using System;
using System.IO;
using NUnit.Framework;
using ProtoBuf;
namespace Protobuf_DateTimeKindTest
{
[TestFixture]
public class ProtobufTests
{
[Test]
public void TestDateTimeUtcSerialization()
{
var obj = new DateTimeWrapper { Date = DateTime.UtcNow };
obj.Date = DateTime.SpecifyKind(obj.Date, DateTimeKind.Utc);
byte [] serializedData;
using (var stream = new MemoryStream())
{
Serializer.Serialize(stream, obj);
serializedData = stream.ToArray();
}
DateTimeWrapper deserialized;
using (var stream = new MemoryStream(serializedData))
{
deserialized = Serializer.Deserialize<DateTimeWrapper>(stream);
}
Assert.AreEqual(DateTimeKind.Utc, deserialized.Date.Kind);
}
}
public class DateTimeWrapper
{
public DateTime Date { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment