Skip to content

Commit 3b17dbf

Browse files
committed
Upgrades dependencies and modernizes async test patterns
- Replaces `MessagePack` with `Foundatio.MessagePack` and upgrades `Foundatio.Redis` to v12 - Updates test tooling (xunit, coverlet, Shouldly) to latest versions - Converts `.GetAwaiter().GetResult()` calls to proper `async/await` in tests - Cleans up README placeholder text
1 parent 1b0798c commit 3b17dbf

7 files changed

Lines changed: 57 additions & 53 deletions

File tree

Neolution.Extensions.Caching.Distributed/Neolution.Extensions.Caching.Distributed.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="MessagePack" Version="2.5.198" />
10+
<PackageReference Include="Foundatio.MessagePack" Version="12.0.0" />
1111
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="6.0.0" />
1212
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
1313
<PackageReference Include="Neolution.CodeAnalysis" Version="2.6.1">

Neolution.Extensions.Caching.RedisHybrid/MsgPackSerializer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public MsgPackSerializer(bool enableCompression)
4343
/// <returns>The deserialized object</returns>
4444
public object Deserialize(Stream data, Type objectType)
4545
{
46-
return MessagePackSerializer.Deserialize(objectType, data, this.options)
47-
?? throw new InvalidOperationException($"Deserialization returned null for type '{objectType}'.");
46+
return MessagePack.MessagePackSerializer.Deserialize(objectType, data, this.options)
47+
?? throw new InvalidOperationException($"Deserialization returned null for type '{objectType}'.");
4848
}
4949

5050
/// <summary>
@@ -59,7 +59,7 @@ public void Serialize(object value, Stream output)
5959
throw new ArgumentNullException(nameof(value));
6060
}
6161

62-
MessagePackSerializer.Serialize(value.GetType(), output, value, this.options);
62+
MessagePack.MessagePackSerializer.Serialize(value.GetType(), output, value, this.options);
6363
}
6464
}
6565
}

Neolution.Extensions.Caching.RedisHybrid/Neolution.Extensions.Caching.RedisHybrid.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Foundatio.Redis" Version="10.6.0" />
11-
<PackageReference Include="MessagePack" Version="2.5.198" />
10+
<PackageReference Include="Foundatio.MessagePack" Version="12.0.0" />
11+
<PackageReference Include="Foundatio.Redis" Version="12.0.0" />
1212
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
1313
<PackageReference Include="Neolution.CodeAnalysis" Version="2.6.1">
1414
<PrivateAssets>all</PrivateAssets>

Neolution.Extensions.Caching.UnitTests/DistributedCacheAsyncTests.cs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
using System;
44
using System.Threading;
5+
using System.Threading.Tasks;
56
using Microsoft.Extensions.DependencyInjection;
67
using Neolution.Extensions.Caching.Abstractions;
78
using Neolution.Extensions.Caching.UnitTests.Models;
@@ -18,31 +19,33 @@ public class DistributedCacheAsyncTests
1819
/// Tests if created objects can be retrieved again from the cache.
1920
/// </summary>
2021
/// <param name="services">The service collection.</param>
22+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
2123
[Theory]
2224
[ClassData(typeof(ServiceCollectionTestDataCollection))]
23-
public void CreatedObjectCanBeRetrievedAgain(IServiceCollection services)
25+
public async Task CreatedObjectCanBeRetrievedAgain(IServiceCollection services)
2426
{
2527
using var serviceProvider = services.BuildServiceProvider();
2628
const string cacheObject = "Hello World!";
2729

2830
// Act
2931
var cache = GetCache(serviceProvider);
30-
cache.SetAsync(TestCacheId.Foobar, cacheObject).GetAwaiter().GetResult();
31-
cache.GetAsync<string>(TestCacheId.Foobar).GetAwaiter().GetResult();
32-
cache.SetAsync(TestCacheId.Foobar, cacheObject).GetAwaiter().GetResult();
33-
cache.GetAsync<string>(TestCacheId.Foobar).GetAwaiter().GetResult();
32+
await cache.SetAsync(TestCacheId.Foobar, cacheObject);
33+
await cache.GetAsync<string>(TestCacheId.Foobar);
34+
await cache.SetAsync(TestCacheId.Foobar, cacheObject);
35+
await cache.GetAsync<string>(TestCacheId.Foobar);
3436

3537
// Assert
36-
cache.GetAsync<string>(TestCacheId.Foobar).GetAwaiter().GetResult().ShouldBe(cacheObject);
38+
(await cache.GetAsync<string>(TestCacheId.Foobar)).ShouldBe(cacheObject);
3739
}
3840

