Inheritance: ViewSwitchingNavigation.Contacts.ViewModels.ContactsViewModel
示例#1
0
        public void WhenContactIsSelected_ThenEmailContactCommandIsEnabledAndNotifiesChange()
        {
            var           contactsServiceMock = new Mock <IContactsService>();
            AsyncCallback callback            = null;
            var           resultMock          = new Mock <IAsyncResult>();

            contactsServiceMock
            .Setup(svc => svc.BeginGetContacts(It.IsAny <AsyncCallback>(), null))
            .Callback <AsyncCallback, object>((cb, s) => callback = cb)
            .Returns(resultMock.Object);
            var contacts = new[] { new Contact {
                                   }, new Contact {
                                   } };

            contactsServiceMock
            .Setup(svc => svc.EndGetContacts(resultMock.Object))
            .Returns(contacts);

            var regionManager = new RegionManager();

            var viewModel = new TestContactsViewModel(contactsServiceMock.Object, regionManager, contacts);

            var notified = false;

            viewModel.EmailContactCommand.CanExecuteChanged += (s, o) => notified = true;
            Assert.IsFalse(viewModel.EmailContactCommand.CanExecute(null));
            viewModel.Contacts.MoveCurrentToFirst();
            Assert.IsTrue(viewModel.EmailContactCommand.CanExecute(null));
            Assert.IsTrue(notified);
        }
        public void WhenContactIsSelected_ThenEmailContactCommandIsEnabledAndNotifiesChange()
        {
            var                   contactsServiceMock = new Mock <IContactsService>();
            AsyncCallback         callback            = null;
            var                   resultMock          = new Mock <IAsyncResult>();
            IEnumerable <Contact> contacts            = new[] { new Contact {
                                                                }, new Contact {
                                                                } };

            contactsServiceMock
            .Setup(svc => svc.GetContactsAsync())
            .Returns(Task.FromResult(contacts));

            var regionManager = new RegionManager();

            var viewModel = new TestContactsViewModel(contactsServiceMock.Object, regionManager, contacts.ToArray());

            var notified = false;

            viewModel.EmailContactCommand.CanExecuteChanged += (s, o) => notified = true;
            Assert.IsFalse(viewModel.EmailContactCommand.CanExecute(null));
            viewModel.Contacts.MoveCurrentToFirst();
            Assert.IsTrue(viewModel.EmailContactCommand.CanExecute(null));
            Assert.IsTrue(notified);
        }
        public void WhenSendingEmail_ThenNavigatesWithAToQueryParameter()
        {
            var           contactsServiceMock = new Mock <IContactsService>();
            AsyncCallback callback            = null;
            var           resultMock          = new Mock <IAsyncResult>();
            var           contacts            = new[] { new Contact {
                                                            EmailAddress = "email"
                                                        }, new Contact {
                                                        } };

            contactsServiceMock
            .Setup(svc => svc.GetContactsAsync())
            .Returns(Task.FromResult(contacts.AsEnumerable()));

            Mock <IRegionManager> regionManagerMock = new Mock <IRegionManager>();

            regionManagerMock.Setup(x => x.RequestNavigate(RegionNames.MainContentRegion, @"ComposeEmailView?To=email"))
            .Verifiable();

            IRegionManager regionManager = regionManagerMock.Object;

            var viewModel = new TestContactsViewModel(contactsServiceMock.Object, regionManager, contacts);

            viewModel.Contacts.MoveCurrentToFirst();

            viewModel.EmailContactCommand.Execute(null);

            regionManagerMock.VerifyAll();
        }
        public void WhenSendingEmail_ThenNavigatesWithAToQueryParameter()
        {
            var contactsServiceMock = new Mock<IContactsService>();
            AsyncCallback callback = null;
            var resultMock = new Mock<IAsyncResult>();
            contactsServiceMock
                .Setup(svc => svc.BeginGetContacts(It.IsAny<AsyncCallback>(), null))
                .Callback<AsyncCallback, object>((cb, s) => callback = cb)
                .Returns(resultMock.Object);
            var contacts = new[] { new Contact { EmailAddress = "email" }, new Contact { } };
            contactsServiceMock
                .Setup(svc => svc.EndGetContacts(resultMock.Object))
                .Returns(contacts);

            Mock<IRegion> regionMock = new Mock<IRegion>();
            regionMock
                .Setup(x => x.RequestNavigate(new Uri("ComposeEmailView?To=email", UriKind.Relative), It.IsAny<Action<NavigationResult>>()))
                .Callback<Uri, Action<NavigationResult>>((s, c) => c(new NavigationResult(null, true)))
                .Verifiable();

            Mock<IRegionManager> regionManagerMock = new Mock<IRegionManager>();
            regionManagerMock.Setup(x => x.Regions.ContainsRegionWithName(RegionNames.MainContentRegion)).Returns(true);
            regionManagerMock.Setup(x => x.Regions[RegionNames.MainContentRegion]).Returns(regionMock.Object);

            IRegionManager regionManager = regionManagerMock.Object;

            var viewModel = new TestContactsViewModel(contactsServiceMock.Object, regionManager, contacts);

            viewModel.Contacts.MoveCurrentToFirst();

            viewModel.EmailContactCommand.Execute(null);

            regionMock.VerifyAll();
        }
        public void WhenContactIsSelected_ThenEmailContactCommandIsEnabledAndNotifiesChange()
        {
            var contactsServiceMock = new Mock<IContactsService>();
            AsyncCallback callback = null;
            var resultMock = new Mock<IAsyncResult>();
            contactsServiceMock
                .Setup(svc => svc.BeginGetContacts(It.IsAny<AsyncCallback>(), null))
                .Callback<AsyncCallback, object>((cb, s) => callback = cb)
                .Returns(resultMock.Object);
            var contacts = new[] { new Contact { }, new Contact { } };
            contactsServiceMock
                .Setup(svc => svc.EndGetContacts(resultMock.Object))
                .Returns(contacts);

            var regionManager = new RegionManager();

            var viewModel = new TestContactsViewModel(contactsServiceMock.Object, regionManager, contacts);

            var notified = false;
            viewModel.EmailContactCommand.CanExecuteChanged += (s, o) => notified = true;
            Assert.IsFalse(viewModel.EmailContactCommand.CanExecute(null));
            viewModel.Contacts.MoveCurrentToFirst();
            Assert.IsTrue(viewModel.EmailContactCommand.CanExecute(null));
            Assert.IsTrue(notified);
        }
        public void WhenSendingEmail_ThenNavigatesWithAToQueryParameter()
        {
            var contactsServiceMock = new Mock<IContactsService>();
            var contacts = new[] { new Contact { EmailAddress = "email" }, new Contact { } };

            contactsServiceMock
                .Setup(svc => svc.GetContactsAsync())
                .ReturnsAsync(contacts);

            //Mock<IRegion> regionMock = new Mock<IRegion>();
            //regionMock
            //    .Setup(x => x.RequestNavigate(new Uri("ComposeEmailView?To=email", UriKind.Relative), It.IsAny<Action<NavigationResult>>()))
            //    .Callback<Uri, Action<NavigationResult>>((s, c) => c(new NavigationResult(null, true)))
            //    .Verifiable();

            Mock<IRegionManager> regionManagerMock = new Mock<IRegionManager>();
            regionManagerMock.Setup(x => x.RequestNavigate(RegionNames.MainContentRegion, @"ComposeEmailView?To=email"))
                .Verifiable();

            IRegionManager regionManager = regionManagerMock.Object;

            var viewModel = new TestContactsViewModel(contactsServiceMock.Object, regionManager, contacts);

            viewModel.Contacts.MoveCurrentToFirst();

            viewModel.EmailContactCommand.Execute(null);

            regionManagerMock.VerifyAll();
        }
        public void WhenContactIsSelected_ThenEmailContactCommandIsEnabledAndNotifiesChange()
        {
            var contactsServiceMock = new Mock<IContactsService>();
            var contacts = new[] { new Contact { }, new Contact { } };

            contactsServiceMock
                .Setup(svc => svc.GetContactsAsync())
                .ReturnsAsync(contacts);

            var regionManager = new RegionManager();

            var viewModel = new TestContactsViewModel(contactsServiceMock.Object, regionManager, contacts);

            var notified = false;
            viewModel.EmailContactCommand.CanExecuteChanged += (s, o) => notified = true;
            Assert.IsFalse(viewModel.EmailContactCommand.CanExecute(null));
            viewModel.Contacts.MoveCurrentToFirst();
            Assert.IsTrue(viewModel.EmailContactCommand.CanExecute(null));
            Assert.IsTrue(notified);
        }
