Skip to content

Commit 14cfb8a

Browse files
Add ICacheKey tests
1 parent 4f216ca commit 14cfb8a

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Apache License, Version 2.0.
3+
4+
using System;
5+
using Microsoft.AspNetCore.Http;
6+
using SixLabors.ImageSharp.Web.Caching;
7+
using SixLabors.ImageSharp.Web.Commands;
8+
using Xunit;
9+
10+
namespace SixLabors.ImageSharp.Web.Tests.Caching
11+
{
12+
public class CacheKeyTests
13+
{
14+
private static readonly ICacheKey UriRelativeCacheKey = new UriRelativeCacheKey();
15+
private static readonly ICacheKey UriAbsoluteCacheKey = new UriAbsoluteCacheKey();
16+
17+
[Fact]
18+
public void UriRelativeCacheKeyOuputIsRelativeAndLowercase()
19+
{
20+
HttpContext context = CreateHttpContext();
21+
var commands = new CommandCollection()
22+
{
23+
{ "Width", "400" }
24+
};
25+
26+
string expected = "/images/image-12345.jpeg?width=400";
27+
string actual = UriRelativeCacheKey.Create(context, commands);
28+
29+
Assert.Equal(expected, actual);
30+
}
31+
32+
[Fact]
33+
public void UriAbsoluteCacheKeyOuputIsAbsoluteAndLowercase()
34+
{
35+
HttpContext context = CreateHttpContext();
36+
var commands = new CommandCollection()
37+
{
38+
{ "Width", "400" }
39+
};
40+
41+
string expected = "http://testwebsite.com/images/image-12345.jpeg?width=400";
42+
string actual = UriAbsoluteCacheKey.Create(context, commands);
43+
44+
Assert.Equal(expected, actual);
45+
}
46+
47+
private static HttpContext CreateHttpContext()
48+
{
49+
var httpContext = new DefaultHttpContext();
50+
httpContext.Request.Scheme = Uri.UriSchemeHttp;
51+
httpContext.Request.Host = new HostString("Testwebsite.com");
52+
httpContext.Request.PathBase = "/Images";
53+
httpContext.Request.Path = "/Image-12345.jpeg";
54+
httpContext.Request.QueryString = new QueryString("?Should-Be=Ignored");
55+
56+
return httpContext;
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)