Esempio n. 1
0
        public void ShouldReturnEntries(MultiDictionaryContext context)
        {
            // given
            var multiDictionary = context.Create <int, string>();

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

            // when
            var entries = multiDictionary.Entries;

            // then
            Check.That(entries).HasSize(7);
            Check.That(entries).Contains(
                Dictionaries.Entry(1, "A"),
                Dictionaries.Entry(1, "B"),
                Dictionaries.Entry(1, "C"),
                Dictionaries.Entry(2, "A"),
                Dictionaries.Entry(3, "X"),
                Dictionaries.Entry(3, "Y"),
                Dictionaries.Entry(3, "Z"));
        }
Esempio n. 2
0
        public void ShouldPreventImmutableMultiDictionaryClear(ImmutableMultiDictionaryCreator creator)
        {
            // given
            var immutableMultiDictionary = creator.Create(Dictionaries.Entry(1, "A"));

            // when
            var result = Try.To(() => immutableMultiDictionary.Clear());

            // then
            var caughtException = result.IsFailure ? result.Error : null;

            Check.That(caughtException).IsNotNull();
            Check.That(caughtException).IsInstanceOf <InvalidOperationException>();
            Check.That(immutableMultiDictionary).IsEqualTo(creator.Create(Dictionaries.Entry(1, "A")));
        }
Esempio n. 3
0
        public void ShouldExtendReadOnlyDictionaryByEntriesMethod()
        {
            // given
            var dictionary = Dictionaries.CreateImmutable("A", "A1", "B", "B1", "C", "C1");

            // when
            var entries = dictionary.Entries();

            // then
            Check.That(entries).HasSize(3);
            Check.That(entries).Contains(
                Dictionaries.Entry("A", "A1"),
                Dictionaries.Entry("B", "B1"),
                Dictionaries.Entry("C", "C1"));
        }
Esempio n. 4
0
        public void ShouldExtendDictionaryByPutAllMethod()
        {
            // given
            var dictionary = new Dictionary <int, string>();

            // when
            dictionary.PutAll(Lists.AsList(Dictionaries.Entry(1, "1"), Dictionaries.Entry(2, "2")))
            .PutAll(Dictionaries.Entry(3, "3"), Dictionaries.Entry(4, "4"));

            // then
            Check.That(dictionary).HasSize(4);
            Check.That(dictionary.Keys).Contains(1, 2, 3, 4);
            Check.That(dictionary[1]).IsEqualTo("1");
            Check.That(dictionary[2]).IsEqualTo("2");
            Check.That(dictionary[3]).IsEqualTo("3");
            Check.That(dictionary[4]).IsEqualTo("4");
        }
        public void ShouldCreateDictionaryFromEntries()
        {
            // given
            var entries = new []
            {
                Dictionaries.Entry(1, "A"),
                Dictionaries.Entry(2, "B"),
                Dictionaries.Entry(3, "C")
            };

            // when
            var dictionary = Dictionaries.CreateFromEntries(entries);

            // then
            Check.That(dictionary).HasSize(3);
            Check.That(dictionary).Contains(entries);
        }
Esempio n. 6
0
        public void ShouldReturnImmutableMultiDictionaryEntries(ImmutableMultiDictionaryCreator creator)
        {
            // given
            var entires = Lists.AsList(
                Dictionaries.Entry(1, "A"),
                Dictionaries.Entry(1, "B"),
                Dictionaries.Entry(1, "C"),
                Dictionaries.Entry(2, "A"),
                Dictionaries.Entry(3, "C"));
            var immutableMultiDictionary = creator.Create(entires.ToArray());

            // when
            var result = immutableMultiDictionary.Entries;

            // then
            Check.That(immutableMultiDictionary.Count).IsEqualTo(entires.Count);
            Check.That(result).HasSize(entires.Count).And.Contains(entires.ToArray());
        }
Esempio n. 7
0
        public void ShouldReturnEntriesInPutOrder()
        {
            // given
            var dictionary = OrderedHashImmutableDictionary <string, int> .Builder()
                             .Put("Z", 1)
                             .Put("Y", 2)
                             .Put("X", 3)
                             .Build();

            // when
            var orderedEntries = dictionary.OrderedEntries;

            // then
            Check.That(orderedEntries).ContainsExactly(
                Dictionaries.Entry("Z", 1),
                Dictionaries.Entry("Y", 2),
                Dictionaries.Entry("X", 3));
        }
