public void FetchFunctionShouldBeCalledOnceForGetOrFetchObject() { int fetchCount = 0; var fetcher = new Func<IObservable<Tuple<string, string>>>(() => { fetchCount++; return Observable.Return(new Tuple<string, string>("Foo", "Bar")); }); string path; using(Utility.WithEmptyDirectory(out path)) { using(var fixture = new TPersistentBlobCache(path)) { var result = fixture.GetOrFetchObject("Test", fetcher).First(); Assert.Equal("Foo", result.Item1); Assert.Equal("Bar", result.Item2); Assert.Equal(1, fetchCount); // 2nd time around, we should be grabbing from cache result = fixture.GetOrFetchObject("Test", fetcher).First(); Assert.Equal("Foo", result.Item1); Assert.Equal("Bar", result.Item2); Assert.Equal(1, fetchCount); } using(var fixture = new TPersistentBlobCache(path)) { var result = fixture.GetOrFetchObject("Test", fetcher).First(); Assert.Equal("Foo", result.Item1); Assert.Equal("Bar", result.Item2); Assert.Equal(1, fetchCount); } } }
public void ObjectsShouldBeRoundtrippable() { new TestScheduler().With(sched => { string path; var input = new UserObject() { Bio = "A totally cool cat!", Name = "octocat", Blog = "http://www.github.com" }; UserObject result; using (Utility.WithEmptyDirectory(out path)) { using (var fixture = new TPersistentBlobCache(path)) { fixture.InsertObject("key", input); } sched.Start(); using (var fixture = new TPersistentBlobCache(path)) { var action = fixture.GetObjectAsync <UserObject>("key"); sched.Start(); result = action.First(); } } Assert.Equal(input.Blog, result.Blog); Assert.Equal(input.Bio, result.Bio); Assert.Equal(input.Name, result.Name); }); }
public void ObjectsShouldBeRoundtrippable() { new TestScheduler().With(sched => { string path; var input = new UserObject() {Bio = "A totally cool cat!", Name = "octocat", Blog = "http://www.github.com"}; UserObject result; using (Utility.WithEmptyDirectory(out path)) { using (var fixture = new TPersistentBlobCache(path)) { fixture.InsertObject("key", input); } sched.Start(); using (var fixture = new TPersistentBlobCache(path)) { var action = fixture.GetObjectAsync<UserObject>("key"); sched.Start(); result = action.First(); } } Assert.Equal(input.Blog, result.Blog); Assert.Equal(input.Bio, result.Bio); Assert.Equal(input.Name, result.Name); }); }
public void ArraysShouldBeRoundtrippableUsingObjectFactory() { new TestScheduler().With(sched => { string path; var input = new[] {new UserModel(new UserObject()) {Age = 123, Name = "Old"}, new UserModel(new UserObject()) {Age = 123, Name = "Old"}}; UserModel[] result; using (Utility.WithEmptyDirectory(out path)) { using (var fixture = new TPersistentBlobCache(path)) { fixture.InsertObject("key", input); } sched.Start(); using (var fixture = new TPersistentBlobCache(path)) { var action = fixture.GetObjectAsync<UserModel[]>("key"); sched.Start(); result = action.First(); } } Assert.Equal(input.First().Age, result.First().Age); Assert.Equal(input.First().Name, result.First().Name); Assert.Equal(input.Last().Age, result.Last().Age); Assert.Equal(input.Last().Name, result.Last().Name); }); }
public void ArraysShouldBeRoundtrippableUsingObjectFactory() { new TestScheduler().With(sched => { string path; var input = new[] { new UserModel(new UserObject()) { Age = 123, Name = "Old" }, new UserModel(new UserObject()) { Age = 123, Name = "Old" } }; UserModel[] result; using (Utility.WithEmptyDirectory(out path)) { using (var fixture = new TPersistentBlobCache(path)) { fixture.InsertObject("key", input); } sched.Start(); using (var fixture = new TPersistentBlobCache(path)) { var action = fixture.GetObjectAsync <UserModel[]>("key"); sched.Start(); result = action.First(); } } Assert.Equal(input.First().Age, result.First().Age); Assert.Equal(input.First().Name, result.First().Name); Assert.Equal(input.Last().Age, result.Last().Age); Assert.Equal(input.Last().Name, result.Last().Name); }); }
public void ObjectsCanBeCreatedUsingObjectFactory() { new TestScheduler().With(sched => { string path; var input = new UserModel(new UserObject()) { Age = 123, Name = "Old" }; UserModel result; using (Utility.WithEmptyDirectory(out path)) { using (var fixture = new TPersistentBlobCache(path)) { fixture.InsertObject("key", input); } sched.Start(); using (var fixture = new TPersistentBlobCache(path)) { var action = fixture.GetObjectAsync <UserModel>("key"); sched.Start(); result = action.First(); } } Assert.Equal(input.Age, result.Age); Assert.Equal(input.Name, result.Name); }); }
public void DownloadUrlTest() { string path; using (Utility.WithEmptyDirectory(out path)) using (var fixture = new TPersistentBlobCache(path)) { var bytes = fixture.DownloadUrl(@"https://www.google.com/intl/en_com/images/srpr/logo3w.png").First(); Assert.True(bytes.Length > 0); } }
public void DownloadUrlTest() { string path; using(Utility.WithEmptyDirectory(out path)) using(var fixture = new TPersistentBlobCache(path)) { var bytes = fixture.DownloadUrl(@"https://www.google.com/intl/en_com/images/srpr/logo3w.png").First(); Assert.True(bytes.Length > 0); } }
public void FetchFunctionShouldBeCalledOnceForGetOrFetchObject() { int fetchCount = 0; var fetcher = new Func <IObservable <Tuple <string, string> > >(() => { fetchCount++; return(Observable.Return(new Tuple <string, string>("Foo", "Bar"))); }); string path; using (Utility.WithEmptyDirectory(out path)) { using (var fixture = new TPersistentBlobCache(path)) { var result = fixture.GetOrFetchObject("Test", fetcher).First(); Assert.Equal("Foo", result.Item1); Assert.Equal("Bar", result.Item2); Assert.Equal(1, fetchCount); // 2nd time around, we should be grabbing from cache result = fixture.GetOrFetchObject("Test", fetcher).First(); Assert.Equal("Foo", result.Item1); Assert.Equal("Bar", result.Item2); Assert.Equal(1, fetchCount); } using (var fixture = new TPersistentBlobCache(path)) { var result = fixture.GetOrFetchObject("Test", fetcher).First(); Assert.Equal("Foo", result.Item1); Assert.Equal("Bar", result.Item2); Assert.Equal(1, fetchCount); } } }
public void FetchFunctionShouldPropagateThrownExceptionAsObservableException() { var fetcher = new Func<IObservable<Tuple<string, string>>>(() => { throw new InvalidOperationException(); }); string path; using(Utility.WithEmptyDirectory(out path)) { using(var fixture = new TPersistentBlobCache(path)) { var result = fixture.GetOrFetchObject("Test", fetcher) .Catch(Observable.Return(new Tuple<string, string>("one", "two"))).First(); Assert.Equal("one", result.Item1); Assert.Equal("two", result.Item2); } } }
public void ObjectsCanBeCreatedUsingObjectFactory() { new TestScheduler().With(sched => { string path; var input = new UserModel(new UserObject()) {Age = 123, Name = "Old"}; UserModel result; using (Utility.WithEmptyDirectory(out path)) { using (var fixture = new TPersistentBlobCache(path)) { fixture.InsertObject("key", input); } sched.Start(); using (var fixture = new TPersistentBlobCache(path)) { var action = fixture.GetObjectAsync<UserModel>("key"); sched.Start(); result = action.First(); } } Assert.Equal(input.Age, result.Age); Assert.Equal(input.Name, result.Name); }); }