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 @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
15 changes: 14 additions & 1 deletion csharp-linq/LookupInCSharp/LookupInCSharp/LookupOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,17 @@ public static bool SearchForKeyInLookup(string key)

public static int GetLookupCount()
=> _lookup.Count;
}

public static (int FromGroupBy, int FromLookup) CountValuesAfterSourceChanges(
string key, Student newStudent)
{
List<Student> students = [.. _students];

var grouped = students.GroupBy(s => s.Name, s => s.Course);
var lookup = students.ToLookup(s => s.Name, s => s.Course);

students.Add(newStudent);

return (grouped.Single(g => g.Key == key).Count(), lookup[key].Count());
}
}
20 changes: 19 additions & 1 deletion csharp-linq/LookupInCSharp/Tests/LookupOperationsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,22 @@ public void WhenGetLookupCountIsCalled_ThenReturnsTheLookupCount()

Assert.Equal(3, count);
}
}

[Fact]
public void GivenKeyThatDoesNotExist_WhenRetrieveValuesOfAKeyFromLookupIsCalled_ThenReturnsEmpty()
{
var values = LookupOperations.RetrieveValuesOfAKeyFromLookup("Michael Sorla");

Assert.Empty(values);
}

[Fact]
public void GivenSourceChangesAfterTheCall_WhenCountValuesAfterSourceChangesIsCalled_ThenOnlyGroupBySeesTheChange()
{
var (fromGroupBy, fromLookup) = LookupOperations.CountValuesAfterSourceChanges(
"Kate Green", new Student("Kate Green", "Taxation"));

Assert.Equal(2, fromGroupBy);
Assert.Equal(1, fromLookup);
}
}
10 changes: 5 additions & 5 deletions csharp-linq/LookupInCSharp/Tests/Tests.csproj
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 All @@ -10,10 +10,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
<PackageReference Include="coverlet.collector" Version="10.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.11.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="4.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading