public async Task AutoWireViewModel_With_Custom_Resolver_And_Factory()
        {
            await ExecuteOnUIThread(() =>
            {
                var page = new MockPage();

                // Set the ViewTypeToViewModelTypeResolver
                ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver((viewType) =>
                {
                    var viewName = viewType.FullName;

                    // The ViewModel is in the same namespace as the View
                    var viewModelName = String.Format("{0}ViewModel", viewName);
                    return Type.GetType(viewModelName);
                });

                // Set the ViewTypeToViewModelTypeResolver
                ViewModelLocationProvider.SetDefaultViewModelFactory((viewModelType) =>
                {
                    // The ViewModel has a constructor with no parameters
                    return Activator.CreateInstance(viewModelType) as ViewModelBase;
                });

                // Fire AutoWireViewModelChanged
                ViewModelLocator.SetAutoWireViewModel(page, true);

                Assert.IsNotNull(page.DataContext);
                Assert.IsInstanceOfType(page.DataContext, typeof(MockPageViewModel));
            });
        }
        public async Task AutoWireViewModel_With_Factory_Registration()
        {
            await ExecuteOnUIThread(() =>
            {
                var page = new MockPage();

                // Register the ViewModel to the page
                ViewModelLocationProvider.Register(typeof(MockPage).ToString(), () => new MockPageViewModel());

                // Fire AutoWireViewModelChanged
                ViewModelLocator.SetAutoWireViewModel(page, true);

                Assert.IsNotNull(page.DataContext);
                Assert.IsInstanceOfType(page.DataContext, typeof(MockPageViewModel));
            });
        }
        public async Task AutoWireViewModel_With_Custom_Resolver()
        {
            await DispatcherHelper.ExecuteOnUIThread(() =>
            {
                var page = new MockPage();

                // Set the ViewTypeToViewModelTypeResolver
                ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver((viewType) =>
                {
                    var viewName = viewType.FullName;

                    // The ViewModel is in the same namespace as the View
                    var viewModelName = String.Format("{0}ViewModel", viewName);
                    return Type.GetType(viewModelName);
                });

                // Fire AutoWireViewModelChanged
                ViewModelLocator.SetAutoWireViewModel(page, true);

                Assert.IsNotNull(page.DataContext);
                Assert.IsInstanceOfType(page.DataContext, typeof(MockPageViewModel));
            });
        }
        public async Task NavigateFromCurrentViewModel_Calls_VieModel_OnNavigatedFrom()
        {
            await ExecuteOnUIThread(() =>
            {
                var frame = new FrameFacadeAdapter(new Frame());

                bool viewModelNavigatedFromCalled = false;
                var viewModel = new MockPageViewModel();
                viewModel.OnNavigatedFromCommand = (frameState, suspending) =>
                {
                    Assert.IsFalse(suspending);
                    viewModelNavigatedFromCalled = true;
                };

                var sessionStateService = new MockSessionStateService();
                sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => new Dictionary<string, object>();

                var navigationService = new FrameNavigationService(frame, (pageToken) => typeof(MockPage), sessionStateService);

                // Initial navigatio
                navigationService.Navigate("page0", 0);

                // Set up the frame's content with a Page
                var view = new MockPage();
                view.DataContext = viewModel;
                frame.Content = view;

                // Navigate to fire the NavigatedToCurrentViewModel
                navigationService.Navigate("page1", 1);

                Assert.IsTrue(viewModelNavigatedFromCalled);
            });
        }