|
3 | 3 | using System.Linq;
|
4 | 4 | using NUnit.Framework;
|
5 | 5 | using ServiceStack.Model;
|
| 6 | +using ServiceStack.Redis.Generic; |
| 7 | +using ServiceStack.Script; |
6 | 8 | using ServiceStack.Text;
|
7 | 9 |
|
8 | 10 | namespace ServiceStack.Redis.Tests
|
@@ -158,6 +160,66 @@ public void Can_DeleteAll()
|
158 | 160 | Assert.That(idsRemaining, Is.Empty);
|
159 | 161 | }
|
160 | 162 |
|
| 163 | + [Test] |
| 164 | + public void Can_DeleteAll_with_runtime_type() |
| 165 | + { |
| 166 | + Redis.StoreAll(testModels); |
| 167 | + |
| 168 | + var mi = Redis.GetType().GetMethod(nameof(RedisClient.DeleteAll)); |
| 169 | + var genericMi = mi.MakeGenericMethod(typeof(TestModel)); |
| 170 | + genericMi.Invoke(Redis, TypeConstants.EmptyObjectArray); |
| 171 | + |
| 172 | + var allModels = Redis.GetAll<TestModel>(); |
| 173 | + Assert.That(allModels, Is.Empty); |
| 174 | + var idsRemaining = Redis.GetAllItemsFromSet(TestModelIdsSetKey); |
| 175 | + Assert.That(idsRemaining, Is.Empty); |
| 176 | + } |
| 177 | + |
| 178 | + [Test] |
| 179 | + public void Can_As_DeleteAll_with_runtime_type() |
| 180 | + { |
| 181 | + Redis.StoreAll(testModels); |
| 182 | + |
| 183 | + var mi = Redis.GetType().GetMethod(nameof(RedisClient.As)); |
| 184 | + var genericMi = mi.MakeGenericMethod(typeof(TestModel)); |
| 185 | + var typedClient = genericMi.Invoke(Redis, TypeConstants.EmptyObjectArray); |
| 186 | + var deleteMi = typedClient.GetType().GetMethod(nameof(IRedisTypedClient<Type>.DeleteAll)); |
| 187 | + deleteMi.Invoke(typedClient, TypeConstants.EmptyObjectArray); |
| 188 | + |
| 189 | + var allModels = Redis.GetAll<TestModel>(); |
| 190 | + Assert.That(allModels, Is.Empty); |
| 191 | + var idsRemaining = Redis.GetAllItemsFromSet(TestModelIdsSetKey); |
| 192 | + Assert.That(idsRemaining, Is.Empty); |
| 193 | + } |
| 194 | + |
| 195 | + [Test] |
| 196 | + public void Can_As_DeleteAll_with_script() |
| 197 | + { |
| 198 | + Redis.StoreAll(testModels); |
| 199 | + |
| 200 | + var context = new ScriptContext { |
| 201 | + ScriptLanguages = { ScriptLisp.Language }, |
| 202 | + AllowScriptingOfAllTypes = true, |
| 203 | + ScriptMethods = { |
| 204 | + new ProtectedScripts() |
| 205 | + }, |
| 206 | + Args = { |
| 207 | + ["redis"] = Redis |
| 208 | + } |
| 209 | + }.Init(); |
| 210 | + |
| 211 | + var type = typeof(TestModel).FullName; |
| 212 | + context.EvaluateCode($"redis.call('DeleteAll<{type}>') |> return"); |
| 213 | + // context.EvaluateCode($"redis.call('As<{type}>').call('DeleteAll') |> return"); |
| 214 | + // context.RenderLisp($"(call redis \"DeleteAll<{type}>\")"); |
| 215 | + // context.RenderLisp($"(call (call redis \"As<{type}>\") \"DeleteAll\")"); |
| 216 | + |
| 217 | + var allModels = Redis.GetAll<TestModel>(); |
| 218 | + Assert.That(allModels, Is.Empty); |
| 219 | + var idsRemaining = Redis.GetAllItemsFromSet(TestModelIdsSetKey); |
| 220 | + Assert.That(idsRemaining, Is.Empty); |
| 221 | + } |
| 222 | + |
161 | 223 | [Test]
|
162 | 224 | public void Can_DeleteByIds()
|
163 | 225 | {
|
|
0 commit comments