Esempio n. 8
0
        public void ShouldReturnImmutableMultiDictionaryValuesForKey(ImmutableMultiDictionaryCreator creator)
        {
            // given
            var immutableMultiDictionary = creator.Create
                                               (Dictionaries.Entry("A", "B"),
                                               Dictionaries.Entry("A", "C"),
                                               Dictionaries.Entry("A", "D"));

            // when
            var keyValues  = immutableMultiDictionary["A"];
            var keyValues2 = immutableMultiDictionary.Get("A");

            // then
            Check.That(keyValues).HasSize(3).And.Contains("B", "C", "D");
            Check.That(keyValues2).HasSize(3).And.Contains("B", "C", "D");

            Check.That(keyValues is IReadOnlyCollection <string>).IsTrue();
            Check.That(keyValues2 is IReadOnlyCollection <string>).IsTrue();
        }
Esempio n. 9
0
        public void ShouldPreventImmutableMultiDictionaryValuesReplacement(ImmutableMultiDictionaryCreator creator)
        {
            // given
            var immutableMultiDictionary = creator.Create(
                Dictionaries.Entry(1, "A"),
                Dictionaries.Entry(1, "B"),
                Dictionaries.Entry(1, "C"));

            // when
            var result = Try.To(() => immutableMultiDictionary.ReplaceValues(1, Lists.AsList("X", "Y")));

            // then
            var caughtException = result.IsFailure ? result.Error : null;

            Check.That(caughtException).IsNotNull();
            Check.That(caughtException).IsInstanceOf <InvalidOperationException>();
            Check.That(immutableMultiDictionary).IsEqualTo(creator.Create(
                                                               Dictionaries.Entry(1, "A"),
                                                               Dictionaries.Entry(1, "B"),
                                                               Dictionaries.Entry(1, "C")));
        }
Esempio n. 10
0
        public void ShouldReturnImmutableMultiDictionaryMultiEntries(ImmutableMultiDictionaryCreator creator)
        {
            // given
            var entires = Lists.AsList(
                Dictionaries.Entry(1, "A"),
                Dictionaries.Entry(1, "B"),
                Dictionaries.Entry(1, "C"),
                Dictionaries.Entry(2, "A"),
                Dictionaries.Entry(3, "C"));
            var immutableMultiDictionary = creator.Create(entires.ToArray());

            // when
            var result = immutableMultiDictionary.MultiEntries;

            // then
            var mutliEntriesDictionary = result.ToDictionary(element => element.Key, element => element.Value);

            Check.That(immutableMultiDictionary.Count).IsEqualTo(entires.Count);
            Check.That(result).HasSize(3);
            Check.That(mutliEntriesDictionary.Keys).HasSize(3).And.Contains(1, 2, 3);
            Check.That(mutliEntriesDictionary[1]).HasSize(3).And.Contains("A", "B", "C");
            Check.That(mutliEntriesDictionary[2]).HasSize(1).And.Contains("A");
            Check.That(mutliEntriesDictionary[3]).HasSize(1).And.Contains("C");
        }
