public FileController(IMessageService messageService, IFileDialogService fileDialogService, IShellService shellService, FileService fileService, ExportFactory<SaveChangesViewModel> saveChangesViewModelFactory) { this.messageService = messageService; this.fileDialogService = fileDialogService; this.shellService = shellService; this.fileService = fileService; this.saveChangesViewModelFactory = saveChangesViewModelFactory; this.documentTypes = new List<IDocumentType>(); this.newCommand = new DelegateCommand(NewCommand); this.openCommand = new DelegateCommand(OpenCommand); this.closeCommand = new DelegateCommand(CloseCommand, CanCloseCommand); this.saveCommand = new DelegateCommand(SaveCommand, CanSaveCommand); this.saveAsCommand = new DelegateCommand(SaveAsCommand, CanSaveAsCommand); this.fileService.NewCommand = newCommand; this.fileService.OpenCommand = openCommand; this.fileService.CloseCommand = closeCommand; this.fileService.SaveCommand = saveCommand; this.fileService.SaveAsCommand = saveAsCommand; this.recentFileList = Settings.Default.RecentFileList ?? new RecentFileList(); this.fileService.RecentFileList = recentFileList; PropertyChangedEventManager.AddHandler(fileService, FileServicePropertyChanged, ""); }
public FileController(CompositionContainer container, IMessageService messageService, IFileDialogService fileDialogService, IShellService shellService, FileService fileService) { this.container = container; this.messageService = messageService; this.fileDialogService = fileDialogService; this.shellService = shellService; this.fileService = fileService; this.documentTypes = new List<IDocumentType>(); this.newCommand = new DelegateCommand(NewCommand); this.openCommand = new DelegateCommand(OpenCommand); this.closeCommand = new DelegateCommand(CloseCommand, CanCloseCommand); this.saveCommand = new DelegateCommand(SaveCommand, CanSaveCommand); this.saveAsCommand = new DelegateCommand(SaveAsCommand, CanSaveAsCommand); this.fileService.NewCommand = newCommand; this.fileService.OpenCommand = openCommand; this.fileService.CloseCommand = closeCommand; this.fileService.SaveCommand = saveCommand; this.fileService.SaveAsCommand = saveAsCommand; this.recentFileList = Settings.Default.RecentFileList; if (this.recentFileList == null) { this.recentFileList = new RecentFileList(); } this.fileService.RecentFileList = recentFileList; AddWeakEventListener(fileService, FileServicePropertyChanged); }
public void RecentFileList() { FileService fileService = Container.GetExportedValue<FileService>(); RecentFileList recentFileList = new RecentFileList(); AssertHelper.PropertyChangedEvent(fileService, x => x.RecentFileList, () => fileService.RecentFileList = recentFileList); Assert.AreEqual(recentFileList, fileService.RecentFileList); }
public void SetMaxFilesNumber() { RecentFileList recentFileList = new RecentFileList(); recentFileList.AddFile("Doc4"); recentFileList.AddFile("Doc3"); recentFileList.AddFile("Doc2"); recentFileList.AddFile("Doc1"); Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new [] { "Doc1", "Doc2", "Doc3", "Doc4" })); // Set a lower number than items are in the list => expect that the list is truncated. recentFileList.MaxFilesNumber = 3; Assert.AreEqual(3, recentFileList.MaxFilesNumber); Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc1", "Doc2", "Doc3" })); AssertHelper.ExpectedException<ArgumentException>(() => recentFileList.MaxFilesNumber = -3); }
public void AddFilesAndPinThem() { RecentFileList recentFileList = new RecentFileList(); recentFileList.MaxFilesNumber = 3; // Add files to an empty list recentFileList.AddFile("Doc3"); recentFileList.AddFile("Doc2"); recentFileList.AddFile("Doc1"); Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc1", "Doc2", "Doc3" })); // Pin first file recentFileList.RecentFiles.First(r => r.Path == "Doc3").IsPinned = true; Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc3", "Doc1", "Doc2" })); // Add a file to a full list recentFileList.AddFile("Doc4"); Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc3", "Doc4", "Doc1" })); // Add a file that already exists in the list recentFileList.AddFile("Doc1"); Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc3", "Doc1", "Doc4" })); // Pin all files recentFileList.RecentFiles.First(r => r.Path == "Doc4").IsPinned = true; Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc4", "Doc3", "Doc1" })); recentFileList.RecentFiles.First(r => r.Path == "Doc1").IsPinned = true; Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc1", "Doc4", "Doc3" })); // Add a file to a full pinned list recentFileList.AddFile("Doc5"); Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc1", "Doc4", "Doc3" })); // Add a file that already exists in the list recentFileList.AddFile("Doc4"); Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc4", "Doc1", "Doc3" })); // Unpin files recentFileList.RecentFiles.First(r => r.Path == "Doc4").IsPinned = false; Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc1", "Doc3", "Doc4" })); recentFileList.RecentFiles.First(r => r.Path == "Doc1").IsPinned = false; Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc3", "Doc1", "Doc4" })); }
public void AddFiles() { RecentFileList recentFileList = new RecentFileList(); recentFileList.MaxFilesNumber = 3; AssertHelper.ExpectedException<ArgumentException>(() => recentFileList.AddFile(null)); // Add files to an empty list recentFileList.AddFile("Doc3"); Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc3" })); recentFileList.AddFile("Doc2"); Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc2", "Doc3" })); recentFileList.AddFile("Doc1"); Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc1", "Doc2", "Doc3" })); // Add a file to a full list recentFileList.AddFile("Doc4"); Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc4", "Doc1", "Doc2" })); // Add a file that already exists in the list recentFileList.AddFile("Doc2"); Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc2", "Doc4", "Doc1" })); }
public void Load() { RecentFileList recentFileList = new RecentFileList(); recentFileList.MaxFilesNumber = 3; recentFileList.AddFile("Doc3"); recentFileList.AddFile("Doc2"); recentFileList.AddFile("Doc1"); AssertHelper.ExpectedException<ArgumentNullException>(() => recentFileList.Load(null)); // Load an empty recent file list recentFileList.Load(new RecentFile[] { }); Assert.IsFalse(recentFileList.RecentFiles.Any()); recentFileList.Load(new[] { new RecentFile("NewDoc1") { IsPinned = true }, new RecentFile("NewDoc2"), new RecentFile("NewDoc3"), new RecentFile("NewDoc4") }); Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "NewDoc1", "NewDoc2", "NewDoc3" })); Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.IsPinned).SequenceEqual(new[] { true, false, false })); }
public void XmlSerializing() { XmlSerializer serializer = new XmlSerializer(typeof(RecentFileList)); // Serialize an empty list MemoryStream stream1 = new MemoryStream(); RecentFileList recentFileList1 = new RecentFileList(); serializer.Serialize(stream1, recentFileList1); stream1.Position = 0; RecentFileList recentFileList2 = (RecentFileList)serializer.Deserialize(stream1); Assert.AreEqual(recentFileList1.RecentFiles.Count, recentFileList2.RecentFiles.Count); Assert.IsTrue(recentFileList1.RecentFiles.Select(f => f.Path).SequenceEqual(recentFileList2.RecentFiles.Select(f => f.Path))); // Serialize a list with items MemoryStream stream2 = new MemoryStream(); recentFileList2.AddFile("Doc3"); recentFileList2.AddFile("Doc2"); recentFileList2.AddFile("Doc1"); serializer.Serialize(stream2, recentFileList2); stream2.Position = 0; RecentFileList recentFileList3 = (RecentFileList)serializer.Deserialize(stream2); Assert.IsTrue(recentFileList2.RecentFiles.Select(f => f.Path).SequenceEqual(recentFileList3.RecentFiles.Select(f => f.Path))); // Set MaxFilesNumber to a lower number recentFileList3.MaxFilesNumber = 2; Assert.IsTrue(recentFileList3.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc1", "Doc2" })); // Check error handling of the serializable implementation IXmlSerializable serializable = recentFileList3; Assert.IsNull(serializable.GetSchema()); AssertHelper.ExpectedException<ArgumentNullException>(() => serializable.ReadXml(null)); AssertHelper.ExpectedException<ArgumentNullException>(() => serializable.WriteXml(null)); }
public void Remove() { RecentFileList recentFileList = new RecentFileList(); AssertHelper.ExpectedException<ArgumentNullException>(() => recentFileList.Remove(null)); recentFileList.AddFile("Doc1"); recentFileList.AddFile("Doc2"); recentFileList.AddFile("Doc3"); RecentFile lastAdded = recentFileList.RecentFiles.First(); recentFileList.Remove(recentFileList.RecentFiles.Last()); Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc3", "Doc2" })); recentFileList.Remove(recentFileList.RecentFiles.First()); Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc2" })); recentFileList.Remove(recentFileList.RecentFiles.First()); Assert.IsTrue(!recentFileList.RecentFiles.Any()); // Try to delete a RecentFile object which was already deleted. AssertHelper.ExpectedException<ArgumentException>(() => recentFileList.Remove(lastAdded)); }