public void Add() { var mruCollection = new MostRecentlyUsedCollection(); var paths = new List <string>(); for (int i = 0; i <= mruCollection.MaximumSize; i++) { paths.Add( string.Format( CultureInfo.InvariantCulture, @"c:\temp\myfile{0}.txt", i)); } for (int i = 0; i < paths.Count; i++) { mruCollection.Add(paths[i]); Assert.That( mruCollection.Select(m => m.FilePath), Is.EquivalentTo( paths .Skip(i >= mruCollection.MaximumSize ? i - mruCollection.MaximumSize + 1 : 0) .Take(i >= mruCollection.MaximumSize ? mruCollection.MaximumSize : i + 1) .Reverse())); } }
public void SerializeAndDeserialize() { var mruCollection = new MostRecentlyUsedCollection(); for (int i = 0; i <= mruCollection.MaximumSize; i++) { mruCollection.Add( string.Format( CultureInfo.InvariantCulture, @"c:\temp\myfile{0}.txt", i)); } var converter = new MostRecentlyUsedCollectionConverter(); var serializedCollection = converter.ConvertTo(null, CultureInfo.InvariantCulture, mruCollection, typeof(string)); var deserializedCollection = converter.ConvertFrom( null, CultureInfo.InvariantCulture, serializedCollection) as MostRecentlyUsedCollection; Assert.That(deserializedCollection.Select(m => m.FilePath), Is.EquivalentTo(mruCollection.Select(m => m.FilePath))); Assert.That(deserializedCollection.Select(m => m.LastTimeOpened), Is.EquivalentTo(mruCollection.Select(m => m.LastTimeOpened))); }