Skip to content

Commit

Permalink
Fie: test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Anson.G authored and Anson.G committed May 7, 2022
1 parent 1c870ae commit a8dad5a
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 32 deletions.
4 changes: 2 additions & 2 deletions EasyCache.InMemory/Drivers/MultiBucketsMemoryCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public Task Delete(string key)
{
if (key.First() == '*')
{
key = key.Substring(1, key.Length);
key = key.Substring(1, key.Length - 1);
}
else if (key.Last() == '*')
{
Expand Down Expand Up @@ -106,7 +106,7 @@ private ConcurrentDictionary<string, CacheItem> GetBucket(uint bucketId)
{
return bucket;
}

throw new Exception($"Not Found Bucket: {bucketId}");
}

Expand Down
2 changes: 1 addition & 1 deletion EasyCache.Redis/Driver/RedisCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Task Delete(string key)
{
if (key.First() == '*')
{
key = key.Substring(1, key.Length);
key = key.Substring(1, key.Length - 1);
}
else if (key.Last() == '*')
{
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# NetCoreCache.Extensions.Redis

[![Build Status](https://github.com/sj-distributor/EasyCache/actions/workflows/dotnet.yml/badge.svg?branch=main)](https://github.com/sj-distributor/EasyCache/actions?query=branch%3Amain)
[![codecov](https://codecov.io/gh/sj-distributor/EasyCache/branch/master/graph/badge.svg?token=XV3W873RGV)](https://codecov.io/gh/sj-distributor/core-cache.Extensions.Redis)
[![Build Status](https://github.com/sj-distributor/EasyCache/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/sj-distributor/EasyCache/actions?query=branch%3Amaster)
[![codecov](https://codecov.io/gh/sj-distributor/EasyCache/branch/master/graph/badge.svg?token=XV3W873RGV)](https://codecov.io/gh/sj-distributor/EasyCache)
[![NuGet version (NetCoreCache)](https://img.shields.io/nuget/v/NetCoreCacheRedis.svg?style=flat-square)](https://www.nuget.org/packages/NetCoreCacheRedis/)
![](https://img.shields.io/badge/license-MIT-green)

Expand Down
1 change: 1 addition & 0 deletions TestApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseServiceProviderFactory(new DynamicProxyServiceProviderFactory());
builder.Services.AddMultiBucketsInMemoryCache();
// builder.Services.AddInMemoryCache();

builder.Services.RegisterServices();

Expand Down
7 changes: 0 additions & 7 deletions TestApi/Service/UserService.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using EasyCache.Core.Attributes;
using TestApi.DB;
using TestApi.Entity;
using TestApi.Utils;

namespace TestApi.Service;

Expand Down Expand Up @@ -55,10 +54,4 @@ public virtual IEnumerable<User> List(string page)
Thread.Sleep(TimeSpan.FromSeconds(1));
return _dbContext.Set<User>().ToList();
}

[Cacheable("users", "{number}")]
public virtual IEnumerable<User> Performance(string number)
{
return DataUtils.GetData();
}
}
18 changes: 0 additions & 18 deletions TestApi/Utils/DataUtils.cs

This file was deleted.

18 changes: 17 additions & 1 deletion UnitTests/MulitBucketsMemoryCacheTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public async void TestMemoryCacheCanDelete(string key, string value, string resu
[Theory]
[InlineData("anson555", "18", null)]
[InlineData("anson555555", "19", null)]
public async void TestMemoryCacheCanDeleteByPattern(string key, string value, string result)
public async void TestMemoryCacheCanDeleteByFirstPattern(string key, string value, string result)
{
await _memoryCache.Set(key, new CacheItem()
{
Expand All @@ -94,6 +94,22 @@ public async void TestMemoryCacheCanDeleteByPattern(string key, string value, st
Assert.Equal(s.Value, result);
}


[Theory]
[InlineData("555Joe", "18", null)]
[InlineData("555555Joe", "19", null)]
public async void TestMemoryCacheCanDeleteByLastPattern(string key, string value, string result)
{
await _memoryCache.Set(key, new CacheItem()
{
Value = value,
Expire = DateTime.Now.AddSeconds(20).Ticks
});
await _memoryCache.Delete("*Joe");
var s = await _memoryCache.Get(key);
Assert.Equal(s.Value, result);
}

[Theory]
[InlineData("ansonExpire11", "18", null)]
[InlineData("ansonExpire22", "19", null)]
Expand Down
16 changes: 15 additions & 1 deletion UnitTests/RedisCacheTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public async void TestRedisCacheCanDelete(string key, string value, string resul
[Theory]
[InlineData("anson1111", "18", null)]
[InlineData("anson2222", "19", null)]
public async void TestRedisCacheCanDeleteByPattern(string key, string value, string result)
public async void TestRedisCacheCanDeleteByLastPattern(string key, string value, string result)
{
await _redisClient.Set(key, new CacheItem()
{
Expand All @@ -71,4 +71,18 @@ public async void TestRedisCacheCanDeleteByPattern(string key, string value, str
var s = await _redisClient.Get(key);
Assert.Equal(s.Value, result);
}

[Theory]
[InlineData("1111Joe", "18", null)]
[InlineData("2222Joe", "19", null)]
public async void TestRedisCacheCanDeleteByFirstPattern(string key, string value, string result)
{
await _redisClient.Set(key, new CacheItem()
{
Value = value,
});
await _redisClient.Delete("*Joe");
var s = await _redisClient.Get(key);
Assert.Equal(s.Value, result);
}
}

0 comments on commit a8dad5a

Please sign in to comment.