Skip to content

Commit 20c317c

Browse files
committed
Add StackExchange.Redis.Extensions Test
1 parent c314f81 commit 20c317c

File tree

8 files changed

+293
-104
lines changed

8 files changed

+293
-104
lines changed

src/.editorconfig

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ dotnet_analyzer_diagnostic.severity = warning
8888
# dotnet_analyzer_diagnostic.category-Naming.severity = warning
8989
dotnet_analyzer_diagnostic.category-Performance.severity = error
9090
# dotnet_analyzer_diagnostic.category-SingleFile.severity = warning
91-
# dotnet_analyzer_diagnostic.category-Reliability.severity = warning
92-
# dotnet_analyzer_diagnostic.category-Security.severity = warning
91+
dotnet_analyzer_diagnostic.category-Reliability.severity = error
92+
dotnet_analyzer_diagnostic.category-Security.severity = error
9393
# dotnet_analyzer_diagnostic.category-Style.severity = warning
9494
# dotnet_analyzer_diagnostic.category-Usage.severity = warning
9595

@@ -551,7 +551,7 @@ dotnet_diagnostic.IDE0047.severity = suggestion
551551
# IDE0049: 简化名称
552552
dotnet_diagnostic.IDE0049.severity = suggestion
553553

554-
# IDE0051: Remove unused private members,关闭,防止 cleanup 自动删除成员
554+
# IDE0051: Remove unused private members,改为 suggestion 防止 cleanup 自动删除成员并保留灰色,使用 S1144 警告
555555
dotnet_diagnostic.IDE0051.severity = suggestion
556556

557557
# IDE0054: 使用复合分配
@@ -572,7 +572,7 @@ dotnet_diagnostic.IDE0061.severity = suggestion
572572
# 使结构字段可写,不要使用可写字段
573573
dotnet_diagnostic.IDE0064.severity = error
574574
# 结构可以使用字段
575-
dotnet_code_quality.ca1051.exclude_structs = true
575+
dotnet_code_quality.CA1051.exclude_structs = true
576576

577577
# IDE0072: Add missing cases
578578
dotnet_diagnostic.IDE0072.severity = error
@@ -728,6 +728,12 @@ dotnet_diagnostic.CS8847.severity = error
728728
#### performance warnings ####
729729
# https://learn.microsoft.com/zh-cn/dotnet/fundamentals/code-analysis/quality-rules/performance-warnings
730730

731+
# CA1815:重写值类型上的 Equals 和相等运算符 改为 none 防止 cleanup 自动,使用 S3898 警告
732+
dotnet_diagnostic.CA1815.severity = none
733+
734+
# CA1822: Mark members as static 改为 none 防止 cleanup 自动 static,使用 S2325 警告
735+
dotnet_diagnostic.CA1822.severity = none
736+
731737
# CA1848: Use the LoggerMessage delegates
732738
dotnet_diagnostic.CA1848.severity = warning
733739

@@ -742,6 +748,9 @@ dotnet_diagnostic.CS1998.severity = error
742748
# CS4014: 由于此调用不会等待,因此在调用完成前将继续执行当前方法
743749
dotnet_diagnostic.CS4014.severity = error
744750

751+
# 在适用处使用属性
752+
dotnet_diagnostic.CA1024.severity = suggestion
753+
745754
# CA1715: Identifiers should have correct prefix
746755
dotnet_diagnostic.CA1715.severity = none
747756

@@ -901,6 +910,7 @@ dotnet_diagnostic.S1133.severity = warning
901910
dotnet_diagnostic.S1134.severity = warning
902911
dotnet_diagnostic.S1135.severity = warning
903912
dotnet_diagnostic.S114.severity = warning
913+
# Unused private types or members should be removed
904914
dotnet_diagnostic.S1144.severity = warning
905915
dotnet_diagnostic.S1147.severity = warning
906916
dotnet_diagnostic.S1151.severity = warning
@@ -1383,9 +1393,6 @@ dotnet_diagnostic.S109.severity = suggestion
13831393
# Sections of code should not be commented out
13841394
dotnet_diagnostic.S125.severity = suggestion
13851395

1386-
# Unused private types or members should be removed
1387-
dotnet_diagnostic.S1144.severity = suggestion
1388-
13891396
# Unused assignments should be removed
13901397
dotnet_diagnostic.S1854.severity = suggestion
13911398

@@ -1401,16 +1408,11 @@ dotnet_diagnostic.S4018.severity = suggestion
14011408
# Exceptions should provide standard constructorss
14021409
dotnet_diagnostic.S4027.severity = suggestion
14031410

