Skip to content

Commit 333c130

Browse files
committed
Enhance caching and CI/CD setup
- Added Microsoft.Extensions.Caching and Promact.Core packages to Promact.Caching.Test.csproj. - Removed obsolete UnitTest1.cs file. - Enabled package generation in Promact.Caching.csproj. - Introduced a GitHub Actions workflow for CI/CD to NuGet. - Added RedisCacheTests for Redis distributed cache testing.
1 parent ad92c43 commit 333c130

File tree

5 files changed

+91
-11
lines changed

5 files changed

+91
-11
lines changed

.github/workflows/build-deploy.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: .NET to NuGet
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
tags:
7+
- '*'
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Setup .NET
17+
uses: actions/setup-dotnet@v4
18+
with:
19+
dotnet-version: '8.0.x' # Replace with your .NET version
20+
21+
- name: Restore dependencies
22+
run: dotnet restore
23+
24+
- name: Build
25+
run: dotnet build --no-restore --configuration Release
26+
27+
- name: Test
28+
run: dotnet test --no-build
29+
30+
- name: Pack
31+
run: dotnet pack --no-build --output nupkg
32+
33+
- name: Push to NuGet
34+
run: dotnet nuget push ./nupkg/*.nupkg --api-key ${{ secrets.NUGET_PUBLISH_API }} --source https://api.nuget.org/v3/index.json

Promact.Caching/Promact.Caching.Test/Promact.Caching.Test.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,17 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12+
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" />
13+
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.6" />
1214
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
1315
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
1416
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
1517
<PackageReference Include="coverlet.collector" Version="3.1.2" />
18+
<PackageReference Include="Promact.Core" Version="1.0.0.2" />
19+
</ItemGroup>
20+
21+
<ItemGroup>
22+
<ProjectReference Include="..\Promact.Caching\Promact.Caching.csproj" />
1623
</ItemGroup>
1724

1825
</Project>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using Microsoft.Extensions.Caching.Distributed;
2+
using Microsoft.Extensions.Caching.StackExchangeRedis;
3+
using Promact.Core.Caching;
4+
5+
6+
namespace Promact.Caching.Test
7+
{
8+
[TestClass]
9+
public class RedisCacheTests
10+
{
11+
private IDistributedCache _distributedCache;
12+
private ICachingService _cacheService;
13+
private string[] _keys = new string[] { "TestKey1", "TestKey2", "TestKey3" };
14+
[TestInitialize]
15+
public void Setup()
16+
{
17+
_distributedCache = new RedisCache(new RedisCacheOptions
18+
{
19+
Configuration = "localhost:6379"
20+
});
21+
22+
_cacheService = new DistributedCachingServices(_distributedCache);
23+
}
24+
25+
[TestMethod]
26+
public void AddDataSuccessTest()
27+
{
28+
var data = new TestData() { Name = "Test", Age = 20 };
29+
_cacheService.Set("TestKey1", data);
30+
31+
var result = _cacheService.Get<TestData>("TestKey1");
32+
Assert.IsNotNull(result);
33+
Assert.AreEqual(data.Name, result.Name);
34+
Assert.AreEqual(data.Age, result.Age);
35+
}
36+
37+
[TestCleanup]
38+
public void CleanUp()
39+
{
40+
_keys.ToList().ForEach(key => _cacheService.Remove(key));
41+
}
42+
}
43+
44+
internal class TestData
45+
{
46+
public string Name { get; set; }
47+
public int Age { get; set; }
48+
}
49+
}

Promact.Caching/Promact.Caching.Test/UnitTest1.cs

Lines changed: 0 additions & 11 deletions
This file was deleted.

Promact.Caching/Promact.Caching/Promact.Caching.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<TargetFramework>net6.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7+
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
78
</PropertyGroup>
89

910
<ItemGroup>

0 commit comments

Comments
 (0)