-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add unit test for freeredis bus
- Loading branch information
Showing
3 changed files
with
103 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 24 additions & 23 deletions
47
tests/EasyCaching.Bus.FreeRedis.Tests/EasyCaching.Bus.FreeRedis.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,31 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="EasyCaching.BaseTest" Version="1.9.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" /> | ||
<PackageReference Include="xunit" Version="2.4.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.2.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="EasyCaching.BaseTest" Version="1.9.0" /> | ||
<PackageReference Include="EasyCaching.Serialization.Json" Version="1.9.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" /> | ||
<PackageReference Include="xunit" Version="2.4.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.2.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\EasyCaching.Bus.FreeRedis\EasyCaching.Bus.FreeRedis.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\EasyCaching.Bus.FreeRedis\EasyCaching.Bus.FreeRedis.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
103 changes: 79 additions & 24 deletions
103
tests/EasyCaching.Bus.FreeRedis.Tests/FreeRedisCachingBusTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,94 @@ | ||
using Castle.DynamicProxy.Generators; | ||
using EasyCaching.Core.Bus; | ||
using FreeRedis; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace EasyCaching.Bus.FreeRedis.Tests | ||
namespace EasyCaching.Bus.FreeRedis.Tests; | ||
|
||
public class FreeRedisCachingBusTest | ||
{ | ||
public class FreeRedisCachingBusTest | ||
{ | ||
|
||
public FreeRedisCachingBusTest() | ||
private const string Topic = "test-topic"; | ||
private IEasyCachingBus _bus; | ||
|
||
public FreeRedisCachingBusTest() | ||
{ | ||
IServiceCollection services = new ServiceCollection(); | ||
services.AddEasyCaching(option => | ||
{ | ||
|
||
} | ||
option.WithFreeRedisBus(config => | ||
{ | ||
config.ConnectionStrings = new List<ConnectionStringBuilder> | ||
{ | ||
"192.168.3.86:6379,defaultDatabase=6,poolsize=10" | ||
}; | ||
config.SerializerName = "json"; | ||
}); | ||
option.WithJson("json"); | ||
}); | ||
|
||
[Fact] | ||
public void WithFreeRedisBus_Connectioned_Should_Succeed() | ||
{ | ||
IServiceCollection services = new ServiceCollection(); | ||
IServiceProvider serviceProvider = services.BuildServiceProvider(); | ||
|
||
_bus = serviceProvider.GetService<IEasyCachingBus>()!; | ||
} | ||
|
||
|
||
[Fact] | ||
public void WithFreeRedisBus_Connectioned_Should_Succeed() | ||
{ | ||
IServiceCollection services = new ServiceCollection(); | ||
|
||
services.AddEasyCaching(option => | ||
services.AddEasyCaching(option => | ||
{ | ||
option.WithFreeRedisBus(config => | ||
{ | ||
option.WithFreeRedisBus(config => | ||
config.ConnectionStrings = new List<ConnectionStringBuilder> | ||
{ | ||
config.ConnectionStrings = new List<ConnectionStringBuilder> | ||
{ | ||
"192.168.3.86:6379,defaultDatabase=6,poolsize=10" | ||
}; | ||
config.SerializerName = "json"; | ||
}); | ||
"192.168.3.86:6379,defaultDatabase=6,poolsize=10" | ||
}; | ||
}); | ||
IServiceProvider serviceProvider = services.BuildServiceProvider(); | ||
var client = serviceProvider.GetService<EasyCachingFreeRedisClient>(); | ||
Assert.NotNull(client); | ||
}); | ||
IServiceProvider serviceProvider = services.BuildServiceProvider(); | ||
var client = serviceProvider.GetService<EasyCachingFreeRedisClient>(); | ||
Assert.NotNull(client); | ||
|
||
var flag = client.Ping(); | ||
Assert.Equal("PONG", flag); | ||
} | ||
|
||
[Fact] | ||
public async Task Publish_Msg_Should_Succeed() | ||
{ | ||
var message = new EasyCachingMessage | ||
{ | ||
Id = Guid.NewGuid().ToString("N"), | ||
CacheKeys = new string[] { "freeredis:bus:cachekey" } | ||
}; | ||
await _bus.PublishAsync(Topic, message); | ||
|
||
Assert.True(true); | ||
} | ||
|
||
[Fact] | ||
public async Task Publish_Msg_And_Subscribe_Should_Succeed() | ||
{ | ||
var sendMsgCachkey = "freeredis:bus:cachekey"; | ||
var message = new EasyCachingMessage | ||
{ | ||
Id = Guid.NewGuid().ToString("N"), | ||
CacheKeys = new string[] { sendMsgCachkey } | ||
}; | ||
var getMsgCachkey = string.Empty; | ||
await _bus.SubscribeAsync(Topic, | ||
msg => | ||
{ | ||
getMsgCachkey = msg.CacheKeys[0]; | ||
}, | ||
() => { }); | ||
|
||
var flag = client.Ping(); | ||
Assert.Equal("PONG", flag); | ||
} | ||
await _bus.PublishAsync(Topic, message); | ||
await Task.Delay(1000); | ||
Assert.Equal(sendMsgCachkey, getMsgCachkey); | ||
} | ||
} |