public void ConcurrentOrderedMap_Add_ReturnsFalseIfKeyExists()
        {
            const string key   = "foo";
            const string value = "bar";

            var dict = new ConcurrentOrderedDictionary <string, string>();

            dict.Add(key, value);

            Assert.False(dict.Add(key, value));
        }
        public void ConcurrentOrderedMap_ByDefault_OrdersValues_ByInsertionOrder()
        {
            const string firstValue  = "foo";
            const string secondValue = "bar";

            var dict = new ConcurrentOrderedDictionary <string, string>();

            dict.Add("foo", firstValue);
            dict.Add("bar", secondValue);

            var expectedOrder = new[] { firstValue, secondValue };

            Assert.Equal(expectedOrder, dict.Values);
        }
        public void ConcurrentOrderedMap_ByDefault_OrdersKeys_ByInsertionOrder()
        {
            const string firstKey  = "foo";
            const string secondKey = "bar";

            var dict = new ConcurrentOrderedDictionary <string, string>();

            dict.Add(firstKey, "bar");
            dict.Add(secondKey, "foo");

            var expectedOrder = new[] { firstKey, secondKey };

            Assert.Equal(expectedOrder, dict.Keys);
        }
        public void ConcurrentOrderedMap_Supports_AddWithKeyValuePair()
        {
            var dict = new ConcurrentOrderedDictionary <string, string>();

            dict.Add(new KeyValuePair <string, string>("foo", "bar"));
            Assert.Single(dict);
        }
        public void ConcurrentOrderedMap_Supports_Adds()
        {
            var dict = new ConcurrentOrderedDictionary <string, string>();

            dict.Add("foo", "bar");
            Assert.Single(dict);
        }
        public void ConcurrentOrderedMap_ByDefault_EnumeratesValues_ByInsertionOrder()
        {
            const string firstValue  = "foo";
            const string secondValue = "bar";

            var dict = new ConcurrentOrderedDictionary <string, string>();

            dict.Add("foo", firstValue);
            dict.Add("bar", secondValue);

            using (IEnumerator <string> enumerator = dict.GetEnumerator())
            {
                enumerator.MoveNext();
                Assert.Equal(firstValue, enumerator.Current);
                enumerator.MoveNext();
                Assert.Equal(secondValue, enumerator.Current);
            }
        }
        public void ConcurrentOrderedMap_ContainsKey_ReturnsTrueIfKeyExists()
        {
            const string expectedKey = "foo";

            var dict = new ConcurrentOrderedDictionary <string, string>();

            dict.Add(expectedKey, "bar");
            Assert.True(dict.ContainsKey(expectedKey));
        }
        public void ConcurrentOrderedMap_TryGetValue_ReturnsTrueIfKeyExists()
        {
            const string key = "foo";

            var dict = new ConcurrentOrderedDictionary <string, string>();

            dict.Add(key, "bar");

            Assert.True(dict.TryGetValue(key, out var value));
        }
        public void ConcurrentOrderedMap_TryGetValue_ReturnsValueOutIfKeyExists()
        {
            const string key           = "foo";
            const string expectedValue = "bar";

            var dict = new ConcurrentOrderedDictionary <string, string>();

            dict.Add(key, expectedValue);

            dict.TryGetValue(key, out var value);
            Assert.Equal(expectedValue, value);
        }
        public void ConcurrentOrderedMap_ByDefault_CopiesTo_ByInsertionOrder_AndRespectsArrayIndex()
        {
            IEnumerable <string> expectedValues = Enumerable.Range(0, 10).Reverse().Select(v => v.ToString());

            var dict = new ConcurrentOrderedDictionary <string, string>();

            foreach (var val in expectedValues)
            {
                dict.Add(val, val);
            }

            var copiedArray = new string[15];

            dict.CopyTo(copiedArray, 5);

            Assert.Equal(expectedValues, copiedArray.Skip(5));
        }
        public void ConcurrentOrderedMap_Add_ReturnsTrueIfItemIsAdded()
        {
            var dict = new ConcurrentOrderedDictionary <string, string>();

            Assert.True(dict.Add("foo", "bar"));
        }