Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am not able to mock the navigationcontext using moq framework.
Can anyone help on this

Constructor
--------------
 public CreateQuestionsViewModel(IEventAggregator eventAggregator, IUnityContainer unityContainer)
            : base(eventAggregator, unityContainer)
        {
            FrameWorkManager.Log(DisplayMessages.msgBoxInitrCreateViewModelLog);
            Initialize();
        }

Method
---------
 public override void OnNavigatedTo(NavigationContext navigationContext)
        {
            try
            {
                using (new WaitCursor())
                {
                    if (navigationContext.NavigationService.Region.Context != null)
                    {
                        if (navigationContext.NavigationService.Region.Context is QuestionDTO question)
                        {
                            if (navigationContext.Parameters[Constants.ISUSEREDITING_QUESTION] != null)
                            {
                                _IsQuestionEditing = (bool)navigationContext.Parameters[Constants.ISUSEREDITING_QUESTION];
                            }
                            if (navigationContext.Parameters[Constants.ISUSERCLONING_QUESTION] != null)
                            {
                                _IsQuestionCloning = (bool)navigationContext.Parameters[Constants.ISUSERCLONING_QUESTION];
                                CloneQuestionCommand.RaiseCanExecuteChanged();
                            }
                            LoadQuestionForCloningOrEditing(question);
                        }
                        EnableDisableSavePreviewButtons();
                    }
                    else
                        _AddNewQuestionInstance = true;

                }
            }
            catch (Exception ex)
            {
                FrameWorkManager.PublishException(ex);
                MessageBoxService.Show(DisplayMessages.strErrorLoadingQuestion, DisplayMessages.msgBoxErrorCaption, DXMVVM.MessageButton.OK, DXMVVM.MessageIcon.Error, DXMVVM.MessageResult.OK);

            }
        }

Below are the other methods name inside the viewmodel
public override void OnNavigatedFrom(NavigationContext navigationContext)

public override void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)


What I have tried:

I tried with moq framework for writing the unit test methods
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900