Skip to content

@di97mni /gist:3009467
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.