AddFile() public method

Adds a file to the recent file list. If the file already exists in the list then it only changes the position in the list.
The argument fileName must not be null or empty.
public AddFile ( string fileName ) : void
fileName string The path of the recent file.
return void
示例#1
0
        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);
        }
示例#2
0
        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" }));
        }
示例#3
0
        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" }));
        }
示例#4
0
        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 }));
        }
示例#5
0
        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));
        }