Created
October 26, 2012 03:02
-
-
Save mattjohnsonpint/3956638 to your computer and use it in GitHub Desktop.
RavenDB Bug getting DateTimeOffset value from metadata
This file contains hidden or 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 Raven.Client.Embedded; | |
| using Raven.Json.Linq; | |
| using Xunit; | |
| namespace RavenTests | |
| { | |
| public class Tests | |
| { | |
| [Fact] | |
| public void Test() | |
| { | |
| var documentStore = new EmbeddableDocumentStore { RunInMemory = true }; | |
| documentStore.Initialize(); | |
| var someDate = new DateTimeOffset(2012, 1, 1, 0, 0, 0, TimeSpan.Zero); | |
| using (var session = documentStore.OpenSession()) | |
| { | |
| // Add some data | |
| var ball = new Ball { Id = "balls/1", Color = "Red" }; | |
| session.Store(ball); | |
| // Give it a metadata value that is a DateTimeOffset | |
| var metadata = session.Advanced.GetMetadataFor(ball); | |
| metadata.Add("SomeDate", RavenJToken.FromObject(someDate)); | |
| session.SaveChanges(); | |
| } | |
| using (var session = documentStore.OpenSession()) | |
| { | |
| var ball = session.Load<Ball>("balls/1"); | |
| var metadata = session.Advanced.GetMetadataFor(ball); | |
| // This line fails with the message: Invalid cast from 'System.String' to 'System.DateTimeOffset'. | |
| var dt = metadata.Value<DateTimeOffset>("SomeDate"); | |
| Assert.Equal(someDate, dt); | |
| } | |
| } | |
| } | |
| public class Ball | |
| { | |
| public string Id { get; set; } | |
| public string Color { get; set; } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment