Created
June 28, 2012 06:16
-
-
Save di97mni/3009467 to your computer and use it in GitHub Desktop.
Code example to SO question "Eventstore and Sqlite in-memory"
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
// This gist is for http://stackoverflow.com/questions/7854446/eventstore-and-sqlite-in-memory/7928744#comment14765049_7928744 | |
// From example http://www.filedropper.com/eventstoredisposedobjectissue | |
// If Get() is changed from returning IQueryable to IEnumerable and adding commits.ToArray() then it's working | |
// So from this | |
public class CommitsController : ApiController | |
{ | |
private readonly IStoreEvents store; | |
public CommitsController(IStoreEvents store) | |
{ | |
this.store = store; | |
} | |
public IQueryable<Commit> Get() | |
{ | |
var commits = store.Advanced.GetFrom(EventStoreConstants.StreamId, 0, int.MaxValue); | |
return commits.AsQueryable(); | |
} | |
} | |
// To this | |
public class CommitsController : ApiController | |
{ | |
private readonly IStoreEvents store; | |
public CommitsController(IStoreEvents store) | |
{ | |
this.store = store; | |
} | |
public IEnumerable<Commit> Get() | |
{ | |
var commits = store.Advanced.GetFrom(EventStoreConstants.StreamId, 0, int.MaxValue); | |
return commits.ToArray(); | |
} | |
} | |
// Note that test also needs to be changed to be able to handle IEnumerable instead of IQueryable | |
[Test] | |
public void Can_get_commits() | |
{ | |
var response = client.GetAsync("http://something/api/commits").Result; | |
if (response.IsSuccessStatusCode == false) | |
{ | |
var error = response.Content.ReadAsStringAsync().Result; | |
Console.Out.WriteLine("error = {0}", error); | |
} | |
response.EnsureSuccessStatusCode(); | |
var result = response.Content.ReadAsAsync<IEnumerable<Commit>>().Result; | |
Assert.True(result.Any()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment