public void programs_is_populated_from_cloud_if_cache_errors_and_cloud_is_populated() { var document = "# First Program"; var stateService = new StateServiceMock(); var scheduler = new TestScheduler(); stateService .When(x => x.Get<string>(It.IsAny<string>())) .Return(Observable.Throw<string>(new InvalidOperationException())); stateService .When(x => x.Set<string>(It.IsAny<string>(), It.IsAny<string>())) .Return(Observable.Return(Unit.Default)); var sut = new ExerciseProgramsViewModelBuilder() .WithCloudDocument(document) .WithScheduler(scheduler) .WithStateService(stateService) .Build(); scheduler.AdvanceMinimal(); Assert.NotNull(sut.Programs); Assert.Equal(1, sut.Programs.Count); }
public void document_is_not_stored_in_cache_if_loaded_from_cache() { var document = "# First Program"; var scheduler = new TestScheduler(); var stateService = new StateServiceMock(); stateService .When(x => x.Get<string>(It.IsAny<string>())) .Return(Observable.Return(document)); stateService .When(x => x.Set<string>(It.IsAny<string>(), It.IsAny<string>())) .Return(Observable.Return(Unit.Default)); var sut = new ExerciseProgramsViewModelBuilder() .WithScheduler(scheduler) .WithStateService(stateService) .Build(); scheduler.AdvanceMinimal(); Assert.Equal(ExerciseProgramsViewModelStatus.LoadedFromCache, sut.Status); stateService .Verify(x => x.Set<string>("ExerciseProgramsDocument", document)) .WasNotCalled(); }
public ExerciseProgramsViewModelBuilder WithCachedDocument(string cachedDocument) { var stateService = new StateServiceMock(MockBehavior.Loose); stateService .When(x => x.GetAsync<string>(It.IsAny<string>())) .Return(Observable.Return(cachedDocument)); stateService .When(x => x.SetAsync<string>(It.IsAny<string>(), It.IsAny<string>())) .Return(Observable.Return(Unit.Default)); return this.WithStateService(stateService); }