public void errors_saving_data_are_surfaced() { var api = new ApiMockBuilder() .WithSaveDinosaur(new InvalidOperationException("foo")) .Build(); var sut = new DinosaurDetailsViewModelBuilder() .WithTestScheduler(out var scheduler) .WithApi(api) .Build(); sut.Name = "Barney"; scheduler.AdvanceByMs(2001); Assert.NotNull(sut.Error); Assert.Equal("foo", sut.Error.Exception.Message); api .When(x => x.SaveDinosaur(It.IsAny <Dinosaur>())) .Return(Observable.Return(Unit.Default)); sut .Error .RetryCommand .Execute(null); scheduler.AdvanceByMs(1); Assert.Null(sut.Error); }
public void errors_deleting_data_are_surfaced() { var api = new ApiMockBuilder() .WithDeleteDinosaur(new InvalidOperationException("foo")) .Build(); var sut = new DinosaurDetailsViewModelBuilder() .WithApi(api) .WithConfirmDeleteInteraction(true) .Build(); sut .DeleteCommand .Execute() .Subscribe( _ => { }, _ => { }); Assert.NotNull(sut.Error); Assert.Equal("foo", sut.Error.Exception.Message); api .When(x => x.DeleteDinosaur(It.IsAny <int>())) .Return(Observable.Return(Unit.Default)); sut .Error .RetryCommand .Execute(null); Assert.Null(sut.Error); }
public void errors_retrieving_data_are_surfaced() { var api = new ApiMockBuilder() .WithGetDinosaur(new InvalidOperationException("foo")) .Build(); var sut = new DinosaurDetailsViewModelBuilder() .WithApi(api) .Build(); Assert.NotNull(sut.Error); Assert.Equal("foo", sut.Error.Exception.Message); api .When(x => x.GetDinosaur(It.IsAny <int>())) .Return(Observable.Return(default(Dinosaur))); sut .Error .RetryCommand .Execute(null); Assert.Null(sut.Error); }
public void memory_is_reclaimed_after_deactivation() { // // IMPORTANT: if you're observing failures in this test, try running it in release mode without a debugger attached. // // The SUT will subscribe to this subject, so we hold a reference to it so that it can't be GC'd. var isAuditingAvailable = new Subject <bool>(); var api = new ApiMockBuilder() .WithIsAuditingAvailable(isAuditingAvailable) .Build(); var sut = new DinosaurDetailsViewModelBuilder() .WithApi( new ApiMockBuilder() .WithIsAuditingAvailable(isAuditingAvailable) .Build()) .Build(); var weakSut = new WeakReference(sut); sut = null; GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); Assert.True(weakSut.IsAlive); // Deactivation is when the SUT should detach subscriptions and therefore become eligible for collection. ((DinosaurDetailsViewModel)weakSut.Target) .Activator .Deactivate(); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); Assert.False(weakSut.IsAlive); }