Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,26 @@ public void WhenUsingSelectManyToFlattenTheCollectionAndSubCollections_ThenColle
Assert.That(detailedListOfEmployees[4], Is.EqualTo("Cedric | Development | Developer"));
Assert.That(detailedListOfEmployees[5], Is.EqualTo("Monica | BackOffice | HumanResources"));
}

[Test]
public void WhenProjectingACollectionProperty_ThenSelectNestsAndSelectManyFlattens()
{
var employeeLists = _listOfDepartments.Select(d => d.Employees); // IEnumerable<List<Employee>>
var employees = _listOfDepartments.SelectMany(d => d.Employees); // IEnumerable<Employee>

Assert.That(employeeLists.Count(), Is.EqualTo(3));
Assert.That(employees.Count(), Is.EqualTo(6));
}

[Test]
public void WhenUsingASecondFromClauseInQuerySyntax_ThenItTranslatesToSelectMany()
{
var employees = from department in _listOfDepartments
from employee in department.Employees
select employee;

var flattenedWithSelectMany = _listOfDepartments.SelectMany(department => department.Employees);

Assert.That(employees, Is.EqualTo(flattenedWithSelectMany));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand Down
Loading