Skip to content

Instantly share code, notes, and snippets.

@thefringeninja
Created May 1, 2012 21:40
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 thefringeninja/2571658 to your computer and use it in GitHub Desktop.
Save thefringeninja/2571658 to your computer and use it in GitHub Desktop.
public abstract class RavenSingleProjectionSpecification<TViewModel>
: QuerySpecification<List<Event>, TViewModel>
{
public List<Event> Given = new List<Event>();
public RavenRelativeUri Key;
public RavenSingleProjectionSpecification()
{
var store = new EmbeddableDocumentStore
{
RunInMemory = true,
//UseEmbeddedHttpServer = true,
}
.CustomizeWith(RavenConventions.Standard)
.Initialize();
var provider = new DocumentSessionProvider
{
CurrentSession = store.OpenSession()
};
var bus = new Bus();
bus.RegisterReadModel(provider);
On = () => Given;
When = events =>
{
events.Each(bus.Publish);
provider.CurrentSession.SaveChanges();
using (var session = store.OpenSession())
{
return session.Load<TViewModel>((ValueType)Key);
}
};
}
}
public class SomeDocumentSpecification : RavenSingleProjectionSpecification<SomeDocument> {}
public class Specifications
{
public SomeDocumentSpecification not_important = new SomeDocumentSpecification
{
Given =
{
new SomeEvent()
},
Key = "/not-important",
Expect =
{
result => result.SomeProperty == "Something"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment