Skip to content

Instantly share code, notes, and snippets.

@mattjohnsonpint
Created October 26, 2012 03:02
Show Gist options
  • Select an option

  • Save mattjohnsonpint/3956638 to your computer and use it in GitHub Desktop.

Select an option

Save mattjohnsonpint/3956638 to your computer and use it in GitHub Desktop.
RavenDB Bug getting DateTimeOffset value from metadata
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