示例#8
0
        public void WhenSendingEmail_ThenNavigatesWithAToQueryParameter()
        {
            var           contactsServiceMock = new Mock <IContactsService>();
            AsyncCallback callback            = null;
            var           resultMock          = new Mock <IAsyncResult>();

            contactsServiceMock
            .Setup(svc => svc.BeginGetContacts(It.IsAny <AsyncCallback>(), null))
            .Callback <AsyncCallback, object>((cb, s) => callback = cb)
            .Returns(resultMock.Object);
            var contacts = new[] { new Contact {
                                       EmailAddress = "email"
                                   }, new Contact {
                                   } };

            contactsServiceMock
            .Setup(svc => svc.EndGetContacts(resultMock.Object))
            .Returns(contacts);

            Mock <IRegion> regionMock = new Mock <IRegion>();

            regionMock
            .Setup(x => x.RequestNavigate(new Uri("ComposeEmailView?To=email", UriKind.Relative), It.IsAny <Action <NavigationResult> >()))
            .Callback <Uri, Action <NavigationResult> >((s, c) => c(new NavigationResult(null, true)))
            .Verifiable();

            Mock <IRegionManager> regionManagerMock = new Mock <IRegionManager>();

            regionManagerMock.Setup(x => x.Regions.ContainsRegionWithName(RegionNames.MainContentRegion)).Returns(true);
            regionManagerMock.Setup(x => x.Regions[RegionNames.MainContentRegion]).Returns(regionMock.Object);

            IRegionManager regionManager = regionManagerMock.Object;

            var viewModel = new TestContactsViewModel(contactsServiceMock.Object, regionManager, contacts);

            viewModel.Contacts.MoveCurrentToFirst();

            viewModel.EmailContactCommand.Execute(null);

            regionMock.VerifyAll();
        }
        public void WhenSendingEmail_ThenNavigatesWithAToQueryParameter()
        {
            var contactsServiceMock = new Mock<IContactsService>();
            var resultMock = new Mock<IAsyncResult>();
            var contacts = new[] { new Contact { EmailAddress = "email" }, new Contact { } };
            contactsServiceMock
                .Setup(svc => svc.GetContactsAsync())
                .Returns(Task.FromResult(contacts.AsEnumerable()));

            Mock<IRegionManager> regionManagerMock = new Mock<IRegionManager>();
            regionManagerMock.Setup(x => x.RequestNavigate(RegionNames.MainContentRegion, @"ComposeEmailView?To=email"))
                .Verifiable();

            IRegionManager regionManager = regionManagerMock.Object;

            var viewModel = new TestContactsViewModel(contactsServiceMock.Object, regionManager, contacts);

            viewModel.Contacts.MoveCurrentToFirst();

            viewModel.EmailContactCommand.Execute(null);

            regionManagerMock.VerifyAll();
        }