IObservable <Company> Subscribe(ResolveEventStreamContext context, ContextFactory contextFactory, ILogger logger) { long lastId = 0; var inner = Observable.Using( token => Task.FromResult(contextFactory.BuildContext()), async(ctx, token) => { try { var companies = await GetCompanies(context, ctx, lastId, token: token); if (companies.Any()) { lastId = companies.Max(transaction => transaction.Id); } return(companies.ToObservable()); } catch (OperationCanceledException) { logger.LogInformation("Companies subscription has been cancelled."); return(Observable.Empty <Company>()); } catch (Exception e) { logger.LogError(e, "Unable to get companies."); return(Observable.Empty <Company>()); } }); return(Observable.Interval(TimeSpan.FromSeconds(1)).SelectMany(_ => inner)); }
public void RetrieveStudentsTest() { using (var appContext = ContextFactory.BuildContext()) { // Setup var foo = new Student() { Name = "John Snow", Address = "Winterfell Avenue 39b" }; var bar = new Student() { Name = "Grey Worm", Address = "Tent Park 13122" }; appContext.Students.Add(foo); appContext.Students.Add(bar); appContext.SaveChanges(); // Act var data = appContext.Students; // Assert Assert.Contains(data, e => e.Id == foo.Id); Assert.Contains(data, e => e.Id == bar.Id); // Cleanup appContext.Students.Remove(foo); appContext.Students.Remove(bar); appContext.SaveChanges(); } }