예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MostRecentlyUsedModel"/> class.
        /// </summary>
        /// <param name="context">The context that is used to execute actions on the UI thread.</param>
        /// <param name="mostRecentlyUsed">The object that stores information about a most recently used file.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="context"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="mostRecentlyUsed"/> is <see langword="null" />.
        /// </exception>
        public MostRecentlyUsedModel(IContextAware context, MostRecentlyUsed mostRecentlyUsed)
            : base(context)
        {
            {
                Lokad.Enforce.Argument(() => mostRecentlyUsed);
            }

            m_Mru = mostRecentlyUsed;
        }
        public void Create()
        {
            var context = new Mock <IContextAware>();
            var mru     = new MostRecentlyUsed(@"c:\temp\a.txt", DateTimeOffset.Now);
            var model   = new MostRecentlyUsedModel(context.Object, mru);

            Assert.AreEqual(Path.GetFileNameWithoutExtension(mru.FilePath), model.FileName);
            Assert.AreEqual(mru.FilePath, model.FilePath);
            Assert.AreEqual(mru.LastTimeOpened, model.LastTimeOpened);
        }
예제 #3
0
        public void Add(K key, V value)
        {
            var mruNode = MostRecentlyUsed.Add(value);

            mruNode.OnRemoval = () =>
            {
                MruNode <V> node;
                Dictionary.TryRemove(key, out node);
            };
            Dictionary.TryAdd(key, mruNode);
        }
예제 #4
0
        public void MostRecentlyUsedTest()
        {
            File.Delete(MRUFile);

            var mru = new MostRecentlyUsed(MRUFile);

            Assert.AreEqual(0, mru.Count);

            mru.Update("A");
            Assert.AreEqual(1, mru.Count);
            Assert.AreEqual("A", mru[0]);

            mru.Update("B");
            Assert.AreEqual(2, mru.Count);
            Assert.AreEqual("B", mru[0]);
            Assert.AreEqual("A", mru[1]);

            mru.Update("C");
            Assert.AreEqual(3, mru.Count);
            Assert.AreEqual("C", mru[0]);
            Assert.AreEqual("B", mru[1]);
            Assert.AreEqual("A", mru[2]);

            mru.Update("B");
            Assert.AreEqual(3, mru.Count);
            Assert.AreEqual("B", mru[0]);
            Assert.AreEqual("C", mru[1]);
            Assert.AreEqual("A", mru[2]);

            var mru2 = new MostRecentlyUsed(MRUFile);

            Assert.AreEqual(3, mru2.Count);
            Assert.AreEqual("B", mru2[0]);
            Assert.AreEqual("C", mru2[1]);
            Assert.AreEqual("A", mru2[2]);

            var vals = new List <string>();

            foreach (string s in mru2)
            {
                vals.Add(s);
            }
            Assert.AreEqual(3, vals.Count);
            Assert.AreEqual("B", vals[0]);
            Assert.AreEqual("C", vals[1]);
            Assert.AreEqual("A", vals[2]);
        }
예제 #5
0
 public void Clear()
 {
     Dictionary.Clear();
     MostRecentlyUsed.Clear();
 }