/// <summary>
        /// Converts dictionary to LinkedListMultiDictionary.
        /// </summary>
        /// <typeparam name="TKey">Type of dictionary key</typeparam>
        /// <typeparam name="TValue">Type of dictionary value</typeparam>
        /// <param name="source">this</param>
        /// <returns>LinkedListMultiDictionary</returns>
        public static LinkedListMultiDictionary <TKey, TValue> ToLinkedListMultiDictionary <TKey, TValue>(
            this IReadOnlyDictionary <TKey, TValue> source)
        {
            Preconditions.IsNotNull(source, () => new ArgumentNullException("source"));
            var result = new LinkedListMultiDictionary <TKey, TValue>();

            result.PutAll(source);
            return(result);
        }
Exemplo n.º 2
0
        public void ShouldExntedReadOnlyDictionaryByToLinkedListMultiDictionaryMethod()
        {
            // given
            var dictionary = Dictionaries.CreateImmutable("A", "A1", "B", "B1", "C", "C1");

            // when
            var multiDictionary = dictionary.ToLinkedListMultiDictionary();

            // then
            Check.That(multiDictionary)
            .IsEqualTo(LinkedListMultiDictionary <string, string> .Of("A", "A1", "B", "B1", "C", "C1"));
        }
        public void ShouldAllowDuplicatedValuesForKey()
        {
            // given
            var multiDictionary = new LinkedListMultiDictionary <int, string>();

            // when
            multiDictionary.Put(1, "A");
            multiDictionary.Put(1, "A");
            multiDictionary.PutAll(2, Lists.AsList("A", "B", "B"));

            // then
            Check.That(multiDictionary.Count).IsEqualTo(5);
            Check.That(multiDictionary.Values).ContainsExactly("A", "A", "A", "B", "B");
            Check.That(multiDictionary[1]).ContainsExactly("A", "A");
            Check.That(multiDictionary[1]).IsInstanceOf <LinkedList <string> >();
            Check.That(multiDictionary[2]).ContainsExactly("A", "B", "B");
            Check.That(multiDictionary[2]).IsInstanceOf <LinkedList <string> >();
        }
        public void ShouldConvertMultiDictionaryToDictionaryWithLinkedLists()
        {
            // given
            var multiDictionary = new LinkedListMultiDictionary <int, string>();

            multiDictionary.Put(1, "A");
            multiDictionary.Put(2, "B");
            multiDictionary.PutAll(3, Lists.AsList("A", "B", "C", "C"));

            // when
            var dictionary = multiDictionary.ToDictionary();

            // then
            Check.That(dictionary[1]).IsInstanceOf <LinkedList <string> >()
            .And.ContainsExactly("A");
            Check.That(dictionary[2]).IsInstanceOf <LinkedList <string> >()
            .And.ContainsExactly("B");
            Check.That(dictionary[3]).IsInstanceOf <LinkedList <string> >()
            .And.ContainsExactly("A", "B", "C", "C");
        }