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()));
            }
        }
Exemplo n.º 2
0
        public void Add_FirstItem()
        {
            var mru = new MostRecentlyUsedCollection <String>();

            mru.Add("one");

            Assert.AreEqual(1, mru.Count);
        }
Exemplo n.º 3
0
        public void Penultimate_ZeroItems()
        {
            var mru = new MostRecentlyUsedCollection <String>();

            var actual = mru.Penultimate;

            Assert.AreEqual(null, actual);
        }
        public void Add_FirstItem()
        {
            var mru = new MostRecentlyUsedCollection<String>();

            mru.Add("one");

            Assert.AreEqual(1, mru.Count);
        }
Exemplo n.º 5
0
        public void Clear_Empty()
        {
            var mru = new MostRecentlyUsedCollection <String>();

            mru.Clear();

            Assert.AreEqual(0, mru.Count);
        }
Exemplo n.º 6
0
        public void Load()
        {
            var items = new [] { "a", "b", "c", "d" };
            var c     = new MostRecentlyUsedCollection <string> ();

            c.Load(items);
            c.SequenceShouldEqual(items);
        }
        public void Clear_Empty()
        {
            var mru = new MostRecentlyUsedCollection<String>();

            mru.Clear();

            Assert.AreEqual(0, mru.Count);
        }
Exemplo n.º 8
0
        public void GetEnumerator_OneItem()
        {
            var mru = new MostRecentlyUsedCollection <String>();

            mru.Add("one");

            EnumerableExtensions.EnumerateSame(new[] { "one" }, mru);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WelcomeModel"/> class.
 /// </summary>
 /// <param name="context">The context that is used to execute actions on the UI thread.</param>
 /// <exception cref="ArgumentNullException">
 ///     Thrown if <paramref name="context"/> is <see langword="null" />.
 /// </exception>
 public WelcomeModel(IContextAware context)
     : base(context)
 {
     var collection = new MostRecentlyUsedCollection();
     foreach (var mru in collection)
     {
         m_Mru.Add(new MostRecentlyUsedModel(context, mru));
     }
 }
        public void Contains_OneItem()
        {
            var mru = new MostRecentlyUsedCollection<String>();
            mru.Add("one");

            var actual = mru.Contains("one");

            Assert.AreEqual(true, actual);
        }
Exemplo n.º 11
0
        public void Contains_OneItem()
        {
            var mru = new MostRecentlyUsedCollection <String>();

            mru.Add("one");

            var actual = mru.Contains("one");

            Assert.AreEqual(true, actual);
        }
Exemplo n.º 12
0
        public void Penultimate_OneItem()
        {
            var mru = new MostRecentlyUsedCollection <String>();

            mru.Add("one");

            var actual = mru.Penultimate;

            Assert.AreEqual(null, actual);
        }
        public void Clear_WithItems()
        {
            var mru = new MostRecentlyUsedCollection<String>();
            mru.Add("one");
            mru.Add("two");

            mru.Clear();

            Assert.AreEqual(0, mru.Count);
        }
        public void Add_TwoItems()
        {
            var mru = new MostRecentlyUsedCollection<String>();
            mru.Add("one");

            mru.Add("two");

            Assert.AreEqual(2, mru.Count);
            EnumerableExtensions.EnumerateSame(new [] {"two", "one"}, mru);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WelcomeModel"/> class.
        /// </summary>
        /// <param name="context">The context that is used to execute actions on the UI thread.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="context"/> is <see langword="null" />.
        /// </exception>
        public WelcomeModel(IContextAware context)
            : base(context)
        {
            var collection = new MostRecentlyUsedCollection();

            foreach (var mru in collection)
            {
                m_Mru.Add(new MostRecentlyUsedModel(context, mru));
            }
        }
Exemplo n.º 16
0
        public void Clear_WithItems()
        {
            var mru = new MostRecentlyUsedCollection <String>();

            mru.Add("one");
            mru.Add("two");

            mru.Clear();

            Assert.AreEqual(0, mru.Count);
        }
Exemplo n.º 17
0
        public void Add_TwoItems()
        {
            var mru = new MostRecentlyUsedCollection <String>();

            mru.Add("one");

            mru.Add("two");

            Assert.AreEqual(2, mru.Count);
            EnumerableExtensions.EnumerateSame(new [] { "two", "one" }, mru);
        }
Exemplo n.º 18
0
        public void Remove_Exists()
        {
            var mru = new MostRecentlyUsedCollection <String>();

            mru.Add("one");
            mru.Add("two");

            var actual = mru.Remove("one");

            Assert.AreEqual(true, actual);
        }
Exemplo n.º 19
0
        public void Remove_DoesNotExist()
        {
            var mru = new MostRecentlyUsedCollection <String>();

            mru.Add("one");
            mru.Add("two");

            var actual = mru.Remove("three");

            Assert.AreEqual(false, actual);
        }
Exemplo n.º 20
0
        public void Clear()
        {
            var c = new MostRecentlyUsedCollection <string> {
                "a", "b", "c"
            };

            c.Count.ShouldEqual(3);

            c.Clear();

            c.Count.ShouldEqual(0);
        }
Exemplo n.º 21
0
        public void Maximum()
        {
            var c = new MostRecentlyUsedCollection <string> ();

            var documents = Enumerable
                            .Range(0, c.MaxCount * 2)
                            .Select(i => i.ToString())
                            .ToArray();

            documents.ForEach(c.Add);

            c.ShouldEqual(documents.Reverse().Take(c.MaxCount));
        }
Exemplo n.º 22
0
        public void CollectionChanges()
        {
            var expectedChanges = new List <NotifyCollectionChangedEventArgs> ();
            var actualChanges   = new List <NotifyCollectionChangedEventArgs> ();

            var c = new MostRecentlyUsedCollection <string> (maxCount: 5);

            c.CollectionChanged += (sender, e) => {
                expectedChanges.Count.ShouldBeGreaterThan(0);
                actualChanges.Add(e);
            };

            void AssertChanges(Action action, params NotifyCollectionChangedEventArgs [] _expectedChanges)
Exemplo n.º 23
0
        public void OrderAndDuplicates()
        {
            var c = new MostRecentlyUsedCollection <string> {
                "a", "b", "c"
            };

            c.SequenceShouldEqual(new [] { "c", "b", "a" });

            c.Add("b");
            c.SequenceShouldEqual(new [] { "b", "c", "a" });

            c.Add("b");
            c.SequenceShouldEqual(new [] { "b", "c", "a" });
        }
Exemplo n.º 24
0
        public void Validation()
        {
            var validItems = new [] { "a", "b", "c" };

            var c = new MostRecentlyUsedCollection <string> (
                itemValidationDelegate: i => validItems.Contains(i));

            c.Load(new [] { "a", "b", "c", "d" });
            c.SequenceShouldEqual(validItems);

            c.Clear();
            c.Count.ShouldEqual(0);

            c.Add("d");
            c.Count.ShouldEqual(0);

            // ensure even if we make no inserts, we still validate the rest
            c.Load(new [] { "a", "b", "c", "d" });
            validItems = new [] { "a" };
            c.Add("a");
            c.SequenceShouldEqual(new [] { "a" });
        }
        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)));
        }
        public void IsReadOnly()
        {
            var mru = new MostRecentlyUsedCollection<String>();

            Assert.AreEqual(false, mru.IsReadOnly);
        }
        public void GetEnumerator_OneItem()
        {
            var mru = new MostRecentlyUsedCollection<String>();
            mru.Add("one");

            EnumerableExtensions.EnumerateSame(new[] {"one"}, mru);
        }
Exemplo n.º 28
0
        public void IsReadOnly()
        {
            var mru = new MostRecentlyUsedCollection <String>();

            Assert.AreEqual(false, mru.IsReadOnly);
        }
        public void Penultimate_TwoItems()
        {
            var mru = new MostRecentlyUsedCollection<String>();
            mru.Add("one");
            mru.Add("two");

            var actual = mru.Penultimate;

            Assert.AreEqual("one", actual);
        }
        public void Remove_Exists()
        {
            var mru = new MostRecentlyUsedCollection<String>();
            mru.Add("one");
            mru.Add("two");

            var actual = mru.Remove("one");

            Assert.AreEqual(true, actual);
        }
        public void Remove_DoesNotExist()
        {
            var mru = new MostRecentlyUsedCollection<String>();
            mru.Add("one");
            mru.Add("two");

            var actual = mru.Remove("three");

            Assert.AreEqual(false, actual);
        }
        public void Penultimate_ZeroItems()
        {
            var mru = new MostRecentlyUsedCollection<String>();

            var actual = mru.Penultimate;

            Assert.AreEqual(null, actual);
        }