Skip to content

Commit 8f8ea9e

Browse files
Refactor structure, add tests, and improve cache API
- Move main library to AspNetCoreCacheKit folder; add AspNetCoreCacheKit.Tests project with xUnit tests - Make Set methods generic for type safety in CacheService and ICacheService - Move NullCacheEntry to its own file and make it internal - Fix key composition logic and improve argument validation - Update DI extension and project packaging metadata - Add test helper and comprehensive unit tests for all cache scenarios
1 parent d17572d commit 8f8ea9e

10 files changed

Lines changed: 486 additions & 22 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<IsPackable>false</IsPackable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="coverlet.collector" Version="6.0.2" />
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
13+
<PackageReference Include="xunit" Version="2.9.2" />
14+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<ProjectReference Include="..\AspNetCoreCacheKit\AspNetCoreCacheKit.csproj" />
19+
</ItemGroup>
20+
21+
<ItemGroup>
22+
<Using Include="Xunit" />
23+
</ItemGroup>
24+
25+
</Project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using AspNetCoreCacheKit.Models;
2+
using Microsoft.Extensions.Caching.Memory;
3+
using Microsoft.Extensions.Options;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace AspNetCoreCacheKit.Tests.Helpers
11+
{
12+
internal static class CacheServiceFactory
13+
{
14+
public static CacheService Create(
15+
bool isEnabled = true,
16+
int durationMinutes = 60,
17+
Dictionary<string, int>? groupDurations = null)
18+
{
19+
var memoryCache = new MemoryCache(new MemoryCacheOptions());
20+
21+
var options = Options.Create(new CacheOptions
22+
{
23+
IsEnabled = isEnabled,
24+
DurationMinutes = durationMinutes,
25+
GroupDurations = groupDurations ?? []
26+
});
27+
28+
return new CacheService(memoryCache, options);
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)