public void WhenEmailsAreReturned_ThenViewModelIsPopulated() { var asyncResultMock = new Mock<IAsyncResult>(); var emailServiceMock = new Mock<IEmailService>(MockBehavior.Strict); AsyncCallback callback = null; emailServiceMock .Setup(svc => svc.BeginGetEmailDocuments(It.IsAny<AsyncCallback>(), null)) .Callback<AsyncCallback, object>((ac, o) => callback = ac) .Returns(asyncResultMock.Object); var email = new EmailDocument { }; emailServiceMock .Setup(svc => svc.EndGetEmailDocuments(asyncResultMock.Object)) .Returns(new[] { email }); var viewModel = new InboxViewModel(emailServiceMock.Object, new Mock<IRegionManager>().Object); this.EnqueueConditional(() => callback != null); this.EnqueueCallback( () => { callback(asyncResultMock.Object); }); this.EnqueueCallback( () => { CollectionAssert.AreEqual(new[] { email }, viewModel.Messages.Cast<EmailDocument>().ToArray()); emailServiceMock.VerifyAll(); }); this.EnqueueTestComplete(); }
public void WhenCreated_ThenRequestsEmailsToService() { var emailServiceMock = new Mock<IEmailService>(); var requested = false; emailServiceMock .Setup(svc => svc.BeginGetEmailDocuments(It.IsAny<AsyncCallback>(), null)) .Callback(() => requested = true); var viewModel = new InboxViewModel(emailServiceMock.Object, new Mock<IRegionManager>().Object); Assert.IsTrue(requested); }
public void WhenExecutingTheNewCommand_ThenNavigatesToComposeEmailView() { var emailServiceMock = new Mock<IEmailService>(); Mock<IRegionManager> regionManagerMock = new Mock<IRegionManager>(); regionManagerMock.Setup(x => x.RequestNavigate(RegionNames.MainContentRegion, new Uri("ComposeEmailView", UriKind.Relative))).Verifiable(); var viewModel = new InboxViewModel(emailServiceMock.Object, regionManagerMock.Object); viewModel.ComposeMessageCommand.Execute(null); regionManagerMock.VerifyAll(); }
public void WhenExecutingTheOpenCommand_ThenNavigatesToEmailView() { var email = new EmailDocument(); var emailServiceMock = new Mock<IEmailService>(); Mock<IRegionManager> regionManagerMock = new Mock<IRegionManager>(); regionManagerMock.Setup(x => x.RequestNavigate(RegionNames.MainContentRegion, new Uri(@"EmailView?EmailId=" + email.Id.ToString("N"), UriKind.Relative))).Verifiable(); var viewModel = new InboxViewModel(emailServiceMock.Object, regionManagerMock.Object); viewModel.OpenMessageCommand.Execute(email); regionManagerMock.VerifyAll(); }
public void WhenExecutingTheNewCommand_ThenNavigatesToComposeEmailView() { var emailServiceMock = new Mock<IEmailService>(); Mock<IRegion> regionMock = new Mock<IRegion>(); regionMock .Setup(x => x.RequestNavigate(new Uri("ComposeEmailView", 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); var viewModel = new InboxViewModel(emailServiceMock.Object, regionManagerMock.Object); viewModel.ComposeMessageCommand.Execute(null); regionMock.VerifyAll(); }
public InboxView(InboxViewModel viewModel) { InitializeComponent(); this.ViewModel = viewModel; }
public void WhenExecutingTheReplyCommand_ThenNavigatesToComposeEmailViewWithId() { var email = new EmailDocument(); var emailServiceMock = new Mock<IEmailService>(); AsyncCallback callback = null; var asyncResultMock = new Mock<IAsyncResult>(); emailServiceMock .Setup(svc => svc.BeginGetEmailDocuments(It.IsAny<AsyncCallback>(), null)) .Callback<AsyncCallback, object>((ac, o) => callback = ac) .Returns(asyncResultMock.Object); emailServiceMock .Setup(svc => svc.EndGetEmailDocuments(asyncResultMock.Object)) .Returns(new[] { email }); Mock<IRegion> regionMock = new Mock<IRegion>(); regionMock .Setup(x => x.RequestNavigate(new Uri(@"ComposeEmailView?ReplyTo=" + email.Id.ToString("N"), 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); var viewModel = new InboxViewModel(emailServiceMock.Object, regionManagerMock.Object); EnqueueConditional(() => callback != null); EnqueueCallback( () => { callback(asyncResultMock.Object); }); EnqueueConditional( () => { return !viewModel.Messages.IsEmpty; }); EnqueueCallback( () => { viewModel.Messages.MoveCurrentToFirst(); viewModel.ReplyMessageCommand.Execute(null); regionMock.VerifyAll(); }); EnqueueTestComplete(); }