Inheritance: BindableBase, INavigationAware
        public void WhenAskedCanNavigateForDifferentQuery_ThenReturnsFalse()
        {
            var email = new EmailDocument();

            var emailServiceMock = new Mock<IEmailService>();
            emailServiceMock
                .Setup(svc => svc.GetEmailDocument(email.Id))
               .Returns(email)
               .Verifiable();

            var viewModel = new EmailViewModel(emailServiceMock.Object);

            NavigationContext context = new NavigationContext(new Mock<IRegionNavigationService>().Object, new Uri("location", UriKind.Relative));
            context.Parameters.Add("EmailId", email.Id);
            
            ((INavigationAware)viewModel).OnNavigatedTo(context);

            context = new NavigationContext(new Mock<IRegionNavigationService>().Object, new Uri("location", UriKind.Relative));
            context.Parameters.Add("EmailId", new Guid());

            bool canNavigate =
                ((INavigationAware)viewModel).IsNavigationTarget(context);

            Assert.IsFalse(canNavigate);
        }
        public void WhenAskedCanNavigateForDifferentQuery_ThenReturnsFalse()
        {
            var email = new EmailDocument();

            var emailServiceMock = new Mock<IEmailService>();
            emailServiceMock
                .Setup(svc => svc.GetEmailDocument(email.Id))
               .Returns(email)
               .Verifiable();

            var viewModel = new EmailViewModel(emailServiceMock.Object);

            ((INavigationAware)viewModel).OnNavigatedTo(new NavigationContext(new Mock<IRegionNavigationService>().Object, new Uri("location?EmailId=" + email.Id.ToString("N"), UriKind.Relative)));

            bool canNavigate =
                ((INavigationAware)viewModel).IsNavigationTarget(new NavigationContext(new Mock<IRegionNavigationService>().Object, new Uri("location?EmailId=" + Guid.NewGuid().ToString("N"), UriKind.Relative)));

            Assert.IsFalse(canNavigate);
        }
        public void WhenNavigatedTo_ThenRequestsEmailFromService()
        {
            var email = new EmailDocument();

            var emailServiceMock = new Mock<IEmailService>();
            emailServiceMock
                .Setup(svc => svc.GetEmailDocument(email.Id))
               .Returns(email)
               .Verifiable();

            var viewModel = new EmailViewModel(emailServiceMock.Object);

            var notified = false;
            viewModel.PropertyChanged += (s, o) => notified = o.PropertyName == "Email";
            ((INavigationAware)viewModel).OnNavigatedTo(
                new NavigationContext(
                    new Mock<IRegionNavigationService>().Object,
                    new Uri("location?EmailId=" + email.Id.ToString("N"), UriKind.Relative)));

            Assert.IsTrue(notified);
            emailServiceMock.VerifyAll();
        }
        public void WhenGoingBack_ThenNavigatesBack()
        {
            var emailServiceMock = new Mock<IEmailService>();

            var viewModel = new EmailViewModel(emailServiceMock.Object);

            var journalMock = new Mock<IRegionNavigationJournal>();

            var navigationServiceMock = new Mock<IRegionNavigationService>();
            navigationServiceMock.SetupGet(svc => svc.Journal).Returns(journalMock.Object);

            NavigationContext context = new NavigationContext(navigationServiceMock.Object, new Uri("location", UriKind.Relative));
            context.Parameters.Add("EmailId", Guid.NewGuid());

            ((INavigationAware)viewModel).OnNavigatedTo(context);

            viewModel.GoBackCommand.Execute(null);

            journalMock.Verify(j => j.GoBack());
        }