public void ShouldPutEntriesFromMultiDictionary(MultiDictionaryContext context) { // given var multiDictionary = context.Create <int, string>(); multiDictionary.PutAll(1, context.CollectionOf("E", "F")); multiDictionary.Put(3, "R"); var anotherMultiDictionary = new ArrayListMultiDictionary <int, string>(); anotherMultiDictionary.PutAll(1, Lists.AsList("A", "B", "C")); anotherMultiDictionary.PutAll(2, Lists.AsList("X", "Y", "Z")); anotherMultiDictionary.PutAll(3, Lists.AsList("Q", "W", "E")); // when multiDictionary.PutAll(anotherMultiDictionary); // then Check.That(multiDictionary.Count).IsEqualTo(12); Check.That(multiDictionary.Values).HasSize(12); Check.That(multiDictionary.Values).Contains( "A", "B", "C", "E", "F", "Q", "W", "E", "R", "X", "Y", "Z"); Check.That(multiDictionary[1]).HasSize(5).And.Contains("A", "B", "C", "E", "F"); Check.That(multiDictionary[2]).HasSize(3).And.Contains("X", "Y", "Z"); Check.That(multiDictionary[3]).HasSize(4).And.Contains("Q", "W", "E", "R"); }
/// <summary> /// Converts dictionary to ArrayListMultiDictionary. /// </summary> /// <typeparam name="TKey">Type of dictionary key</typeparam> /// <typeparam name="TValue">Type of dictionary value</typeparam> /// <param name="source">this</param> /// <returns>ArrayListMultiDictionary</returns> public static ArrayListMultiDictionary <TKey, TValue> ToArrayListMultiDictionary <TKey, TValue>( this IReadOnlyDictionary <TKey, TValue> source) { Preconditions.IsNotNull(source, () => new ArgumentNullException("source")); var result = new ArrayListMultiDictionary <TKey, TValue>(); result.PutAll(source); return(result); }
public void ShouldConvertArrayListMultiDictionaryToImmutable() { // given var multiDictionary = new ArrayListMultiDictionary <int, string>(); multiDictionary.Put(1, "A"); multiDictionary.PutAll(2, Lists.AsList("A", "B", "B")); multiDictionary.PutAll(3, Lists.AsList("X", "Y")); // when var immutableMultiDictionary = multiDictionary.ToImmutableMultiDictionary(); // then Check.That(immutableMultiDictionary).IsInstanceOf <ImmutableListMultiDictionary <int, string> >(); Check.That(immutableMultiDictionary).IsEqualTo(ImmutableListMultiDictionary <int, string> .Of( 1, "A", 2, "A", 2, "B", 2, "B", 3, "X", 3, "Y")); }
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)); }
public void ShouldAllowDuplicatedValuesForKey() { // given var multiDictionary = new ArrayListMultiDictionary<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<List<string>>(); Check.That(multiDictionary[2]).ContainsExactly("A", "B", "B"); Check.That(multiDictionary[2]).IsInstanceOf<List<string>>(); }
public void ShouldConvertMultiDictionaryToDictionaryWithArrayLists() { // given var multiDictionary = new ArrayListMultiDictionary<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<List<string>>() .And.ContainsExactly("A"); Check.That(dictionary[2]).IsInstanceOf<List<string>>() .And.ContainsExactly("B"); Check.That(dictionary[3]).IsInstanceOf<List<string>>() .And.ContainsExactly("A", "B", "C", "C"); }