3941
/// <summary>
4042
/// Tests if created objects can be retrieved again from the cache.
4143
/// </summary>
4244
/// <param name="serviceCollection">The service collection.</param>
45+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
4346
[Theory]
4447
[ClassData(typeof(ServiceCollectionTestDataCollection))]
45-
public void CreatedObjectWithKeyCanBeRetrievedAgain(IServiceCollection serviceCollection)
48+
public async Task CreatedObjectWithKeyCanBeRetrievedAgain(IServiceCollection serviceCollection)
4649
{
4750
// Assign
4851
using var serviceProvider = serviceCollection.BuildServiceProvider();
@@ -52,40 +55,42 @@ public void CreatedObjectWithKeyCanBeRetrievedAgain(IServiceCollection serviceCo
5255

5356
// Act
5457
var cache = GetCache(serviceProvider);
55-
cache.SetAsync(TestCacheId.Foobar, key, cacheObject).GetAwaiter().GetResult();
58+
await cache.SetAsync(TestCacheId.Foobar, key, cacheObject);
5659

5760
// Assert
58-
cache.GetAsync<string>(TestCacheId.Foobar, key).GetAwaiter().GetResult().ShouldBe(cacheObject);
61+
(await cache.GetAsync<string>(TestCacheId.Foobar, key)).ShouldBe(cacheObject);
5962
}
6063

6164
/// <summary>
6265
/// Tests if removed object cannot be retrieved again from the cache.
6366
/// </summary>
6467
/// <param name="serviceCollection">The service collection.</param>
68+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
6569
[Theory]
6670
[ClassData(typeof(ServiceCollectionTestDataCollection))]
67-
public void RemovedObjectCannotBeRetrievedAgain(IServiceCollection serviceCollection)
71+
public async Task RemovedObjectCannotBeRetrievedAgain(IServiceCollection serviceCollection)
6872
{
6973
// Assign
7074
using var serviceProvider = serviceCollection.BuildServiceProvider();
7175
const string cacheObject = "Hello World!";
7276

7377
// Act
7478
var cache = GetCache(serviceProvider);
75-
cache.SetAsync(TestCacheId.Foobar, cacheObject).GetAwaiter().GetResult();
76-
cache.RemoveAsync(TestCacheId.Foobar).GetAwaiter().GetResult();
79+
await cache.SetAsync(TestCacheId.Foobar, cacheObject);
80+
await cache.RemoveAsync(TestCacheId.Foobar);
7781

7882
// Assert
79-
cache.GetAsync<string>(TestCacheId.Foobar).GetAwaiter().GetResult().ShouldBeNull();
83+
(await cache.GetAsync<string>(TestCacheId.Foobar)).ShouldBeNull();
8084
}
8185

8286
/// <summary>
8387
/// Tests if removed object cannot be retrieved again from the cache.
8488
/// </summary>
8589
/// <param name="serviceCollection">The service collection.</param>
90+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
8691
[Theory(Skip = "Refresh is removed from interface (no strong use-case)")]
8792
[ClassData(typeof(ServiceCollectionTestDataCollection))]
88-
public void RefreshedObjectDidNotExpire(IServiceCollection serviceCollection)
93+
public async Task RefreshedObjectDidNotExpire(IServiceCollection serviceCollection)
8994
{
9095
// Assign
9196
using var serviceProvider = serviceCollection.BuildServiceProvider();
@@ -99,21 +104,21 @@ public void RefreshedObjectDidNotExpire(IServiceCollection serviceCollection)
99104
var cache = GetCache(serviceProvider);
100105

101106
// Add two objects to cache, both with a sliding expiration of 1000ms
102-
cache.SetWithOptionsAsync(TestCacheId.Foobar, cacheObject, options).GetAwaiter().GetResult();
103-
cache.SetWithOptionsAsync(TestCacheId.NonRefreshedFoobar, cacheObject, options).GetAwaiter().GetResult();
107+
await cache.SetWithOptionsAsync(TestCacheId.Foobar, cacheObject, options);
108+
await cache.SetWithOptionsAsync(TestCacheId.NonRefreshedFoobar, cacheObject, options);
104109

105110
// After a wait of 500ms, refresh only one of the objects.
106111
Thread.Sleep(TimeSpan.FromMilliseconds(500));
107112

108-
//cache.RefreshAsync(TestCacheId.Foobar).GetAwaiter().GetResult()
113+
//await cache.RefreshAsync(TestCacheId.Foobar)
109114

110115
// After a wait of 750ms, one of the objects should now be expired because its at least 1250ms (500+750) old at the moment.
111116
// But the refreshed object should still be valid for roughly another 250ms.
112117
Thread.Sleep(TimeSpan.FromMilliseconds(750));
113118

114119
// Assert
115-
cache.GetAsync<string>(TestCacheId.Foobar).GetAwaiter().GetResult().ShouldBe(cacheObject);
116-
cache.GetAsync<string>(TestCacheId.NonRefreshedFoobar).GetAwaiter().GetResult().ShouldBeNull();
120+
(await cache.GetAsync<string>(TestCacheId.Foobar)).ShouldBe(cacheObject);
121+
(await cache.GetAsync<string>(TestCacheId.NonRefreshedFoobar)).ShouldBeNull();
117122
}
118123

119124
/// <summary>

Neolution.Extensions.Caching.UnitTests/Neolution.Extensions.Caching.UnitTests.csproj

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,24 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="coverlet.msbuild" Version="3.2.0">
10+
<PackageReference Include="coverlet.msbuild" Version="8.0.0">
1111
<PrivateAssets>all</PrivateAssets>
1212
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1313
</PackageReference>
14-
<PackageReference Include="Foundatio" Version="10.6.0" />
15-
<PackageReference Include="Foundatio.Redis" Version="10.6.0" />
16-
<PackageReference Include="Foundatio.Xunit" Version="10.6.0" />
14+
<PackageReference Include="Foundatio.Xunit" Version="12.0.0" />
1715
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="6.0.2" />
18-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
19-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
16+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
2017
<PackageReference Include="Neolution.CodeAnalysis.TestsRuleset" Version="2.6.1">
2118
<PrivateAssets>all</PrivateAssets>
2219
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2320
</PackageReference>
24-
<PackageReference Include="Shouldly" Version="4.1.0" />
25-
<PackageReference Include="xunit" Version="2.4.2" />
26-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
21+
<PackageReference Include="Shouldly" Version="4.3.0" />
22+
<PackageReference Include="xunit" Version="2.9.3" />
23+
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
2724
<PrivateAssets>all</PrivateAssets>
2825
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2926
</PackageReference>
30-
<PackageReference Include="coverlet.collector" Version="3.2.0">
27+
<PackageReference Include="coverlet.collector" Version="8.0.0">
3128
<PrivateAssets>all</PrivateAssets>
3229
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3330
</PackageReference>

Neolution.Extensions.Caching.UnitTests/RedisHybridCacheTests.cs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace Neolution.Extensions.Caching.UnitTests
22
{
33
using System;
4+
using System.Threading.Tasks;
45
using Foundatio.Caching;
56
using Foundatio.Xunit;
67
using Microsoft.Extensions.DependencyInjection;
@@ -30,8 +31,9 @@ public RedisHybridCacheTests(ITestOutputHelper outputHelper)
3031
/// <summary>
3132
/// Tests if created objects can be retrieved again from the cache.
3233
/// </summary>
34+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
3335
[Fact(Skip = "Activate as soon as we spin up a local Redis instance")]
34-
public void CreatedObjectCanBeRetrievedAgain()
36+
public async Task CreatedObjectCanBeRetrievedAgain()
3537
{
3638
// Assign
3739
var services = this.CreateServiceCollection();
@@ -45,31 +47,32 @@ public void CreatedObjectCanBeRetrievedAgain()
4547
var cache = GetCache(serviceProvider);
4648

4749
logger.LogInformation("Before Setting Foobar");
48-
cache.SetAsync(TestCacheId.Foobar, cacheObject + 11).GetAwaiter().GetResult();
50+
await cache.SetAsync(TestCacheId.Foobar, cacheObject + 11);
4951
logger.LogInformation("After Setting Foobar");
5052

5153
logger.LogInformation("Before Getting Foobar");
52-
cache.GetAsync<string>(TestCacheId.Foobar).GetAwaiter().GetResult();
54+
await cache.GetAsync<string>(TestCacheId.Foobar);
5355
logger.LogInformation("After Getting Foobar");
5456

5557
logger.LogInformation("Before ReSetting Foobar");
56-
cache.SetAsync(TestCacheId.Foobar, cacheObject).GetAwaiter().GetResult();
58+
await cache.SetAsync(TestCacheId.Foobar, cacheObject);
5759
logger.LogInformation("After ReSetting Foobar");
5860

5961
logger.LogInformation("Before ReGetting Foobar");
60-
cache.GetAsync<string>(TestCacheId.Foobar).GetAwaiter().GetResult();
62+
await cache.GetAsync<string>(TestCacheId.Foobar);
6163
logger.LogInformation("After ReGetting Foobar");
6264

6365
// Assert
6466
logger.LogInformation("Next value should come from Cache");
65-
cache.GetAsync<string>(TestCacheId.Foobar).GetAwaiter().GetResult().ShouldBe(cacheObject);
67+
(await cache.GetAsync<string>(TestCacheId.Foobar)).ShouldBe(cacheObject);
6668
}
6769

6870
/// <summary>
6971
/// Tests if created objects can be retrieved again from the cache.
7072
/// </summary>
73+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
7174
[Fact(Skip = "Activate as soon as we spin up a local Redis instance")]
72-
public void CreatedObjectWithKeyCanBeRetrievedAgain()
75+
public async Task CreatedObjectWithKeyCanBeRetrievedAgain()
7376
{
7477
// Assign
7578
var services = this.CreateServiceCollection();
@@ -80,17 +83,18 @@ public void CreatedObjectWithKeyCanBeRetrievedAgain()
8083

8184
// Act
8285
var cache = GetCache(serviceProvider);
83-
cache.SetAsync(TestCacheId.Foobar, key, cacheObject).GetAwaiter().GetResult();
86+
await cache.SetAsync(TestCacheId.Foobar, key, cacheObject);
8487

8588
// Assert
86-
cache.GetAsync<string>(TestCacheId.Foobar, key).GetAwaiter().GetResult().ShouldBe(cacheObject);
89+
(await cache.GetAsync<string>(TestCacheId.Foobar, key)).ShouldBe(cacheObject);
8790
}
8891

8992
/// <summary>
9093
/// Tests if removed object cannot be retrieved again from the cache.
9194
/// </summary>
95+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
9296
[Fact(Skip = "Activate as soon as we spin up a local Redis instance")]
93-
public void RemovedObjectCannotBeRetrievedAgain()
97+
public async Task RemovedObjectCannotBeRetrievedAgain()
9498
{
9599
// Assign
96100
var services = this.CreateServiceCollection();
@@ -99,11 +103,11 @@ public void RemovedObjectCannotBeRetrievedAgain()
99103

100104
// Act
101105
var cache = GetCache(serviceProvider);
102-
cache.SetAsync(TestCacheId.Foobar, cacheObject).GetAwaiter().GetResult();
103-
cache.RemoveAsync(TestCacheId.Foobar).GetAwaiter().GetResult();
106+
await cache.SetAsync(TestCacheId.Foobar, cacheObject);
107+
await cache.RemoveAsync(TestCacheId.Foobar);
104108

105109
// Assert
106-
cache.GetAsync<string>(TestCacheId.Foobar).GetAwaiter().GetResult().ShouldBeNull();
110+
(await cache.GetAsync<string>(TestCacheId.Foobar)).ShouldBeNull();
107111
}
108112

109113
/// <summary>
@@ -123,7 +127,7 @@ private static IDistributedCache<TestCacheId> GetCache(IServiceProvider serviceP
123127
private IServiceCollection CreateServiceCollection()
124128
{
125129
var services = new ServiceCollection();
126-
this.Log.MinimumLevel = LogLevel.Trace;
130+
this.Log.DefaultLogLevel = LogLevel.Trace;
127131
services.AddSingleton<ILoggerFactory>(this.Log);
128132
services.AddRedisHybridCache("localhost", options =>
129133
{

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
# Introduction
2-
TODO: Give a short introduction of your project. Let this section explain the objectives or the motivation behind this project.
1+
# Introduction
32

43
A type-safe caching abstraction library for .NET that uses enum-based cache identifiers instead of magic strings.
54

65
# Build and Test
7-
TODO: Describe and show how to build your code and run the tests.
86

97
- **Strongly-Typed Cache Keys**: Use enums instead of magic strings for cache identifiers, providing compile-time safety and IntelliSense support
108
- **Multiple Implementations**:
@@ -451,4 +449,4 @@ This project uses [GitVersion](https://gitversion.net/) for semantic versioning
451449

452450
## Support
453451

454-
For issues, questions, or contributions, please use the GitHub issue tracker.
452+
For issues, questions, or contributions, please use the GitHub issue tracker.

0 commit comments

Comments
 (0)