static (IDisposable, WeakReference) GetWeakReference() { var vm = new InteractionBindViewModel(); var view = new InteractionBindView { ViewModel = vm }; var weakRef = new WeakReference(vm); var disposable = view.BindInteraction( vm, vm => vm.Interaction1, input => { input.SetOutput(true); return(Task.CompletedTask); }); view.ViewModel = new InteractionBindViewModel(); return(disposable, weakRef); }
public void ShouldUnregisterObservableHandlerWhenBindingIsDisposed() { var vm = new InteractionBindViewModel(); var view = new InteractionBindView { ViewModel = vm }; var disposable = view.BindInteraction( vm, vm => vm.Interaction1, input => { input.SetOutput(true); return(Observable.Return(Unit.Default)); }); disposable.Dispose(); _ = Assert.ThrowsAsync <UnhandledInteractionException <string, bool> >(() => vm.Interaction1.Handle("123").ToTask()); }
public async Task ShouldReceiveOutputFromObservableHandler() { var vm = new InteractionBindViewModel(); var view = new InteractionBindView { ViewModel = vm }; var disposable = view.BindInteraction( vm, vm => vm.Interaction1, input => { input.SetOutput(true); return(Observable.Return(Unit.Default)); }); bool isDeletionConfirmed = await vm.Interaction1.Handle("123"); isDeletionConfirmed.Should().BeTrue(); }
public void ShouldUnregisterTaskHandlerFromOverwrittenViewModel() { var vm = new InteractionBindViewModel(); var view = new InteractionBindView { ViewModel = vm }; var disposable = view.BindInteraction( vm, vm => vm.Interaction1, input => { input.SetOutput(true); return(Task.CompletedTask); }); view.ViewModel = new InteractionBindViewModel(); _ = Assert.ThrowsAsync <UnhandledInteractionException <string, bool> >(() => vm.Interaction1.Handle("123").ToTask()); }
public async Task ReceiveOutputFromTaskHandler() { var vm = new InteractionBindViewModel(); var view = new InteractionBindView { ViewModel = vm }; var disposable = view.BindInteraction( vm, vm => vm.Interaction1, input => { input.SetOutput(true); return(Task.CompletedTask); }); bool isDeletionConfirmed = await vm.Interaction1.Handle("123"); isDeletionConfirmed.Should().BeTrue(); }
public void ShouldUnregisterObservableHandlerFromOverwrittenNestedViewModel() { var firstInteractionVm = new InteractionBindViewModel(); var vm = new InteractionAncestorViewModel(); var view = new InteractionAncestorView { ViewModel = vm }; var disposable = view.BindInteraction( vm, vm => vm.InteractionViewModel.Interaction1, input => { input.SetOutput(true); return(Observable.Return(Unit.Default)); }); view.ViewModel.InteractionViewModel = new InteractionBindViewModel(); _ = Assert.ThrowsAsync <UnhandledInteractionException <string, bool> >(() => firstInteractionVm.Interaction1.Handle("123").ToTask()); }
public async Task ShouldRegisterTaskHandlerToNewlyAssignedViewModel() { var vm = new InteractionBindViewModel(); var view = new InteractionBindView { ViewModel = vm }; var disp = view.BindInteraction( vm, vm => vm.Interaction1, input => { input.SetOutput(true); return(Task.CompletedTask); }); view.ViewModel = new InteractionBindViewModel(); bool isDeletionConfirmed = await view.ViewModel.Interaction1.Handle("123"); isDeletionConfirmed.Should().BeTrue(); }
public async Task RegisterObservableHandlerToNewlyAssignedViewModel() { var vm = new InteractionBindViewModel(); var view = new InteractionBindView { ViewModel = vm }; var disposable = view.BindInteraction( vm, vm => vm.Interaction1, input => { input.SetOutput(true); return(Observable.Return(Unit.Default)); }); view.ViewModel = new InteractionBindViewModel(); var isDeletionConfirmed = await view.ViewModel.Interaction1.Handle("123"); isDeletionConfirmed.Should().BeTrue(); }