public
Last active

Code example to SO question "Eventstore and Sqlite in-memory"

  • Download Gist
gistfile1.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
// 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());
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.