public void ProviderShouldCallOnNavigatingFromMethod()
        {
            bool isCancelInvoked      = false;
            bool isNavigatedInvoked   = false;
            const NavigationMode mode = NavigationMode.Refresh;

            ViewPageMappingProvider.FindMappingForView = (type, b) => PageMapping;
            NavigationProvider.CurrentViewModel.ShouldBeNull();
            var viewModel = GetViewModel <NavigableViewModelMock>();

            NavigationService.OnNavigated(new NavigationEventArgsMock(new ViewMock {
                DataContext = viewModel
            }, NavigationMode.New));

            viewModel.OnNavigatingFromDelegate = context =>
            {
                isCancelInvoked = true;
                context.NavigationProvider.ShouldEqual(NavigationProvider);
                context.NavigationMode.ShouldEqual(mode);
                return(ToolkitExtensions.FromResult(false));
            };
            viewModel.OnNavigatedFromDelegate = context => isNavigatedInvoked = true;

            var cancelArgs = new NavigatingCancelEventArgsMock(mode, true)
            {
                Cancel = false
            };

            NavigationService.OnNavigating(cancelArgs);
            cancelArgs.Cancel.ShouldBeTrue();
            isCancelInvoked.ShouldBeTrue();
            isNavigatedInvoked.ShouldBeFalse();
        }
示例#2
0
        public Task <MessageResult> ShowAsync(string messageBoxText, string caption = "",
                                              MessageButton button        = MessageButton.Ok, MessageImage icon      = MessageImage.None,
                                              MessageResult defaultResult = MessageResult.None, IDataContext context = null)
        {
            bool             success;
            MessageBoxButton buttons = ConvertMessageBoxButtons(button, out success);

            Should.BeSupported(success, "The MessageBoxAdapter doesn't support {0} value", button);

            if (_threadManager.IsUiThread)
            {
                MessageBoxResult result = MessageBox.Show(messageBoxText, caption, buttons,
                                                          ConvertMessageBoxImages(icon),
                                                          ConvertMessageBoxResults(defaultResult));
                return(ToolkitExtensions.FromResult(ConvertMessageBoxResult(result)));
            }
            var tcs = new TaskCompletionSource <MessageResult>();

            _threadManager.InvokeOnUiThreadAsync(() =>
            {
                MessageBoxResult result = MessageBox.Show(messageBoxText, caption, buttons,
                                                          ConvertMessageBoxImages(icon), ConvertMessageBoxResults(defaultResult));
                tcs.SetResult(ConvertMessageBoxResult(result));
            });
            return(tcs.Task);
        }
        public virtual void MediatorShouldCallOnNavigatingFromMethodOnClose()
        {
            bool result    = false;
            bool isInvoked = false;
            var  view      = new DialogViewMock();
            var  vm        = GetViewModel <NavigableViewModelMock>();

            ViewManager.GetViewDelegate = (model, s) => view;
            WindowViewMediatorBase <TView> windowMediator = Create(vm);

            vm.OnNavigatingFromDelegate = o =>
            {
                o.ShouldNotBeNull();
                isInvoked = true;
                return(ToolkitExtensions.FromResult(result));
            };
            windowMediator.ShowAsync(null, DataContext.Empty);
            windowMediator.CloseAsync(null).Result.ShouldBeFalse();
            isInvoked.ShouldBeTrue();

            isInvoked = false;
            result    = true;
            windowMediator.CloseAsync(null).Result.ShouldBeTrue();
            isInvoked.ShouldBeTrue();
        }
示例#4
0
        public virtual void MediatorShouldCallOnNavigatingOnClose()
        {
            bool result    = false;
            bool isInvoked = false;
            var  view      = new DialogViewMock();
            var  vm        = GetViewModel <NavigableViewModelMock>();

            ViewManager.GetViewDelegate = (model, s) => view;
            WindowViewMediatorBase <TView> windowMediator = Create(vm);

            NavigationDispatcher.OnNavigatingFromAsync = context =>
            {
                isInvoked = true;
                context.ShouldNotBeNull();
                context.NavigationMode.ShouldEqual(NavigationMode.Back);
                context.NavigationType.ShouldEqual(NavigationType.Window);
                context.ViewModelFrom.ShouldEqual(vm);
                return(ToolkitExtensions.FromResult(result));
            };
            windowMediator.ShowAsync(DataContext.Empty);
            windowMediator.CloseAsync(null).Result.ShouldBeFalse();
            isInvoked.ShouldBeTrue();

            isInvoked = false;
            result    = true;
            windowMediator.CloseAsync(null).Result.ShouldBeTrue();
            isInvoked.ShouldBeTrue();
        }
 Task <object> IViewManager.GetViewAsync(IViewModel viewModel, IDataContext dataContext)
 {
     if (GetViewRawDelegate == null)
     {
         return(ToolkitExtensions.FromResult(GetViewDelegate(viewModel, dataContext.GetData(InitializationConstants.ViewName))));
     }
     return(ToolkitExtensions.FromResult(GetViewRawDelegate(viewModel, dataContext)));
 }
