Commit 7cf358ea authored by Nick Craver's avatar Nick Craver

Tests: enforce Naming in Release, and without the attribute

As we go for green on the test suite, we'll want this checked in PRs and such. And in general DEBUG and RELEASE not matching is becoming a pain. Trying to minimize the differences.
parent 6f746c6f
......@@ -185,39 +185,43 @@ public void CheckSyncAsyncMethodsMatch(Type from, Type to)
Log("Validated: {0} ({1} methods)", from.Name, count);
}
private static readonly Type ignoreType = typeof(ConnectionMultiplexer).Assembly.GetType("StackExchange.Redis.IgnoreNamePrefixAttribute");
private void CheckMethod(MethodInfo method, bool isAsync)
{
#if DEBUG
bool ignorePrefix = ignoreType != null && Attribute.IsDefined(method, ignoreType);
if (ignorePrefix)
{
Attribute attrib = Attribute.GetCustomAttribute(method, ignoreType);
if ((bool)attrib.GetType().GetProperty("IgnoreEntireMethod").GetValue(attrib))
{
return;
}
}
string shortName = method.Name, fullName = method.DeclaringType.Name + "." + shortName;
CheckName(method, isAsync);
if (!ignorePrefix)
switch (shortName)
{
Assert.True(
shortName.StartsWith("Debug")
|| shortName.StartsWith("Execute")
|| shortName.StartsWith("Geo")
|| shortName.StartsWith("Hash")
|| shortName.StartsWith("HyperLogLog")
|| shortName.StartsWith("Key")
|| shortName.StartsWith("List")
|| shortName.StartsWith("Lock")
|| shortName.StartsWith("Publish")
|| shortName.StartsWith("Set")
|| shortName.StartsWith("Script")
|| shortName.StartsWith("SortedSet")
|| shortName.StartsWith("String")
|| shortName.StartsWith("Stream")
, fullName + ":Prefix");
case nameof(IDatabaseAsync.IsConnected):
return;
case nameof(IDatabase.CreateBatch):
case nameof(IDatabase.CreateTransaction):
case nameof(IDatabase.IdentifyEndpoint):
case nameof(IDatabase.Sort):
case nameof(IDatabase.SortAndStore):
case nameof(IDatabaseAsync.IdentifyEndpointAsync):
case nameof(IDatabaseAsync.SortAsync):
case nameof(IDatabaseAsync.SortAndStoreAsync):
CheckName(method, isAsync);
break;
default:
CheckName(method, isAsync);
var isValid = shortName.StartsWith("Debug")
|| shortName.StartsWith("Execute")
|| shortName.StartsWith("Geo")
|| shortName.StartsWith("Hash")
|| shortName.StartsWith("HyperLogLog")
|| shortName.StartsWith("Key")
|| shortName.StartsWith("List")
|| shortName.StartsWith("Lock")
|| shortName.StartsWith("Publish")
|| shortName.StartsWith("Set")
|| shortName.StartsWith("Script")
|| shortName.StartsWith("SortedSet")
|| shortName.StartsWith("String")
|| shortName.StartsWith("Stream");
Log(fullName + ": " + (isValid ? "valid" : "invalid"));
Assert.True(isValid, fullName + ":Prefix");
break;
}
Assert.False(shortName.Contains("If"), fullName + ":If"); // should probably be a When option
......@@ -231,7 +235,6 @@ private void CheckMethod(MethodInfo method, bool isAsync)
{
Assert.False(typeof(Task).IsAssignableFrom(returnType), fullName + ":Task");
}
#endif
}
private void CheckName(MemberInfo member, bool isAsync)
......
......@@ -20,7 +20,6 @@ public interface IDatabase : IRedis, IDatabaseAsync
/// </summary>
/// <param name="asyncState">The async object state to be passed into the created <see cref="IBatch"/>.</param>
/// <returns>The created batch.</returns>
[IgnoreNamePrefix]
IBatch CreateBatch(object asyncState = null);
/// <summary>
......@@ -29,7 +28,6 @@ public interface IDatabase : IRedis, IDatabaseAsync
/// </summary>
/// <param name="asyncState">The async object state to be passed into the created <see cref="ITransaction"/>.</param>
/// <returns>The created transaction.</returns>
[IgnoreNamePrefix]
ITransaction CreateTransaction(object asyncState = null);
/// <summary>
......@@ -422,7 +420,6 @@ public interface IDatabase : IRedis, IDatabaseAsync
/// <param name="key">The key to check.</param>
/// <param name="flags">The flags to use for this operation.</param>
/// <returns>The endpoint serving the key.</returns>
[IgnoreNamePrefix]
EndPoint IdentifyEndpoint(RedisKey key = default(RedisKey), CommandFlags flags = CommandFlags.None);
/// <summary>
......@@ -1073,7 +1070,6 @@ public interface IDatabase : IRedis, IDatabaseAsync
/// <param name="flags">The flags to use for this operation.</param>
/// <returns>The sorted elements, or the external values if <c>get</c> is specified.</returns>
/// <remarks>https://redis.io/commands/sort</remarks>
[IgnoreNamePrefix]
RedisValue[] Sort(RedisKey key, long skip = 0, long take = -1, Order order = Order.Ascending, SortType sortType = SortType.Numeric, RedisValue by = default(RedisValue), RedisValue[] get = null, CommandFlags flags = CommandFlags.None);
/// <summary>
......@@ -1094,7 +1090,6 @@ public interface IDatabase : IRedis, IDatabaseAsync
/// <param name="flags">The flags to use for this operation.</param>
/// <returns>The number of elements stored in the new list.</returns>
/// <remarks>https://redis.io/commands/sort</remarks>
[IgnoreNamePrefix]
long SortAndStore(RedisKey destination, RedisKey key, long skip = 0, long take = -1, Order order = Order.Ascending, SortType sortType = SortType.Numeric, RedisValue by = default(RedisValue), RedisValue[] get = null, CommandFlags flags = CommandFlags.None);
/// <summary>
......
......@@ -16,7 +16,6 @@ public interface IDatabaseAsync : IRedisAsync
/// </summary>
/// <param name="key">The key to check for.</param>
/// <param name="flags">The flags to use for this operation.</param>
[IgnoreNamePrefix(true)]
bool IsConnected(RedisKey key, CommandFlags flags = CommandFlags.None);
/// <summary>
......@@ -385,7 +384,6 @@ public interface IDatabaseAsync : IRedisAsync
/// <param name="key">The key to check.</param>
/// <param name="flags">The flags to use for this operation.</param>
/// <returns>The endpoint serving the key.</returns>
[IgnoreNamePrefix]
Task<EndPoint> IdentifyEndpointAsync(RedisKey key = default(RedisKey), CommandFlags flags = CommandFlags.None);
/// <summary>
......@@ -1012,7 +1010,6 @@ public interface IDatabaseAsync : IRedisAsync
/// <param name="flags">The flags to use for this operation.</param>
/// <returns>The sorted elements, or the external values if <c>get</c> is specified.</returns>
/// <remarks>https://redis.io/commands/sort</remarks>
[IgnoreNamePrefix]
Task<RedisValue[]> SortAsync(RedisKey key, long skip = 0, long take = -1, Order order = Order.Ascending, SortType sortType = SortType.Numeric, RedisValue by = default(RedisValue), RedisValue[] get = null, CommandFlags flags = CommandFlags.None);
/// <summary>
......@@ -1033,7 +1030,6 @@ public interface IDatabaseAsync : IRedisAsync
/// <param name="flags">The flags to use for this operation.</param>
/// <returns>The number of elements stored in the new list.</returns>
/// <remarks>https://redis.io/commands/sort</remarks>
[IgnoreNamePrefix]
Task<long> SortAndStoreAsync(RedisKey destination, RedisKey key, long skip = 0, long take = -1, Order order = Order.Ascending, SortType sortType = SortType.Numeric, RedisValue by = default(RedisValue), RedisValue[] get = null, CommandFlags flags = CommandFlags.None);
/// <summary>
......
using System;
using System;
using System.Diagnostics;
namespace StackExchange.Redis
......@@ -16,16 +16,4 @@ public partial interface IRedis : IRedisAsync
/// <remarks>https://redis.io/commands/ping</remarks>
TimeSpan Ping(CommandFlags flags = CommandFlags.None);
}
[Conditional("DEBUG")]
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
internal class IgnoreNamePrefixAttribute : Attribute
{
public IgnoreNamePrefixAttribute(bool ignoreEntireMethod = false)
{
IgnoreEntireMethod = ignoreEntireMethod;
}
public bool IgnoreEntireMethod { get; }
}
}
\ No newline at end of file
}
......@@ -15,7 +15,6 @@ public interface ISubscriber : IRedis
/// </summary>
/// <param name="channel">The channel to identify the server endpoint by.</param>
/// <param name="flags">The command flags to use.</param>
[IgnoreNamePrefix]
EndPoint IdentifyEndpoint(RedisChannel channel, CommandFlags flags = CommandFlags.None);
/// <summary>
......@@ -23,7 +22,6 @@ public interface ISubscriber : IRedis
/// </summary>
/// <param name="channel">The channel to identify the server endpoint by.</param>
/// <param name="flags">The command flags to use.</param>
[IgnoreNamePrefix]
Task<EndPoint> IdentifyEndpointAsync(RedisChannel channel, CommandFlags flags = CommandFlags.None);
/// <summary>
......@@ -100,7 +98,6 @@ public interface ISubscriber : IRedis
/// the channel is not actively subscribed
/// </summary>
/// <param name="channel">The channel to check which server endpoint was subscribed on.</param>
[IgnoreNamePrefix]
EndPoint SubscribedEndpoint(RedisChannel channel);
/// <summary>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment