public void WhenSaving_ThenGetsEtag() { using (var store = NewDocumentStore()) { var foo = new IndexWithTwoProperties.Foo {Id = Guid.NewGuid().ToString(), Value = "foo"}; using (var session = store.OpenSession()) { session.Store(foo); session.SaveChanges(); var metadata = session.Advanced.GetMetadataFor(foo); Assert.NotNull(metadata.Value<string>("@etag")); } using (var session = store.OpenSession()) { var loaded = session.Load<IndexWithTwoProperties.Foo>(foo.Id); var metadata = session.Advanced.GetMetadataFor(loaded); Assert.NotNull(metadata.Value<string>("@etag")); } } }
public void WhenModifyingMetadata_ThenSavesChanges() { using(var store = NewDocumentStore()) { string id = null; // Initial create using (var session = store.OpenSession()) { var foo = new IndexWithTwoProperties.Foo { Value = "hello" }; session.Store(foo); session.SaveChanges(); id = foo.Id; } // Update metadata using (var session = store.OpenSession()) { var foo = session.Load<IndexWithTwoProperties.Foo>(id); var metadata = session.Advanced.GetMetadataFor(foo); metadata["foo"] = "bar"; session.SaveChanges(); } // Entity should have the updated metadata now. using (var session = store.OpenSession()) { var foo = session.Load<IndexWithTwoProperties.Foo>(id); var metadata = session.Advanced.GetMetadataFor(foo); Assert.Equal("bar", metadata["foo"].Value<string>()); } } }
public void WhenSaving_ThenGetsEtag() { using (var store = NewDocumentStore()) { var foo = new IndexWithTwoProperties.Foo { Id = Guid.NewGuid().ToString(), Value = "foo" }; using (var session = store.OpenSession()) { session.Store(foo); session.SaveChanges(); var metadata = session.Advanced.GetMetadataFor(foo); Assert.NotNull(metadata.Value <string>("@etag")); } using (var session = store.OpenSession()) { var loaded = session.Load <IndexWithTwoProperties.Foo>(foo.Id); var metadata = session.Advanced.GetMetadataFor(loaded); Assert.NotNull(metadata.Value <string>("@etag")); } } }
public void WhenUpdating_ThenPreservesMetadata() { using (var store = NewDocumentStore()) { var foo = new IndexWithTwoProperties.Foo {Value = "hello"}; using (var session = store.OpenSession()) { session.Store(foo); session.Advanced.GetMetadataFor(foo)["bar"] = "baz"; session.SaveChanges(); } // When we load, the metadata is there. using (var session = store.OpenSession()) { var saved = session.Load<IndexWithTwoProperties.Foo>(foo.Id); var metadata = session.Advanced.GetMetadataFor(saved); Assert.Equal("baz", metadata["bar"].Value<string>()); } // When we update, we kill the existing metadata. using (var session = store.OpenSession()) { var saved = session.Load<IndexWithTwoProperties.Foo>(foo.Id); saved.Value = "bye"; session.Store(saved); session.SaveChanges(); } // When we load, the metadata is gone. using (var session = store.OpenSession()) { var saved = session.Load<IndexWithTwoProperties.Foo>(foo.Id); var metadata = session.Advanced.GetMetadataFor(saved); // FAILS HERE var jToken = metadata["bar"]; Assert.Equal("baz", jToken.Value<string>()); } } }
public void WhenUpdating_ThenPreservesMetadata() { using (var store = NewDocumentStore()) { var foo = new IndexWithTwoProperties.Foo { Value = "hello" }; using (var session = store.OpenSession()) { session.Store(foo); session.Advanced.GetMetadataFor(foo)["bar"] = "baz"; session.SaveChanges(); } // When we load, the metadata is there. using (var session = store.OpenSession()) { var saved = session.Load <IndexWithTwoProperties.Foo>(foo.Id); var metadata = session.Advanced.GetMetadataFor(saved); Assert.Equal("baz", metadata["bar"].Value <string>()); } // When we update, we kill the existing metadata. using (var session = store.OpenSession()) { var saved = session.Load <IndexWithTwoProperties.Foo>(foo.Id); saved.Value = "bye"; session.Store(saved); session.SaveChanges(); } // When we load, the metadata is gone. using (var session = store.OpenSession()) { var saved = session.Load <IndexWithTwoProperties.Foo>(foo.Id); var metadata = session.Advanced.GetMetadataFor(saved); // FAILS HERE var jToken = metadata["bar"]; Assert.Equal("baz", jToken.Value <string>()); } } }
public void WhenModifyingMetadata_ThenSavesChanges() { using (var store = NewDocumentStore()) { string id = null; // Initial create using (var session = store.OpenSession()) { var foo = new IndexWithTwoProperties.Foo { Value = "hello" }; session.Store(foo); session.SaveChanges(); id = foo.Id; } // Update metadata using (var session = store.OpenSession()) { var foo = session.Load <IndexWithTwoProperties.Foo>(id); var metadata = session.Advanced.GetMetadataFor(foo); metadata["foo"] = "bar"; session.SaveChanges(); } // Entity should have the updated metadata now. using (var session = store.OpenSession()) { var foo = session.Load <IndexWithTwoProperties.Foo>(id); var metadata = session.Advanced.GetMetadataFor(foo); Assert.Equal("bar", metadata["foo"].Value <string>()); } } }