Skip to content

Instantly share code, notes, and snippets.

@di97mni
Created June 28, 2012 06:16
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 di97mni/3009467 to your computer and use it in GitHub Desktop.
Save di97mni/3009467 to your computer and use it in GitHub Desktop.
Code example to SO question "Eventstore and Sqlite in-memory"
// 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