Ejemplo n.º 1
0
    private void NavigateToProvider(CloudExplorerView view)
    {
        _listeners?.Dispose();
        _listeners = new CompositeDisposable();

        view.WhenAnyValue(x => x.ViewModel.Auth.IsAuthenticated)
        .Where(authenticated => authenticated)
        .Select(x => new CloudExplorerView {
            ViewModel = ViewModel.SelectedProvider
        })
        .Subscribe(NavigateWithoutBackStack)
        .DisposeWith(_listeners);

        view.WhenAnyValue(x => x.ViewModel.Auth.IsAuthenticated)
        .Where(authenticated => !authenticated)
        .Select(x => new AuthView {
            ViewModel = ViewModel.SelectedProvider.Auth
        })
        .Subscribe(NavigateWithoutBackStack)
        .DisposeWith(_listeners);

        view.WhenAnyValue(x => x.ViewModel.Folder.IsVisible)
        .Where(visible => visible)
        .Select(x => new CreateFolderView {
            ViewModel = ViewModel.SelectedProvider.Folder
        })
        .Subscribe(NavigateWithoutBackStack)
        .DisposeWith(_listeners);

        view.WhenAnyValue(x => x.ViewModel.Folder.IsVisible)
        .Where(visible => !visible)
        .Skip(1)
        .Select(x => new CloudExplorerView {
            ViewModel = ViewModel.SelectedProvider
        })
        .Subscribe(NavigateWithoutBackStack)
        .DisposeWith(_listeners);

        view.WhenAnyValue(x => x.ViewModel.Rename.IsVisible)
        .Where(visible => visible)
        .Select(x => new RenameFileView {
            ViewModel = ViewModel.SelectedProvider.Rename
        })
        .Subscribe(NavigateWithoutBackStack)
        .DisposeWith(_listeners);

        view.WhenAnyValue(x => x.ViewModel.Rename.IsVisible)
        .Where(visible => !visible)
        .Skip(1)
        .Select(x => new CloudExplorerView {
            ViewModel = ViewModel.SelectedProvider
        })
        .Subscribe(NavigateWithoutBackStack)
        .DisposeWith(_listeners);
    }
        public void Constructor_Initializes()
        {
            var fakeCfInstances = new Dictionary <string, CloudFoundryInstance>();

            mockCloudFoundryService.SetupGet(mock => mock.CloudFoundryInstances).Returns(fakeCfInstances);
            var vm   = new CloudExplorerViewModel(services);
            var view = new CloudExplorerView(vm);

            // Verify DataContext initalized
            Assert.AreSame(vm, view.DataContext);

            // Verify commands point to view model
            var openLoginCommand = view.OpenLoginFormCommand as DelegatingCommand;
            var stopAppCommand   = view.StopCfAppCommand as AsyncDelegatingCommand;

            Assert.IsNotNull(openLoginCommand);
            Assert.IsNotNull(stopAppCommand);
            Assert.AreEqual(vm, openLoginCommand.action.Target);
            Assert.AreEqual(vm, stopAppCommand.action.Target);
        }