public Remove ( |
||
recentFile | The recent file to remove. | |
return | void |
public void Remove(RecentFile recentFile)
{
if (recentFile == null) { throw new ArgumentNullException(nameof(recentFile)); }
if (recentFiles.Remove(recentFile))
{
recentFile.PropertyChanged -= RecentFilePropertyChanged;
}
else
{
throw new ArgumentException("The passed recentFile was not found in the recent files list.", nameof(recentFile));
}
}
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)); }