public void ShouldPutMultipleValuesForKey(MultiDictionaryContext context) { // given var multiDictionary = context.Create <int, string>(); // when multiDictionary.Put(1, "A"); multiDictionary.Put(1, "B"); multiDictionary.Put(1, "C"); multiDictionary.Put(2, "A"); multiDictionary.PutAll(3, Lists.AsList("X", "Y", "Z")); // then Check.That(multiDictionary.Count).IsEqualTo(7); Check.That(multiDictionary.Values).HasSize(7); Check.That(multiDictionary.Values).Contains("A", "B", "C", "A", "X", "Y", "Z"); Check.That(multiDictionary.Get(1)).ContainsExactly("A", "B", "C"); Check.That(multiDictionary.ValuesCount(1)).IsEqualTo(3); Check.That(multiDictionary.Get(2)).ContainsExactly("A"); Check.That(multiDictionary.ValuesCount(2)).IsEqualTo(1); Check.That(multiDictionary[3]).ContainsExactly("X", "Y", "Z"); Check.That(multiDictionary.ValuesCount(3)).IsEqualTo(3); }
public void RetunedCollectionsShouldNotAffectDictionary(MultiDictionaryContext context) { // given var multiDictionary = context.Create <int, string>(); multiDictionary.PutAll(1, Lists.AsList("X", "Y", "Z")); multiDictionary.PutAll(2, Lists.AsList("A", "B")); var keys = multiDictionary.Keys; var values = multiDictionary.Values; var key1Values = multiDictionary.Get(1); var key2Values = multiDictionary[2]; // when keys.Clear(); values.Clear(); key1Values.Remove("Y"); key2Values.Remove("B"); // then Check.That(multiDictionary.Keys).HasSize(2); Check.That(multiDictionary.Keys).Contains(1, 2); Check.That(multiDictionary.Values).HasSize(5); Check.That(multiDictionary.Values).Contains("X", "Y", "Z", "A", "B"); Check.That(multiDictionary.Get(1)).ContainsExactly("X", "Y", "Z"); Check.That(multiDictionary.Get(2)).ContainsExactly("A", "B"); }
private static IEnumerable <ITestCaseData> ToStringTestCases() { yield return(new TestCaseData("test") .SetName("Should return string") .Returns("test")); yield return(new TestCaseData(null) .SetName("Should generate toString of null object") .Returns("null")); yield return(new TestCaseData(new List <int?> { 1, 2, null, 3 }) .SetName("Should generate toString of collection") .Returns("[1, 2, null, 3]")); yield return(new TestCaseData(Lists.EmptyList <int>()) .SetName("Should generate toString of empty collection") .Returns("[]")); yield return(new TestCaseData((object)new object[] { "A", "B", 3, 4 }) .SetName("Should generate toString of array") .Returns("[A, B, 3, 4]")); yield return(new TestCaseData(Dictionaries.Create("A", 1, "B", 2, "C", 3)) .SetName("Should generate toString of dictionary") .Returns("[(A, 1), (B, 2), (C, 3)]")); yield return(new TestCaseData(Dictionaries.Create( "A", Lists.AsList(Lists.AsList(1, 2, 3), Lists.AsList(4, 5, 6)), "B", Lists.AsList(Lists.AsList(1), Lists.AsList(2)), "C", Lists.AsList(Lists.EmptyList <int>(), null))) .SetName("Should generate toString of complex dictionary") .Returns("[(A, [[1, 2, 3], [4, 5, 6]]), (B, [[1], [2]]), (C, [[], null])]")); }
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")); }
private static IEnumerable <ITestCaseData> StringFormatTestCases() { yield return(new TestCaseData("test", new object[0]) .SetName("Should format string without params") .Returns("test")); yield return(new TestCaseData("This is '{0}'", new object[] { null }) .SetName("Should format null params") .Returns("This is 'null'")); yield return(new TestCaseData("{0}, {1}, {2}", new object[] { 1, "B", null }) .SetName("Should format multiple params") .Returns("1, B, null")); yield return(new TestCaseData("This is {0}", new object[] { Lists.AsList(1, 2, 3) }) .SetName("Should format list params") .Returns("This is [1, 2, 3]")); yield return(new TestCaseData("This is {0}", new object[] { Lists.AsList(Lists.AsList("A", "B"), Lists.AsList("C", "D"), Lists.EmptyList <string>()) }) .SetName("Should format nested list params") .Returns("This is [[A, B], [C, D], []]")); yield return(new TestCaseData("This is {0}", new object[] { Dictionaries.Create("A", 1, "B", 2) }) .SetName("Should format dictionary params") .Returns("This is [(A, 1), (B, 2)]")); }
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"); }
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 ShouldExtendImmutableListByMinusMethod() { // given IImmutableList <int> list = ImmutableList.CreateRange(Lists.AsList(1, 2, 3, 4, 4)); // when var result = list.Minus(Lists.AsList(1, 3, 4)); // then Check.That(result).ContainsExactly(2); }
public void ShouldConvertSetToComparable() { // given ISet <string> enumerable = new HashSet <string>(new [] { "A", "B", "C" }); // when var comparable = enumerable.ToComparable(); // then Check.That(comparable).IsEqualTo(Lists.AsList("C", "B", "A")); }
public void ShouldExtendImmutableListByPlusMethod() { // given IImmutableList <string> list = ImmutableList.CreateRange(Lists.AsList("A", "B")); // when var result = list.Plus(Lists.AsList("B", "C", "D")); // then Check.That(result).ContainsExactly("A", "B", "B", "C", "D"); }
public void ShouldExtenedEnumerableByToSetMethod() { // given IEnumerable <int> enumerable = Lists.AsList(1, 2, 3, 3, 3, 4, 5); // then var set = enumerable.ToSet(); // then Check.That(set).HasSize(5); Check.That(set).Contains(1, 2, 3, 4, 5); }
public void ShouldExtendListByAddAllMethod() { // given IList <string> list = new List <string>(); // when list.AddAll(Lists.AsList("A", "B", "C")); list.AddAll("D", "E", "F"); // then Check.That(list).ContainsExactly("A", "B", "C", "D", "E", "F"); }
private static IEnumerable <TestCaseData> NullSafeListTestCases() { yield return(new TestCaseData((IList <string>)null) .SetName("Should create empty list for null") .Returns(Lists.EmptyMutableList <string>())); var notNullList = Lists.AsList("A", "B"); yield return(new TestCaseData(notNullList) .SetName("Should return given list if not null") .Returns(notNullList)); }
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 ShouldExtendImmutableSetByMinusMethod() { // given IImmutableSet <int> set = ImmutableHashSet.CreateRange(Lists.AsList(1, 2, 3)); // when var result = set.Minus(Lists.AsList(1, 3, 4)); // then Check.That(result).HasSize(1); Check.That(result).Contains(2); }
public void ShouldExtendImmutableSetByPlusMethod() { // given IImmutableSet <string> set = ImmutableHashSet.CreateRange(Lists.AsList("A", "B")); // when var result = set.Plus(Lists.AsList("B", "C", "D")); // then Check.That(result).HasSize(4); Check.That(result).Contains("A", "B", "C", "D"); }
public void ShouldExtendSetByAddAllMethod() { // given ISet <string> set = new HashSet <string>(); // when set.AddAll(Lists.AsList("A", "B", "C")); set.AddAll("D", "E", "F"); // then Check.That(set).HasSize(6); Check.That(set).Contains("A", "B", "C", "D", "E", "F"); }
public void ShouldExtendArrayEnumerableByContainsAllMethod() { // given IEnumerable array = new object[] { 1, "A", "X" }; // when var containsAll1 = array.ContainsAll(Lists.AsList("A", "X")); var containsAll2 = array.ContainsAll(Lists.AsList("A", "X", "B")); // then Check.That(containsAll1).IsTrue(); Check.That(containsAll2).IsFalse(); }
public void ShouldBuildToStringFromFields() { // given var obj = new TestObj2(age: 30, surname: "Testowski", data: Lists.AsList("A", "B", "C")); // when var toString = ToStringHelper.Of(obj) .AddFields() .ToString(); // then Check.That(toString).IsEqualTo("TestObj2 {age:30, surname:Testowski, data:[A, B, C]}"); }
public void ShouldExtendListByPlusMethod() { // given IList <string> list = new List <string> { "A", "B" }; // when var result = list.Plus(Lists.AsList("B", "C", "D")); // then Check.That(result).ContainsExactly("A", "B", "B", "C", "D"); }
public void ShouldConvertCollectionToComparable() { // given ICollection <string> enumerable = new[] { "A", "B", "C" }; // when var comparable = enumerable.ToComparable(); // then Check.That(comparable).IsEqualTo(Lists.AsList("A", "B", "C")); Check.That(comparable.GetHashCode()).IsEqualTo(enumerable.ToComparable().GetHashCode()); Check.That(comparable.ToString()).IsEqualTo("[A, B, C]"); }
public void ShouldExtenedLinkedListByFindAllMethod() { // given IEnumerable <int> list = Lists.AsLinkedList(Lists.AsList(1, 2, 3, 4)); Predicate <int> filter = item => item % 2 == 0; // when var filtered = list.FindAll(filter); // then Check.That(filtered).IsInstanceOf <LinkedList <int> >(); Check.That(filtered).ContainsExactly(2, 4); }
public void ShouldExtenedEnumerableByDistinctElementCountMethod() { // given var set = Sets.AsSet("A", "B", "C"); var list = Lists.AsList("A", "B", "B", "B", "C", "C", "D", "D", "D", "D"); // when var setDistinctElementsCount = set.DistinctElementCount(); var listDistinctElementsCount = list.DistinctElementCount(); // then Check.That(setDistinctElementsCount).IsEqualTo(Dictionaries.Create("A", 1, "B", 1, "C", 1)); Check.That(listDistinctElementsCount).IsEqualTo(Dictionaries.Create("A", 1, "B", 3, "C", 2, "D", 4)); }
public void ShouldExtendSetByPlusMethod() { // given ISet <string> set = new HashSet <string> { "A", "B" }; // when var result = set.Plus(Lists.AsList("B", "C", "D")); // then Check.That(result).HasSize(4); Check.That(result).Contains("A", "B", "C", "D"); }
public void ShouldPassIsCollectionNotEmptyEvaluationWithMessage() { // given const string errorMessage = "Collection cannot be empty"; IEnumerable <int> enumerable = Lists.AsList(1, 2, 3); // when var result = Try.To(() => Preconditions.IsNotEmpty(enumerable, errorMessage)); // then var caughtException = result.IsFailure ? result.Error : null; Check.That(caughtException).IsNull(); }
public void ShouldPreventImmutableMultiDictionaryPutAllKeyEntries(ImmutableMultiDictionaryCreator creator) { // given var immutableMultiDictionary = creator.Create <int, string>(); // when var result = Try.To(() => immutableMultiDictionary.PutAll(1, Lists.AsList("A", "B", "C"))); // 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 ShouldExtendSetByRemoveAllMethod() { // given ISet <string> set = new HashSet <string> { "A", "B", "C", "D", "E", "F" }; // when set.RemoveAll(Lists.AsList("A", "B")); set.RemoveAll("E", "F"); // then Check.That(set).HasSize(2); Check.That(set).Contains("C", "D"); }
public void ShouldReplaceKeyValues(MultiDictionaryContext context) { // given var multiDictionary = context.Create <string, int>(); multiDictionary.PutAll("A", Lists.AsList(1, 2, 3, 4)); // when var replaced = multiDictionary.ReplaceValues("A", Lists.AsList(5, 6)); // when Check.That(multiDictionary.Count).IsEqualTo(2); Check.That(replaced).ContainsExactly(1, 2, 3, 4); Check.That(multiDictionary.Get("A")).ContainsExactly(5, 6); }
public void ShouldThrowExceptionOnIsSingletonEvaluationWithMessage() { // given const string errorMessage = "Collection must contains only one element"; IEnumerable <string> enumerable = Lists.AsList("A", "B"); // when var result = Try.To(() => Preconditions.IsSingleton(enumerable, errorMessage)); // then var caughtException = result.IsFailure ? result.Error : null; Check.That(caughtException).IsNotNull(); Check.That(caughtException).IsInstanceOf <ArgumentException>(); Check.That(caughtException.Message).IsEqualTo(errorMessage); }
public void ShouldThrowExceptionOnIsCollectionEmptyEvaluationWithMessage() { // given const string errorMessage = "Collection must be empty"; IEnumerable <int> enumerable = Lists.AsList(1); // when var result = Try.To(() => Preconditions.IsEmpty(enumerable, errorMessage)); // then var caughtException = result.IsFailure ? result.Error : null; Check.That(caughtException).IsNotNull(); Check.That(caughtException).IsInstanceOf <ArgumentException>(); Check.That(caughtException.Message).IsEqualTo(errorMessage); }