Esempio n. 11
0
        public void ShouldPutValuesIntoCompositeDictionary(CompositeDictionaryCreator creator)
        {
            // given
            var compositeDictionary = creator.Create <string, int, string>();

            // when
            compositeDictionary.Put("A", 1, "A1");
            compositeDictionary.Put("A", 2, "A2");
            compositeDictionary.Put("A", 3, "A3");
            compositeDictionary.Put("B", 1, "B1");
            compositeDictionary.PutAll(Dictionaries.Create(
                                           "C", Dictionaries.Create(1, "C1", 2, "C2"),
                                           "D", Dictionaries.Create(1, "D1", 2, "D2")));

            // then
            Check.That(compositeDictionary.Count).IsEqualTo(8);
            Check.That(compositeDictionary.PrimaryKeysCount).IsEqualTo(4);
            Check.That(compositeDictionary.IsEmpty).IsFalse();
            Check.That(compositeDictionary.Get("A", 1)).IsEqualTo("A1");
            Check.That(compositeDictionary[CompositeKeys.Of("A", 2)]).IsEqualTo("A2");
            Check.That(compositeDictionary.Get(CompositeKeys.Of("A", 3))).IsEqualTo("A3");
            Check.That(compositeDictionary.Get("B", 1)).IsEqualTo("B1");
            Check.That(compositeDictionary.Get("C", 1)).IsEqualTo("C1");
            Check.That(compositeDictionary.Get("C", 2)).IsEqualTo("C2");
            Check.That(compositeDictionary.Get("D", 1)).IsEqualTo("D1");
            Check.That(compositeDictionary.Get("D", 2)).IsEqualTo("D2");

            Check.That(compositeDictionary.Values).HasSize(8).And
            .Contains("A1", "A2", "A3", "B1", "C1", "C2", "D1", "D2");

            Check.That(compositeDictionary.Entries).HasSize(8).And.Contains(
                Dictionaries.Entry("A", Dictionaries.Entry(1, "A1")),
                Dictionaries.Entry("A", Dictionaries.Entry(2, "A2")),
                Dictionaries.Entry("A", Dictionaries.Entry(3, "A3")),
                Dictionaries.Entry("B", Dictionaries.Entry(1, "B1")),
                Dictionaries.Entry("C", Dictionaries.Entry(1, "C1")),
                Dictionaries.Entry("C", Dictionaries.Entry(2, "C2")),
                Dictionaries.Entry("D", Dictionaries.Entry(1, "D1")),
                Dictionaries.Entry("D", Dictionaries.Entry(2, "D2")));

            Check.That(compositeDictionary.PrimaryKeys).HasSize(4).And
            .Contains("A", "B", "C", "D");
            Check.That(compositeDictionary.SecondaryKeys).HasSize(3).And
            .Contains(1, 2, 3);

            Check.That(compositeDictionary.PrimaryKeyEntries("A")).HasSize(3).And
            .Contains(Dictionaries.Entry(1, "A1"), Dictionaries.Entry(2, "A2"), Dictionaries.Entry(3, "A3"));
            Check.That(compositeDictionary.PrimaryKeyEntries("B")).HasSize(1).And
            .Contains(Dictionaries.Entry(1, "B1"));
            Check.That(compositeDictionary.PrimaryKeyEntries("C")).HasSize(2).And
            .Contains(Dictionaries.Entry(1, "C1"), Dictionaries.Entry(2, "C2"));
            Check.That(compositeDictionary.PrimaryKeyEntries("D")).HasSize(2).And
            .Contains(Dictionaries.Entry(1, "D1"), Dictionaries.Entry(2, "D2"));
            Check.That(compositeDictionary.PrimaryKeyValues("A")).HasSize(3).And.Contains("A1", "A2", "A3");
            Check.That(compositeDictionary.PrimaryKeyValues("B")).HasSize(1).And.Contains("B1");
            Check.That(compositeDictionary.PrimaryKeyValues("C")).HasSize(2).And.Contains("C1", "C2");
            Check.That(compositeDictionary.PrimaryKeyValues("D")).HasSize(2).And.Contains("D1", "D2");

            Check.That(compositeDictionary.SecondaryKeyEntries(1)).HasSize(4).And
            .Contains(Dictionaries.Entry("A", "A1"), Dictionaries.Entry("B", "B1"),
                      Dictionaries.Entry("C", "C1"), Dictionaries.Entry("D", "D1"));
            Check.That(compositeDictionary.SecondaryKeyEntries(2)).HasSize(3).And
            .Contains(Dictionaries.Entry("A", "A2"), Dictionaries.Entry("C", "C2"), Dictionaries.Entry("D", "D2"));
            Check.That(compositeDictionary.SecondaryKeyEntries(3)).HasSize(1).And
            .Contains(Dictionaries.Entry("A", "A3"));
            Check.That(compositeDictionary.SecondaryKeyValues(1)).HasSize(4).And.Contains("A1", "B1", "C1", "D1");
            Check.That(compositeDictionary.SecondaryKeyValues(2)).HasSize(3).And.Contains("A2", "C2", "D2");
            Check.That(compositeDictionary.SecondaryKeyValues(3)).HasSize(1).And.Contains("A3");
        }