public void NewDocumentDialogViewModelCloseTest() { MockDocumentType documentType = new MockDocumentType("Mock Document Type", ".mock"); MockNewDocumentDialogView view = new MockNewDocumentDialogView(); NewDocumentDialogViewModel viewModel = new NewDocumentDialogViewModel( view, new List<IDocumentType>() { documentType }); Assert.AreEqual("NewFile", viewModel.FileName); Assert.AreEqual(documentType, viewModel.SelectDocumentType); object owner = new object(); bool showDialogCalled = false; view.ShowDialogAction = v => { showDialogCalled = true; // Cancel v.Close(); }; bool? dialogResult = viewModel.ShowDialog(owner); Assert.IsNull(dialogResult); Assert.IsTrue(showDialogCalled); showDialogCalled = false; view.ShowDialogAction = v => { showDialogCalled = true; v.ViewModel.FileName = "NewMockFile"; v.ViewModel.SelectDocumentType = documentType; v.ViewModel.OKCommand.Execute(null); }; dialogResult = viewModel.ShowDialog(owner); Assert.IsTrue(showDialogCalled); Assert.AreEqual(true, dialogResult); Assert.AreEqual("NewMockFile", viewModel.FileName); Assert.AreEqual(documentType, viewModel.SelectDocumentType); }
private IDocument NewDocument() { // Show the new document view to the user INewDocumentDialogView newDocumentView = container.GetExportedValue<INewDocumentDialogView>(); NewDocumentDialogViewModel newDocumentViewModel = new NewDocumentDialogViewModel( newDocumentView, documentTypes.Where(d=> d.CanNew()).Select(d => d)); bool? dialogResult = newDocumentViewModel.ShowDialog(shellService.ShellView); if (dialogResult == true) { return NewCore(Path.Combine(Path.GetDirectoryName(SolutionDoc.FullFilePath), newDocumentViewModel.FileName + newDocumentViewModel.SelectDocumentType.FileExtension)); } else return null; }