-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathCoreTests.cs
149 lines (117 loc) · 6.56 KB
/
CoreTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
using Xunit;
using NRedisStack.Core;
using NRedisStack;
using static NRedisStack.Auxiliary;
using StackExchange.Redis;
using System.Xml.Linq;
using System.Reflection;
using NRedisStack.RedisStackCommands;
namespace NRedisStack.Tests.Core;
public class CoreTests : AbstractNRedisStackTest, IDisposable
{
public CoreTests(RedisFixture redisFixture) : base(redisFixture) { }
[SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")]
public void TestSimpleSetInfo()
{
var redis = ConnectionMultiplexer.Connect("localhost");
var db = redis.GetDatabase();
db.Execute("FLUSHALL");
db.ClientSetInfo(SetInfoAttr.LibraryName, "TestLibraryName");
db.ClientSetInfo(SetInfoAttr.LibraryVersion, "1.2.3");
var info = db.Execute("CLIENT", "INFO").ToString();
Assert.EndsWith($"lib-name=TestLibraryName lib-ver=1.2.3\n", info);
}
[SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")]
public async Task TestSimpleSetInfoAsync()
{
var redis = ConnectionMultiplexer.Connect("localhost");
var db = redis.GetDatabase();
db.Execute("FLUSHALL");
await db.ClientSetInfoAsync(SetInfoAttr.LibraryName, "TestLibraryName");
await db.ClientSetInfoAsync(SetInfoAttr.LibraryVersion, "1.2.3");
var info = db.Execute("CLIENT", "INFO").ToString();
Assert.EndsWith($"lib-name=TestLibraryName lib-ver=1.2.3\n", info);
}
[SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")]
public void TestSetInfoDefaultValue()
{
ResetInfoDefaults(); // demonstrate first connection
var redis = ConnectionMultiplexer.Connect("localhost");
var db = redis.GetDatabase();
db.Execute("FLUSHALL");
db.Execute(new SerializedCommand("PING")); // only the extension method of Execute (which is used for all the commands of Redis Stack) will set the library name and version.
var info = db.Execute("CLIENT", "INFO").ToString();
Assert.EndsWith($"lib-name=NRedisStack;.NET-{Environment.Version} lib-ver={GetNRedisStackVersion()}\n", info);
}
[SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")]
public async Task TestSetInfoDefaultValueAsync()
{
ResetInfoDefaults(); // demonstrate first connection
var redis = ConnectionMultiplexer.Connect("localhost");
var db = redis.GetDatabase();
db.Execute("FLUSHALL");
await db.ExecuteAsync(new SerializedCommand("PING")); // only the extension method of Execute (which is used for all the commands of Redis Stack) will set the library name and version.
var info = (await db.ExecuteAsync("CLIENT", "INFO")).ToString();
Assert.EndsWith($"lib-name=NRedisStack;.NET-{Environment.Version} lib-ver={GetNRedisStackVersion()}\n", info);
}
[SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")]
public void TestSetInfoWithValue()
{
ResetInfoDefaults(); // demonstrate first connection
var redis = ConnectionMultiplexer.Connect("localhost");
var db = redis.GetDatabase("MyLibraryName;v1.0.0");
db.Execute("FLUSHALL");
db.Execute(new SerializedCommand("PING")); // only the extension method of Execute (which is used for all the commands of Redis Stack) will set the library name and version.
var info = db.Execute("CLIENT", "INFO").ToString();
Assert.EndsWith($"NRedisStack(MyLibraryName;v1.0.0);.NET-{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info);
}
[SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")]
public async Task TestSetInfoWithValueAsync()
{
ResetInfoDefaults(); // demonstrate first connection
var redis = ConnectionMultiplexer.Connect("localhost");
var db = redis.GetDatabase("MyLibraryName;v1.0.0");
db.Execute("FLUSHALL");
await db.ExecuteAsync(new SerializedCommand("PING")); // only the extension method of Execute (which is used for all the commands of Redis Stack) will set the library name and version.
var info = (await db.ExecuteAsync("CLIENT", "INFO")).ToString();
Assert.EndsWith($"NRedisStack(MyLibraryName;v1.0.0);.NET-{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info);
}
[SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")]
public void TestSetInfoNull()
{
ResetInfoDefaults(); // demonstrate first connection
var redis = ConnectionMultiplexer.Connect("localhost");
var db = redis.GetDatabase(null);
db.Execute("FLUSHALL");
var infoBefore = db.Execute("CLIENT", "INFO").ToString();
db.Execute(new SerializedCommand("PING")); // only the extension method of Execute (which is used for all the commands of Redis Stack) will set the library name and version.
var infoAfter = db.Execute("CLIENT", "INFO").ToString();
// Find the indices of "lib-name=" in the strings
int infoAfterLibNameIndex = infoAfter!.IndexOf("lib-name=");
int infoBeforeLibNameIndex = infoBefore!.IndexOf("lib-name=");
// Extract the sub-strings starting from "lib-name="
string infoAfterLibNameToEnd = infoAfter.Substring(infoAfterLibNameIndex);
string infoBeforeLibNameToEnd = infoBefore.Substring(infoBeforeLibNameIndex);
// Assert that the extracted sub-strings are equal
Assert.Equal(infoAfterLibNameToEnd, infoBeforeLibNameToEnd);
}
[SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")]
public async Task TestSetInfoNullAsync()
{
ResetInfoDefaults(); // demonstrate first connection
var redis = ConnectionMultiplexer.Connect("localhost");
var db = redis.GetDatabase(null);
db.Execute("FLUSHALL");
var infoBefore = (await db.ExecuteAsync("CLIENT", "INFO")).ToString();
await db.ExecuteAsync(new SerializedCommand("PING")); // only the extension method of Execute (which is used for all the commands of Redis Stack) will set the library name and version.
var infoAfter = (await db.ExecuteAsync("CLIENT", "INFO")).ToString();
// Find the indices of "lib-name=" in the strings
int infoAfterLibNameIndex = infoAfter!.IndexOf("lib-name=");
int infoBeforeLibNameIndex = infoBefore!.IndexOf("lib-name=");
// Extract the sub-strings starting from "lib-name="
string infoAfterLibNameToEnd = infoAfter.Substring(infoAfterLibNameIndex);
string infoBeforeLibNameToEnd = infoBefore.Substring(infoBeforeLibNameIndex);
// Assert that the extracted sub-strings are equal
Assert.Equal(infoAfterLibNameToEnd, infoBeforeLibNameToEnd);
}
}