Created
October 5, 2011 05:39
-
-
Save AlexandrYZ/1263732 to your computer and use it in GitHub Desktop.
Protobuf DateTimeKind serialization fail
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 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