public static void Eagerly_throws_ArgumentNullException_when_sequence_is_null_with_equality_comparer() { IEnumerable<char> nullSequence = null; IEqualityComparer<char> stringLengthEqualityComparer = new StringLengthEqualityComparer<char>(); Assert.Throws<ArgumentNullException>(() => nullSequence.Without(stringLengthEqualityComparer, 'c')); }
public static void Eagerly_throws_ArgumentNullException_when_elements_to_remove_collection_is_null_with_equality_comparer() { IEnumerable<char> letters = "abcd"; IEqualityComparer<char> stringLengthEqualityComparer = new StringLengthEqualityComparer<char>(); Assert.Throws<ArgumentNullException>(() => letters.Without(stringLengthEqualityComparer, null)); }
public static void Does_not_remove_elements_that_do_not_match_the_passed_element_but_each_other() { IEnumerable<string> fruits = new[] { "apple", "apricot", "banana", "cherry" }; const string elementToRemove = "apricot"; IEqualityComparer<string> stringLengthEqualityComparer = new StringLengthEqualityComparer<string>(); IEnumerable<string> fruitsWithoutElement = fruits.Without(stringLengthEqualityComparer, elementToRemove); fruitsWithoutElement.Should().NotContain("apricot"); fruitsWithoutElement.Should().HaveCount(3); }
private static void ToLookup() { Console.WriteLine("\n ToLookup"); Console.WriteLine(" Employees in lookup, key is id:"); foreach (var employeeGroup in employees.ToLookup(e => e.id)) { foreach (var employee in employeeGroup) { Console.WriteLine($"Key {employeeGroup.Key.ToString().PadRight(10)} Value {employee}"); } } Console.WriteLine(" Employees in lookup, key is id, firstname is selector:"); foreach (var employeeGroup in employees.ToLookup(e => e.id, e => e.firstName)) { foreach (var employee in employeeGroup) { Console.WriteLine($"Key {employeeGroup.Key.ToString().PadRight(10)} Value {employee}"); } } Console.WriteLine(" Employees in lookup, key is firstName, lastName is selector, String length compare:"); foreach (var employeeGroup in employees.ToLookup(e => e.firstName, e => e.lastName, new StringLengthEqualityComparer())) { if (StringLengthEqualityComparer.IsSmall(employeeGroup.Key)) { Console.WriteLine($" Small first name length:"); } else { Console.WriteLine($" Big first name length:"); } foreach (var employee in employeeGroup) { Console.WriteLine($"Key {employeeGroup.Key.ToString().PadRight(10)} Value {employee}"); } } }
public static void Returns_sequence_without_elements_equal_to_passed_element() { IEnumerable<string> fruits = new[] { "apple", "apricot", "banana", "cherry" }; const string elementToRemove = "banana"; IEqualityComparer<string> stringLengthEqualityComparer = new StringLengthEqualityComparer<string>(); fruits = fruits.Without(stringLengthEqualityComparer, elementToRemove); fruits.Should().NotContain("banana"); fruits.Should().NotContain("cherry"); fruits.Should().HaveCount(2); }
public static void Returns_unmodified_sequence_when_sequence_does_not_contain_any_element_to_remove_with_equality_comparer() { IEnumerable<string> stringNumbers = new[] { "1", "22", "333", "4444" }; const string elementToRemove = "55555"; IEqualityComparer<string> stringLengthEqualityComparer = new StringLengthEqualityComparer<string>(); stringNumbers = stringNumbers.Without(stringLengthEqualityComparer, elementToRemove); stringNumbers.Should().HaveCount(4); }
private static void GroupBy() { Console.WriteLine("\n GroupBy"); Console.WriteLine(" Entries grouped by id"); foreach (var entrieGroup in employeesOptionEntries.GroupBy(e => e.id)) { Console.WriteLine($" Group id = {entrieGroup.Key}"); foreach (var entrie in entrieGroup) { entrie.Print(); } } Console.WriteLine(" Employees grouped by firstName <= 5 and firstname > 5"); foreach (var employeeGroup in employees.GroupBy(e => e.firstName, new StringLengthEqualityComparer())) { if (StringLengthEqualityComparer.IsSmall(employeeGroup.Key)) { Console.WriteLine($" Small first name length:"); } else { Console.WriteLine($" Big first name length:"); } foreach (var employee in employeeGroup) { employee.Print(); } } Console.WriteLine(" Date awarded for employees"); foreach (var entrieGroup in employeesOptionEntries.GroupBy(e => e.id, o => o.dateAwarded)) { employees.Where(e => e.id == entrieGroup.Key).FirstOrDefault().Print(); foreach (var entrie in entrieGroup) { Console.WriteLine(entrie); } } Console.WriteLine(" Date awarded for employees with firstname <= 5 and firstName > 5"); var employeesAndTheirOptionEntries = employees.Join(employeesOptionEntries, e => e.id, e => e.id, (e, o) => new { employee = e, employeeOptionEntry = o }); foreach (var group in employeesAndTheirOptionEntries.GroupBy(x => x.employee.firstName, x => x.employeeOptionEntry.dateAwarded, new StringLengthEqualityComparer())) { if (StringLengthEqualityComparer.IsSmall(group.Key)) { Console.WriteLine($" Small first name length:"); } else { Console.WriteLine($" Big first name length:"); } foreach (var date in group.OrderBy(x => x)) { Console.WriteLine(date); } } }