Example #1
0
        public void ShouldExntedReadOnlyDictionaryByToHashSetMultiDictionaryMethod()
        {
            // given
            var dictionary = Dictionaries.CreateImmutable("A", "A1", "B", "B1", "C", "C1");

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

            // then
            Check.That(multiDictionary)
            .IsEqualTo(HashSetMultiDictionary <string, string> .Of("A", "A1", "B", "B1", "C", "C1"));
        }
Example #2
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));
        }
Example #3
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"));
        }
Example #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> >();
        }
Example #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");
        }