Created
February 3, 2015 22:47
-
-
Save thefringeninja/b736fa772b94b43d845d to your computer and use it in GitHub Desktop.
Raven Async and Tests
This file contains hidden or 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 class RavenTestBase { | |
Task<IDocumentStore> _createDocumentStore; | |
ctor() { | |
var source = new TaskCompletionSource<IDocumentStore>(); | |
_createDocumentStore = source.Task; | |
Task.Run(async () => { | |
var store = InitializeDocumentStore(); | |
await CreateIndices(documentStore); | |
await Seed(documentStore); | |
// or, await Task.WhenAll(CreateIndices(documentStore), Seed(documentStore)); if there are nodependencies | |
try { | |
source.SetResult(documentStore); | |
} | |
catch (Exception ex){ | |
source.SetException(ex); | |
} | |
}); | |
} | |
virtual protected IDocumentStore InitializeDocumentStore() { | |
return new EmbeddedDocumentStore{RunInMemory=true}.Initialize(); | |
} | |
Task CreateIndices(IDocumentStore documentStore){ | |
} | |
Task Seed(IDocumentStore documentStore) { | |
} | |
} | |
public class NewFacts { | |
[Fact] | |
public async Task should_be_orwellian() { | |
var store = await _createDocumentStore; | |
Assert.IsTrue(false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
quick question :) I don't understand the connection between this :
and this
var store = await _createDocumentStore;
variables that are
private
are usually prepended with an_
.. so in the test/fact, you're trying to access a private variable (which is out of scope). I also don't understand why you would expose a Task as the result, instead of theIDocumentStore
. Otherwise, we can just expose a method that does all the above, instead of the RESULT of the method (which is what I'm trying to expose).