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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- uses: actions/checkout@v6
- uses: actions/setup-dotnet@v5
- run: dotnet build /p:TreatWarningsAsErrors=true
- run: dotnet test --no-build --logger 'junit' /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura
- run: dotnet test --no-build --logger 'junit' /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:ExcludeByFile='**/*.g.cs'
- uses: test-summary/action@v2
if: always()
with:
Expand Down
20 changes: 0 additions & 20 deletions src/Riok.Mapperly/Helpers/DictionaryExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,12 @@
using System.Diagnostics.CodeAnalysis;

namespace Riok.Mapperly.Helpers;

public static class DictionaryExtensions
{
public static bool Remove<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key, [MaybeNullWhen(false)] out TValue value)
{
if (!dict.TryGetValue(key, out value))
return false;

dict.Remove(key);
return true;
}

public static void RemoveRange<TKey, TValue>(this IDictionary<TKey, TValue> dict, IEnumerable<TKey> keys)
{
foreach (var key in keys)
{
dict.Remove(key);
}
}

public static bool TryAdd<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key, TValue value)
{
if (dict.ContainsKey(key))
return false;

dict.Add(key, value);
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
</ItemGroup>
<!-- ef core tests should only run on newer .NET versions -->
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.11" Condition="'$(TargetFramework)' == 'net8.0'" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.7" Condition="'$(TargetFramework)' == 'net9.0'" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.1" Condition="'$(TargetFramework)' == 'net10.0'" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.23" Condition="'$(TargetFramework)' == 'net8.0'" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.12" Condition="'$(TargetFramework)' == 'net9.0'" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.2" Condition="'$(TargetFramework)' == 'net10.0'" />
</ItemGroup>
<!-- cannot use source generated polyfills since they require language version 11 -->
<ItemGroup Condition="'$(TargetFramework)' == 'net48'">
Expand Down
38 changes: 0 additions & 38 deletions test/Riok.Mapperly.Tests/Helpers/DictionaryExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,8 @@

namespace Riok.Mapperly.Tests.Helpers;

// can't use extension methods due to ambiguous method reference.
// (no support for this method in netstandard2.0)
public class DictionaryExtensionsTest
{
[Fact]
public void RemoveShouldReturnTrueWhenKeyWasRemoved()
{
var d = new Dictionary<string, int> { ["a"] = 10, ["b"] = 20 };
DictionaryExtensions.Remove(d, "a", out var value).ShouldBeTrue();
value.ShouldBe(10);
}

[Fact]
public void RemoveShouldReturnFalseWhenKeyWasNotRemoved()
{
var d = new Dictionary<string, int> { ["a"] = 10, ["b"] = 20 };
DictionaryExtensions.Remove(d, "c", out var value).ShouldBeFalse();
value.ShouldBe(0);
}

[Fact]
public void RemoveRangeShouldRemoveEntries()
{
Expand All @@ -34,24 +16,4 @@ public void RemoveRangeShouldRemoveEntries()
d.RemoveRange(["a", "c"]);
d.Keys.ShouldBe(["b"]);
}

[Fact]
public void TryAddShouldNotAddExistingKey()
{
var d = new Dictionary<string, int> { ["a"] = 10 };

d.TryAdd("a", 20).ShouldBeFalse();

d["a"].ShouldBe(10);
}

[Fact]
public void TryAddShouldAddNewKey()
{
var d = new Dictionary<string, int> { ["a"] = 10 };

d.TryAdd("b", 20).ShouldBeTrue();

d["b"].ShouldBe(20);
}
}