Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 594a15b

Browse files
committed
fixup test re signature changes
1 parent 1daefb6 commit 594a15b

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

tests/ServiceStack.Redis.Tests/AsyncImplementationsTests.Async.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ public void TestSameAPI(Type syncInterface, Type asyncInterface)
8383
}
8484

8585
var expected = new List<string>();
86-
ParameterToken cancellationToken = new ParameterToken("cancellationToken", typeof(CancellationToken), ParameterAttributes.Optional);
86+
ParameterToken cancellationToken = new ParameterToken(
87+
(asyncInterface == typeof(IRemoveByPatternAsync) || asyncInterface == typeof(ICacheClientAsync))
88+
? "token" : "cancellationToken", typeof(CancellationToken), ParameterAttributes.Optional);
8789
foreach (var method in syncInterface.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
8890
{
8991
AddExpected(method);
@@ -169,6 +171,18 @@ void AddFrom(Type syncInterface, string name, bool fromPropertyToMethod = false)
169171
void AddFromTyped(Type syncInterface, string name, params Type[] types)
170172
=> AddExpected(syncInterface.GetMethod(name, types), false);
171173

174+
Type AsyncType(Type result)
175+
{
176+
bool useTask = asyncInterface == typeof(ICacheClientAsync)
177+
|| asyncInterface == typeof(IRemoveByPatternAsync)
178+
|| asyncInterface == typeof(IEntityStoreAsync)
179+
|| asyncInterface == typeof(IEntityStoreAsync<>);
180+
181+
if (result is null || result == typeof(void))
182+
return useTask ? typeof(Task) : typeof(ValueTask);
183+
184+
return (useTask ? typeof(Task<>) : typeof(ValueTask<>)).MakeGenericType(result);
185+
}
172186
void AddExpected(MethodInfo method, bool fromPropertyToMethod = false)
173187
{
174188
if (method is null) return;
@@ -180,7 +194,7 @@ void AddExpected(MethodInfo method, bool fromPropertyToMethod = false)
180194
Type returnType;
181195
if (tok.ReturnType == typeof(void))
182196
{
183-
returnType = typeof(ValueTask);
197+
returnType = AsyncType(tok.ReturnType);
184198
}
185199
else if (tok.ReturnType == typeof(IDisposable))
186200
{
@@ -192,7 +206,7 @@ void AddExpected(MethodInfo method, bool fromPropertyToMethod = false)
192206
}
193207
else
194208
{
195-
returnType = typeof(ValueTask<>).MakeGenericType(SwapForAsyncIfNeedeed(tok.ReturnType));
209+
returnType = AsyncType(SwapForAsyncIfNeedeed(tok.ReturnType));
196210
}
197211
string name = tok.Name + "Async";
198212
bool addCancellation = true;
@@ -793,7 +807,7 @@ public MethodToken(string name, Type returnType, ParameterToken[] parameters,
793807
}
794808

795809
[TestCase(typeof(ICacheClient), typeof(ICacheClientAsync))]
796-
[TestCase(typeof(ICacheClientExtended), typeof(ICacheClientAsync))] // duplicate not an error; APIs are coalesced
810+
[TestCase(typeof(ICacheClientExtended), typeof(ICacheClientAsync), typeof(BasicRedisClientManager))] // duplicate not an error; APIs are coalesced
797811
[TestCase(typeof(IEntityStore), typeof(IEntityStoreAsync))]
798812
[TestCase(typeof(IEntityStore<>), typeof(IEntityStoreAsync<>))]
799813
[TestCase(typeof(IRedisClient), typeof(IRedisClientAsync))]
@@ -825,9 +839,9 @@ public MethodToken(string name, Type returnType, ParameterToken[] parameters,
825839
[TestCase(typeof(IRedisTypedPipeline<>), typeof(IRedisTypedPipelineAsync<>))]
826840
[TestCase(typeof(IRedisTypedQueueableOperation<>), typeof(IRedisTypedQueueableOperationAsync<>))]
827841
[TestCase(typeof(IRedisTypedTransaction<>), typeof(IRedisTypedTransactionAsync<>))]
828-
public void TestFullyImplemented(Type syncInterface, Type asyncInterface)
842+
public void TestFullyImplemented(Type syncInterface, Type asyncInterface, params Type[] ignore)
829843
{
830-
HashSet<Type> except = new HashSet<Type>();
844+
HashSet<Type> except = new HashSet<Type>(ignore ?? Type.EmptyTypes);
831845
#if NET472 // only exists there!
832846
if (syncInterface == typeof(IRedisClientsManager))
833847
{

tests/ServiceStack.Redis.Tests/RedisBasicPersistenceProviderTests.Async.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public async Task Can_DeleteAll_with_runtime_type()
175175

176176
var mi = typeof(IEntityStoreAsync).GetMethod(nameof(IEntityStoreAsync.DeleteAllAsync));
177177
var genericMi = mi.MakeGenericMethod(typeof(TestModel));
178-
await (ValueTask)genericMi.Invoke(RedisAsync, new object[] { CancellationToken.None });
178+
await (Task)genericMi.Invoke(RedisAsync, new object[] { CancellationToken.None });
179179

180180
var allModels = await RedisAsync.As<TestModel>().GetAllAsync();
181181
Assert.That(allModels, Is.Empty);
@@ -192,7 +192,7 @@ public async Task Can_As_DeleteAll_with_runtime_type()
192192
var genericMi = mi.MakeGenericMethod(typeof(TestModel));
193193
var typedClient = genericMi.Invoke(RedisAsync, TypeConstants.EmptyObjectArray);
194194
var deleteMi = typeof(IEntityStoreAsync<TestModel>).GetMethod(nameof(IEntityStoreAsync<Type>.DeleteAllAsync));
195-
await (ValueTask)deleteMi.Invoke(typedClient, new object[] { CancellationToken.None });
195+
await (Task)deleteMi.Invoke(typedClient, new object[] { CancellationToken.None });
196196

197197
var allModels = await RedisAsync.As<TestModel>().GetAllAsync();
198198
Assert.That(allModels, Is.Empty);

0 commit comments

Comments
 (0)