1404-
# Properties should be preferred
1405-
dotnet_diagnostic.S4049.severity = suggestion
1406-
14071411
# Use "DateTimeOffset" instead of "DateTime"
14081412
dotnet_diagnostic.S6566.severity = suggestion
14091413

14101414
# # Boolean literals should not be redundant
14111415
# dotnet_diagnostic.S1125.severity = suggestion
1412-
# # Unused method parameters should be removed
1413-
# dotnet_diagnostic.S1172.severity = suggestion
14141416
# # Redundant casts should not be used
14151417
# dotnet_diagnostic.S1905.severity = suggestion
14161418

@@ -1443,6 +1445,9 @@ dotnet_diagnostic.S2360.severity = none
14431445
# Types and methods should not have too many generic parameters
14441446
dotnet_diagnostic.S2436.severity = none
14451447

1448+
# Properties should be preferred, duplicate with CA1024
1449+
dotnet_diagnostic.S4049.severity = none
1450+
14461451
# Literals should not be passed as localized parameters
14471452
dotnet_diagnostic.S4055.severity = none
14481453

@@ -1463,12 +1468,12 @@ dotnet_diagnostic.S1123.severity = none
14631468
# Track uses of "TODO" tags
14641469
dotnet_diagnostic.S1135.severity = none
14651470

1471+
# Unused method parameters should be removed, duplicate with IDE0060
1472+
dotnet_diagnostic.S1172.severity = none
1473+
14661474
# Composite format strings should not lead to unexpected behavior at runtime
14671475
dotnet_diagnostic.S2275.severity = none
14681476

1469-
# Trivial properties should be auto-implemented
1470-
dotnet_diagnostic.S2325.severity = none
1471-
14721477
# Logging templates should be constant
14731478
dotnet_diagnostic.S2629.severity = none
14741479

@@ -1560,6 +1565,9 @@ dotnet_diagnostic.S3923.severity = error
15601565
# S4158: Empty collections should not be accessed or iterated
15611566
dotnet_diagnostic.S4158.severity = error
15621567

1568+
# S5034: "ValueTask" should be consumed correctly
1569+
dotnet_diagnostic.S5034.severity = error
1570+
15631571
##########################################
15641572
# MessagePack-CSharp
15651573
# https://github.com/MessagePack-CSharp/MessagePack-CSharp/blob/master/doc/analyzers/index.md
@@ -1601,13 +1609,32 @@ resharper_indent_nested_while_stmt = true
16011609
resharper_indent_raw_literal_string = do_not_change
16021610
resharper_outdent_statement_labels = true
16031611

1612+
##########################################
1613+
# change when AnalysisMode is All
1614+
##########################################
1615+
1616+
# Consider making public types internal
1617+
dotnet_diagnostic.CA1515.severity = suggestion
1618+
1619+
# Avoid unused private fields
1620+
dotnet_diagnostic.CA1823.severity = none
1621+
1622+
# CA2007: Do not directly await a Task
1623+
dotnet_diagnostic.CA2007.severity = none
1624+
1625+
# duplicate with IDE0059
1626+
# Unused local variables should be removed
1627+
dotnet_diagnostic.S1481.severity = none
1628+
1629+
# duplicate with CA2213
1630+
# Classes should "Dispose" of members from the classes' own "Dispose" methods
1631+
dotnet_diagnostic.S2952.severity = none
1632+
16041633
[*{Benchmark,Benchmarks}.cs]
16051634
# CA1707: Identifiers should not contain underscores
16061635
dotnet_diagnostic.CA1707.severity = none
16071636
# CRR0035 - No CancellationToken parameter in the asynchronous method
16081637
dotnet_diagnostic.CRR0035.severity = none
1609-
# CA1822: Mark members as static
1610-
dotnet_diagnostic.CA1822.severity = none
16111638

16121639
[*{Test,Tests}.cs]
16131640
# CA1707: Identifiers should not contain underscores

src/plugins/Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<LangVersion>latest</LangVersion>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
7+
<AnalysisMode>All</AnalysisMode>
78
</PropertyGroup>
89

910
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
1-
using System.IO;
21
using StackExchange.Redis;
32

