public void ShouldBuildImmutableListMultiDictionaryAndReturnImmutableListValues() { // given var immutableListMultiDictionary = ImmutableListMultiDictionary <int, string> .Builder() .Put(1, "A") .Put(1, "A") .Put(1, "B") .PutAll(2, Lists.AsList("X", "Y", "Z")) .PutAll(ArrayListMultiDictionary <int, string> .Of(3, "Z", 3, "W")) .PutAll(Dictionaries.Create(4, "_")) .Build(); // when var values1 = immutableListMultiDictionary[1]; var values2 = immutableListMultiDictionary.Get(2); var values3 = immutableListMultiDictionary.Get(3); var values4 = immutableListMultiDictionary[4]; // then Check.That(values1).HasSize(3).And.Contains("A", "B").And.IsInstanceOf <ImmutableList <string> >(); Check.That(values1.DistinctElementCount()).IsEqualTo(Dictionaries.Create("A", 2, "B", 1)); Check.That(values2).HasSize(3).And.Contains("X", "Y", "Z").And.IsInstanceOf <ImmutableList <string> >(); Check.That(values2.DistinctElementCount()).IsEqualTo(Dictionaries.Create("X", 1, "Y", 1, "Z", 1)); Check.That(values3).HasSize(2).And.Contains("Z", "W").And.IsInstanceOf <ImmutableList <string> >(); Check.That(values3.DistinctElementCount()).IsEqualTo(Dictionaries.Create("Z", 1, "W", 1)); Check.That(values4).HasSize(1).And.Contains("_").And.IsInstanceOf <ImmutableList <string> >(); Check.That(values4.DistinctElementCount()).IsEqualTo(Dictionaries.Create("_", 1)); }
public void ShouldExtendEnumberableByToMultiDictionaryMethodWithoutValueConverter() { // given IEnumerable <int> enumerable = Lists.AsList(1, 2, 3); Converter <int, string> keyConverter = element => element.ToString(); // when var multiDictionary = enumerable.ToMultiDictionary(keyConverter); // then Check.That(multiDictionary).IsEqualTo(ArrayListMultiDictionary <string, int> .Of("1", 1, "2", 2, "3", 3)); }
public void ShouldExntedReadOnlyDictionaryByToArrayListMultiDictionaryMethod() { // given var dictionary = Dictionaries.CreateImmutable("A", "A1", "B", "B1", "C", "C1"); // when var multiDictionary = dictionary.ToArrayListMultiDictionary(); // then Check.That(multiDictionary) .IsEqualTo(ArrayListMultiDictionary <string, string> .Of("A", "A1", "B", "B1", "C", "C1")); }
public void ShouldPreventImmutableMultiDictionaryPutAllMultiEntries(ImmutableMultiDictionaryCreator creator) { // given var immutableMultiDictionary = creator.Create <int, string>(); var entries = ArrayListMultiDictionary <int, string> .Of(1, "A", 1, "B", 2, "A"); // when var result = Try.To(() => immutableMultiDictionary.PutAll(entries)); // then var caughtException = result.IsFailure ? result.Error : null; Check.That(caughtException).IsNotNull(); Check.That(caughtException).IsInstanceOf <InvalidOperationException>(); Check.That(immutableMultiDictionary).IsEqualTo(creator.Create <int, string>()); }
public void ShouldReturImmutableMultiDictionaryValues(ImmutableMultiDictionaryCreator creator) { // given var immutableMultiDictionary = creator.Create(ArrayListMultiDictionary <int, string> .Of( 1, "A", 1, "B", 1, "C", 2, "A", 3, "C", 3, "X").Entries.ToArray()); // when var values = immutableMultiDictionary.Values; // then Check.That(immutableMultiDictionary.Count).IsEqualTo(6); Check.That(values).HasSize(6).And.Contains("A", "B", "C", "X"); Check.That(Objects.Equal(values.DistinctElementCount(), Dictionaries.Create("A", 2, "B", 1, "C", 2, "X", 1))) .IsTrue(); Check.That(values is IReadOnlyCollection <string>).IsTrue(); }