示例#6
0
 static Empty()
 {
     TrueObject                           = true;
     FalseObject                          = false;
     WeakReference                        = new WeakReference(null, false);
     TrueTask                             = ToolkitExtensions.FromResult(true);
     FalseTask                            = ToolkitExtensions.FromResult(false);
     Task                                 = FalseTask;
     CountPropertyChangedArgs             = new PropertyChangedEventArgs("Count");
     NotificationCountPropertyChangedArgs = new PropertyChangedEventArgs("NotificationCount");
     IndexerPropertyChangedArgs           = new PropertyChangedEventArgs("Item[]");
 }
示例#7
0
        public Task <MessageResult> ShowAsync(string messageBoxText, string caption = "",
                                              MessageButton button        = MessageButton.Ok, MessageImage icon      = MessageImage.None,
                                              MessageResult defaultResult = MessageResult.None, IDataContext context = null)
        {
            if (_threadManager.IsUiThread)
            {
                return(ToolkitExtensions.FromResult(ShowMessage(messageBoxText, caption, button, icon, defaultResult)));
            }
            var tcs = new TaskCompletionSource <MessageResult>();

            _threadManager.InvokeOnUiThreadAsync(
                () => tcs.SetResult(ShowMessage(messageBoxText, caption, button, icon, defaultResult)));
            return(tcs.Task);
        }
示例#8
0
 static Empty()
 {
     CompletedEvent                      = new ManualResetEvent(true);
     TrueObject                          = true;
     FalseObject                         = false;
     WeakReference                       = new WeakReference(null, false);
     TrueTask                            = ToolkitExtensions.FromResult(true);
     FalseTask                           = ToolkitExtensions.FromResult(false);
     Task                                = FalseTask;
     EmptyDataErrorsChangedArgs          = new DataErrorsChangedEventArgs(string.Empty);
     EmptyPropertyChangedArgs            = new PropertyChangedEventArgs(string.Empty);
     CountChangedArgs                    = new PropertyChangedEventArgs("Count");
     NotificationCountChangedArgs        = new PropertyChangedEventArgs("NotificationCount");
     IndexerPropertyChangedArgs          = new PropertyChangedEventArgs(ReflectionExtensions.IndexerName);
     IsNotificationsSuspendedChangedArgs = new PropertyChangedEventArgs("IsNotificationsSuspended");
     HasChangesChangedArgs               = new PropertyChangedEventArgs("HasChanges");
     SelectedItemChangedArgs             = new PropertyChangedEventArgs("SelectedItem");
     HasErrorsChangedArgs                = new PropertyChangedEventArgs("HasErrors");
     IsValidChangedArgs                  = new PropertyChangedEventArgs("IsValid");
     IsBusyChangedArgs                   = new PropertyChangedEventArgs("IsBusy");
     BusyMessageChangedArgs              = new PropertyChangedEventArgs("BusyMessage");
 }
示例#9
0
 static Empty()
 {
     CompletedEvent                      = new ManualResetEvent(true);
     TrueObject                          = true;
     FalseObject                         = false;
     WeakReference                       = new WeakReference(null, false);
     TrueTask                            = ToolkitExtensions.FromResult(true);
     FalseTask                           = ToolkitExtensions.FromResult(false);
     Task                                = FalseTask;
     EmptyDataErrorsChangedArgs          = new DataErrorsChangedEventArgs(string.Empty);
     EmptyPropertyChangedArgs            = new PropertyChangedEventArgs(string.Empty);
     CountChangedArgs                    = new PropertyChangedEventArgs(nameof(ICollection.Count));
     IndexerPropertyChangedArgs          = new PropertyChangedEventArgs(ReflectionExtensions.IndexerName);
     IsNotificationsSuspendedChangedArgs = new PropertyChangedEventArgs(nameof(ISuspendNotifications.IsNotificationsSuspended));
     HasChangesChangedArgs               = new PropertyChangedEventArgs(nameof(IEditableViewModel.HasChanges));
     SelectedItemChangedArgs             = new PropertyChangedEventArgs(nameof(IGridViewModel.SelectedItem));
     HasErrorsChangedArgs                = new PropertyChangedEventArgs(nameof(IValidatableViewModel.HasErrors));
     IsValidChangedArgs                  = new PropertyChangedEventArgs(nameof(IValidatableViewModel.IsValid));
     IsBusyChangedArgs                   = new PropertyChangedEventArgs(nameof(IViewModel.IsBusy));
     BusyMessageChangedArgs              = new PropertyChangedEventArgs(nameof(IViewModel.BusyMessage));
     BusyInfoChangedArgs                 = new PropertyChangedEventArgs(nameof(IViewModel.BusyInfo));
     ResetEventArgs                      = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset);
 }
示例#10
0
 protected static Task <IDictionary <string, IEnumerable> > FromResult(IDictionary <string, IEnumerable> result)
 {
     return(ToolkitExtensions.FromResult(result));
 }