Esempio n. 1
0
        public void TestDequeue()
        {
            var dictionary = new ConcurrentMultiValueDictionary <int, string>();

            dictionary.Enqueue(1, "a");
            dictionary.Enqueue(1, "b");
            dictionary.Enqueue(1, "c");

            String value;

            Assert.AreEqual(dictionary.GetValues(1).Count, 3);

            Assert.IsTrue(dictionary.TryDequeue(1, out value));
            Assert.AreEqual(value, "a");

            Assert.AreEqual(dictionary.GetValues(1).Count, 2);

            Assert.IsTrue(dictionary.TryDequeue(1, out value));
            Assert.AreEqual(value, "b");

            Assert.AreEqual(dictionary.GetValues(1).Count, 1);

            Assert.IsTrue(dictionary.TryDequeue(1, out value));
            Assert.AreEqual(value, "c");

            Assert.AreEqual(dictionary.GetValues(1).Count, 0);

            Assert.IsFalse(dictionary.TryDequeue(1, out value));
            Assert.IsNull(value);

            Assert.IsFalse(dictionary.TryDequeue(99, out value));
            Assert.IsNull(value);
        }
        public void TestEnqueue()
        {
            var dictionary = new ConcurrentMultiValueDictionary<int, string>();

            dictionary.Enqueue(1, "a");
            dictionary.Enqueue(1, "b");
            dictionary.Enqueue(1, "c");

            dictionary.Enqueue(2, "d");
            dictionary.Enqueue(2, "e");
            dictionary.Enqueue(2, "f");

            List<string> values1 = dictionary.GetValues(1);
            List<string> values2 = dictionary.GetValues(2);

            Assert.AreEqual(values1.Count, 3);
            Assert.AreEqual(values1[0], "a");
            Assert.AreEqual(values1[1], "b");
            Assert.AreEqual(values1[2], "c");

            Assert.AreEqual(values2.Count, 3);
            Assert.AreEqual(values2[0], "d");
            Assert.AreEqual(values2[1], "e");
            Assert.AreEqual(values2[2], "f");
        }
Esempio n. 3
0
        public void TestEnqueue()
        {
            var dictionary = new ConcurrentMultiValueDictionary <int, string>();

            dictionary.Enqueue(1, "a");
            dictionary.Enqueue(1, "b");
            dictionary.Enqueue(1, "c");

            dictionary.Enqueue(2, "d");
            dictionary.Enqueue(2, "e");
            dictionary.Enqueue(2, "f");

            List <string> values1 = dictionary.GetValues(1);
            List <string> values2 = dictionary.GetValues(2);

            Assert.AreEqual(values1.Count, 3);
            Assert.AreEqual(values1[0], "a");
            Assert.AreEqual(values1[1], "b");
            Assert.AreEqual(values1[2], "c");

            Assert.AreEqual(values2.Count, 3);
            Assert.AreEqual(values2[0], "d");
            Assert.AreEqual(values2[1], "e");
            Assert.AreEqual(values2[2], "f");
        }
        public void TestDequeue()
        {
            var dictionary = new ConcurrentMultiValueDictionary<int, string>();

            dictionary.Enqueue(1, "a");
            dictionary.Enqueue(1, "b");
            dictionary.Enqueue(1, "c");

            String value;

            Assert.AreEqual(dictionary.GetValues(1).Count, 3);

            Assert.IsTrue(dictionary.TryDequeue(1, out value));
            Assert.AreEqual(value, "a");

            Assert.AreEqual(dictionary.GetValues(1).Count, 2);

            Assert.IsTrue(dictionary.TryDequeue(1, out value));
            Assert.AreEqual(value, "b");

            Assert.AreEqual(dictionary.GetValues(1).Count, 1);

            Assert.IsTrue(dictionary.TryDequeue(1, out value));
            Assert.AreEqual(value, "c");

            Assert.AreEqual(dictionary.GetValues(1).Count, 0);

            Assert.IsFalse(dictionary.TryDequeue(1, out value));
            Assert.IsNull(value);

            Assert.IsFalse(dictionary.TryDequeue(99, out value));
            Assert.IsNull(value);
        }