public void SaveChangesViewModelCloseTest() { MockDocumentType documentType = new MockDocumentType("Mock Document", ".mock"); var documents = new[] { documentType.New(), documentType.New(), documentType.New() }; MockSaveChangesView view = new MockSaveChangesView(); SaveChangesViewModel viewModel = new SaveChangesViewModel(view) { Documents = documents }; // In this case it tries to get the title of the unit test framework which is "" Assert.AreEqual("", SaveChangesViewModel.Title); Assert.AreEqual(documents, viewModel.Documents); object owner = new object(); Assert.IsFalse(view.IsVisible); MockSaveChangesView.ShowDialogAction = v => { Assert.AreEqual(owner, v.Owner); Assert.IsTrue(v.IsVisible); }; bool? dialogResult = viewModel.ShowDialog(owner); Assert.IsNull(dialogResult); Assert.IsFalse(view.IsVisible); MockSaveChangesView.ShowDialogAction = v => { viewModel.YesCommand.Execute(null); }; dialogResult = viewModel.ShowDialog(owner); Assert.AreEqual(true, dialogResult); MockSaveChangesView.ShowDialogAction = v => { viewModel.NoCommand.Execute(null); }; dialogResult = viewModel.ShowDialog(owner); Assert.AreEqual(false, dialogResult); MockSaveChangesView.ShowDialogAction = null; }
public void NewAndActiveDocumentTest() { FileController fileController = Container.GetExportedValue<FileController>(); IFileService fileService = Container.GetExportedValue<IFileService>(); MockDocumentType documentType = new MockDocumentType("Mock Document", ".mock"); fileController.Register(documentType); Assert.IsFalse(fileService.Documents.Any()); Assert.IsNull(fileService.ActiveDocument); IDocument document = fileController.New(documentType); Assert.IsTrue(fileService.Documents.SequenceEqual(new IDocument[] { document })); Assert.AreEqual(document, fileService.ActiveDocument); AssertHelper.ExpectedException<ArgumentNullException>(() => fileController.New(null)); AssertHelper.ExpectedException<ArgumentException>(() => fileController.New(new MockDocumentType("Dummy", ".dmy"))); AssertHelper.PropertyChangedEvent(fileService, x => x.ActiveDocument, () => fileService.ActiveDocument = null); Assert.AreEqual(null, fileService.ActiveDocument); AssertHelper.ExpectedException<ArgumentException>(() => fileService.ActiveDocument = documentType.New()); }