4-
namespace StackExchangeRedisTest
3+
namespace StackExchangeRedisTest;
4+
5+
public static class DatabaseProvider
56
{
6-
internal sealed class DatabaseProvider
7+
8+
#region Constants & Statics
9+
10+
static DatabaseProvider()
11+
{
12+
Logger = new StringWriter();
13+
Connection = ConnectionMultiplexer.Connect("localhost:6379,DefaultDatabase=5,allowAdmin=true", Logger);
14+
}
15+
16+
/// <summary>
17+
/// Gets the connection.
18+
/// </summary>
19+
public static ConnectionMultiplexer Connection { get; private set; }
20+
21+
/// <summary>
22+
/// Gets the logger.
23+
/// </summary>
24+
public static StringWriter Logger { get; }
25+
26+
public static void Dispose()
727
{
8-
static DatabaseProvider()
9-
{
10-
Logger = new StringWriter();
11-
Connection =
12-
Connection =
13-
ConnectionMultiplexer.Connect("10.99.59.47:7000,10.99.59.47:7000,DefaultDatabase=5,allowAdmin=true",
14-
Logger);
15-
//Connection = ConnectionMultiplexer.Connect("localhost:6379,DefaultDatabase=5", Logger);
16-
}
17-
18-
/// <summary>
19-
/// Gets the connection.
20-
/// </summary>
21-
public static ConnectionMultiplexer Connection { get; private set; }
22-
23-
/// <summary>
24-
/// Gets the logger.
25-
/// </summary>
26-
public static StringWriter Logger { get; }
27-
28-
/// <summary>
29-
/// Gets the database.
30-
/// </summary>
31-
public static IDatabase GetDatabase()
32-
{
33-
return Connection.GetDatabase();
34-
}
35-
36-
/// <summary>
37-
/// Gets the subscriber.
38-
/// </summary>
39-
public static ISubscriber GetSubscriber()
40-
{
41-
return Connection.GetSubscriber();
42-
}
43-
44-
public static void Start()
45-
{
46-
//clear
47-
GetDatabase().Execute("flushdb");
48-
}
49-
50-
public static void Dispose()
51-
{
52-
Connection.Dispose();
53-
Logger.Dispose();
54-
}
28+
Connection.Dispose();
29+
Logger.Dispose();
5530
}
31+
32+
/// <summary>
33+
/// Gets the database.
34+
/// </summary>
35+
public static IDatabase GetDatabase()
36+
{
37+
return Connection.GetDatabase();
38+
}
39+
40+
/// <summary>
41+
/// Gets the subscriber.
42+
/// </summary>
43+
public static ISubscriber GetSubscriber()
44+
{
45+
return Connection.GetSubscriber();
46+
}
47+
48+
public static void Start()
49+
{
50+
//clear
51+
//GetDatabase().Execute("flushdb");
52+
}
53+
54+
#endregion
55+
5656
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using Microsoft.Extensions.Logging;
2+
using StackExchange.Redis.Extensions.Core.Abstractions;
3+
using StackExchange.Redis.Extensions.Core.Configuration;
4+
using StackExchange.Redis.Extensions.Core.Implementations;
5+
6+
namespace StackExchangeRedisTest;
7+
8+
public static class ExtensionDatabaseProvider
9+
{
10+
11+
#region Constants & Statics
12+
13+
private static readonly IRedisClientFactory Factory;
14+
private static readonly ILoggerFactory Logger;
15+
private static readonly RedisConfiguration RedisConfiguration = new()
16+
{
17+
AbortOnConnectFail = true,
18+
Hosts = [new() { Host = "localhost", Port = 6379 }],
19+
Database = 5,
20+
//Ssl = true,
21+
AllowAdmin = true,
22+
KeyPrefix = "ExtensionTest:",
23+
//MaxValueLength = 1024,
24+
IsDefault = true,
25+
Name = "ExtensionTest",
26+
};
27+
28+
static ExtensionDatabaseProvider()
29+
{
30+
Logger = LoggerFactory.Create((builder) => builder.AddConsole().SetMinimumLevel(LogLevel.Information));
31+
Factory = new RedisClientFactory([RedisConfiguration], Logger, new RedisMemoryPackSerializer());
32+
}
33+
34+
public static void Dispose()
35+
{
36+
Logger.Dispose();
37+
foreach (var item in Factory.GetAllClients())
38+
{
39+
item.ConnectionPoolManager.Dispose();
40+
}
41+
}
42+
43+
/// <summary>
44+
/// Gets the database.
45+
/// </summary>
46+
public static IRedisDatabase GetDatabase()
47+
{
48+
return Factory.GetDefaultRedisDatabase();
49+
}
50+
51+
public static void Start()
52+
{
53+
//clear
54+
//GetDatabase().Execute("flushdb");
55+
}
56+
57+
#endregion
58+
59+
}

0 commit comments

Comments
 (0)