diff --git a/src/WebApi.OutputCache.V2/DefaultCacheKeyGenerator.cs b/src/WebApi.OutputCache.V2/DefaultCacheKeyGenerator.cs index 2f28ca8..4e575f2 100644 --- a/src/WebApi.OutputCache.V2/DefaultCacheKeyGenerator.cs +++ b/src/WebApi.OutputCache.V2/DefaultCacheKeyGenerator.cs @@ -26,7 +26,10 @@ protected virtual string MakeBaseKey(HttpActionContext context) protected virtual string FormatParameters(HttpActionContext context, bool excludeQueryString) { - var actionParameters = context.ActionArguments.Where(x => x.Value != null).Select(x => x.Key + "=" + GetValue(x.Value)); + var actionParameters = context + .ActionArguments + .Where(x => x.Value != null && (x.Value is string || x.Value.GetType().IsValueType)) + .Select(x => x.Key + "=" + GetValue(x.Value)); string parameters; diff --git a/test/WebApi.OutputCache.V2.Tests/CacheKeyGenerationTestsBase.cs b/test/WebApi.OutputCache.V2.Tests/CacheKeyGenerationTestsBase.cs index 9b1e6ed..75faa03 100644 --- a/test/WebApi.OutputCache.V2.Tests/CacheKeyGenerationTestsBase.cs +++ b/test/WebApi.OutputCache.V2.Tests/CacheKeyGenerationTestsBase.cs @@ -10,14 +10,23 @@ namespace WebApi.OutputCache.V2.Tests /// public abstract class CacheKeyGenerationTestsBase where TCacheKeyGenerator : ICacheKeyGenerator { - private const string ArgumentKey = "filterExpression"; - private const string ArgumentValue = "val"; + private const string Argument1Key = "filterExpression1"; + private const string Argument1Value = "val"; + private const string Argument2WithFromUriAttributeKey = "filterExpression2"; + private static readonly ClassArgument Argument2WithFromUriAttributeValue = new ClassArgument() { Value1 = "val1", Value2 = 7 }; protected HttpActionContext context; protected MediaTypeHeaderValue mediaType; protected Uri requestUri; protected TCacheKeyGenerator cacheKeyGenerator; protected string BaseCacheKey; + private class ClassArgument + { + public string Value1 { get; set; } + + public int Value2 { get; set; } + } + [SetUp] public virtual void Setup() { @@ -49,12 +58,13 @@ protected virtual void AssertCacheKeysBasicFormat(string cacheKey) protected void AddActionArgumentsToContext() { - context.ActionArguments.Add(ArgumentKey, ArgumentValue); + context.ActionArguments.Add(Argument1Key, Argument1Value); + context.ActionArguments.Add(Argument2WithFromUriAttributeKey, Argument2WithFromUriAttributeValue); } protected string FormatActionArgumentsForKeyAssertion() { - return String.Format("{0}={1}", ArgumentKey, ArgumentValue); + return String.Format("{0}={1}", Argument1Key, Argument1Value); } } }