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

            result.PutAll(source);
            return(result);
        }
Exemplo n.º 2
0
        public void ShouldConvertHashSetMultiDictionaryToImmutableListMultiDictionary()
        {
            // given
            var multiDictionary = new HashSetMultiDictionary <int, string>();

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

            // when
            var immutableMultiDictionary = multiDictionary.ToImmutableListMultiDictionary();

            // then
            Check.That(immutableMultiDictionary).IsEqualTo(ImmutableListMultiDictionary <int, string> .Of(
                                                               1, "A",
                                                               2, "A", 2, "B",
                                                               3, "X", 3, "Y"));
        }
Exemplo n.º 3
0
        private static IEnumerable <ITestCaseData> MultiDictionaryComparationCases()
        {
            MultiDictionary <int, string> first = new ArrayListMultiDictionary <int, string>();

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

            MultiDictionary <int, string> second = new ArrayListMultiDictionary <int, string>();

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

            yield return(new TestCaseData(first, second)
                         .SetName("Should return that multi dictionaries are equals")
                         .Returns(true));

            first = new HashSetMultiDictionary <int, string>();
            first.Put(1, "A");
            first.Put(2, "B");
            first.PutAll(3, Lists.AsList("A", "B", "C"));

            second = new ArrayListMultiDictionary <int, string>();
            second.Put(1, "A");
            second.Put(2, "B");
            second.PutAll(3, Lists.AsList("A", "B", "C"));

            yield return(new TestCaseData(first, second)
                         .SetName("Should return that different implementations of multi dictionaries with same elements are equals")
                         .Returns(true));

            first = new ArrayListMultiDictionary <int, string>();
            first.Put(1, "A");
            first.Put(2, "B");
            first.PutAll(3, Lists.AsList("A", "B", "C"));

            second = new ArrayListMultiDictionary <int, string>();
            second.Put(1, "A");
            second.Put(2, "B");
            second.PutAll(3, Lists.AsList("B", "C"));

            yield return(new TestCaseData(first, second)
                         .SetName("Should return that multi dictionaries with different elements are not equals")
                         .Returns(false));
        }
Exemplo n.º 4
0
        public void ShouldNotAllowDuplicatedValuesForKey()
        {
            // given
            var multiDictionary = new HashSetMultiDictionary <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(3);
            Check.That(multiDictionary.Values).ContainsExactly("A", "A", "B");
            Check.That(multiDictionary[1]).ContainsExactly("A");
            Check.That(multiDictionary[1]).IsInstanceOf <HashSet <string> >();
            Check.That(multiDictionary[2]).ContainsExactly("A", "B");
            Check.That(multiDictionary[2]).IsInstanceOf <HashSet <string> >();
        }
Exemplo n.º 5
0
        public void ShouldConvertMultiDictionaryToDictionaryWithHashSets()
        {
            // given
            var multiDictionary = new HashSetMultiDictionary <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 <HashSet <string> >()
            .And.ContainsExactly("A");
            Check.That(dictionary[2]).IsInstanceOf <HashSet <string> >()
            .And.ContainsExactly("B");
            Check.That(dictionary[3]).IsInstanceOf <HashSet <string> >()
            .And.ContainsExactly("A", "B", "C");
        }