コード例 #1
0
        public void DispatcherShouldNotifyAboutNavigatedCallback()
        {
            var navigationDispatcher = CreateNavigationDispatcher();
            var vmFrom = GetViewModel <NavigableViewModelMock>();
            var vmTo   = GetViewModel <NavigableViewModelMock>();

            IOperationResult result = null;

            OperationCallbackManager.SetResult = (o, r) =>
            {
                result.ShouldBeNull();
                result = r;
            };

            Action <INavigationContext> fromAssert = navContext =>
            {
                result.OperationContext.ShouldEqual(navContext);
                result.Source.ShouldEqual(vmFrom);
                result.IsCanceled.ShouldBeFalse();
                result.IsFaulted.ShouldBeFalse();
            };
            Action <INavigationContext> toAssert = navContext =>
            {
                result.ShouldBeNull();
            };

            var tuples = new List <Tuple <NavigationMode, Action <INavigationContext> > >
            {
                Tuple.Create(NavigationMode.Back, fromAssert),
                Tuple.Create(NavigationMode.Remove, fromAssert),
                Tuple.Create(NavigationMode.New, toAssert),
                Tuple.Create(NavigationMode.Refresh, toAssert),
                Tuple.Create(NavigationMode.Undefined, toAssert)
            };

            foreach (var tuple in tuples)
            {
                result = null;
                var ctx = new NavigationContext(NavigationType.Page, tuple.Item1, vmFrom, vmTo, this);
                navigationDispatcher.OnNavigated(ctx);
                tuple.Item2(ctx);
            }
        }