Created
May 1, 2012 21:40
-
-
Save thefringeninja/2571658 to your computer and use it in GitHub Desktop.
This file contains 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
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