Esempio n. 1
0
        public void _1_Clear_Should_clear_items()
        {
            OtherCircularBuffer <char> collection = new OtherCircularBuffer <char>(42);

            foreach (char c in "mindplugg")
            {
                collection.Add(c);
            }

            collection.Clear();

            Assert.Equal(string.Empty, new string(collection.ToArray()));
        }
Esempio n. 2
0
        public void _2_Add_Should_be_thread_safe()
        {
            OtherCircularBuffer <char> collection = new OtherCircularBuffer <char>(26);

            for (int i = 0; i < 100; ++i)
            {
                "azertyuiopqsdfghjklmwxcvbn".AsParallel().ForAll(collection.Add);
                "azertyuiopqsdfghjklmwxcvbn".AsParallel().ForAll(collection.Add);

                Assert.All(collection, c => Assert.Contains(c, "azertyuiopqsdfghjklmwxcvbn"));

                collection.Clear();
            }
        }
Esempio n. 3
0
        public void _B_Clear_Should_remove_item_references()
        {
            OtherCircularBuffer <object> collection = new OtherCircularBuffer <object>(42);

            object        o         = new object();
            WeakReference reference = new WeakReference(o);

            collection.Add(o);

            o = null;
            collection.Clear();

            GC.Collect();
            GC.WaitForPendingFinalizers();

            Assert.False(reference.IsAlive, "reference is still alive, switch in Release configuration is this is not expected");
        }