Skip to content

Instantly share code, notes, and snippets.

@thoemmi
Last active January 1, 2016 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thoemmi/8123604 to your computer and use it in GitHub Desktop.
Save thoemmi/8123604 to your computer and use it in GitHub Desktop.
using System.Diagnostics;
using Raven.Client.Embedded;
using Raven.Client.Listeners;
using Raven.Json.Linq;
namespace StackOverflow20764813 {
internal class Program {
private static void Main() {
using (var store = new EmbeddableDocumentStore { RunInMemory = true }) {
store.RegisterListener(new TestDocumentStoreListener());
store.Initialize();
using (var session = store.OpenSession()) {
var person = new Person { Name = "Ayende" };
session.Store(person);
session.SaveChanges();
}
using (var session = store.OpenSession()) {
var person = session.Load<Person>(1);
// TestDocumentStoreListener.BeforeStore returns false, so the name should still be "Ayende"
Debug.Assert(person.Name == "Ayende");
}
}
}
}
internal class Person {
public string Id { get; set; }
public string Name { get; set; }
}
internal class TestDocumentStoreListener : IDocumentStoreListener {
public bool BeforeStore(string key, object entityInstance, RavenJObject metadata, RavenJObject original) {
var person = (Person) entityInstance;
person.Name = "Oren";
return false;
}
public void AfterStore(string key, object entityInstance, RavenJObject metadata) {
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment