Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/WebApi.OutputCache.V2/DefaultCacheKeyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
18 changes: 14 additions & 4 deletions test/WebApi.OutputCache.V2.Tests/CacheKeyGenerationTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,23 @@ namespace WebApi.OutputCache.V2.Tests
/// </summary>
public abstract class CacheKeyGenerationTestsBase<TCacheKeyGenerator> 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()
{
Expand Down Expand Up @@ -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);
}
}
}