Skip to content

Commit e2f6a7b

Browse files
committed
added tests for ignoring cache
1 parent 84b8bcd commit e2f6a7b

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

test/WebApi.OutputCache.V2.Tests/ServerSideTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,27 @@ public void can_handle_media_type_when_cache_has_expired_during_request()
305305
Assert.That(result.IsSuccessStatusCode, Is.True);
306306
}
307307

308+
[Test]
309+
public void will_cache_if_cacheouput_present_on_controller()
310+
{
311+
var client = new HttpClient(_server);
312+
var result = client.GetAsync("http://www.strathweb.com/api/ignore/cached").Result;
313+
314+
_cache.Verify(s => s.Contains(It.Is<string>(x => x == "webapi.outputcache.v2.tests.testcontrollers.ignorecontroller-cached:application/json; charset=utf-8")), Times.Exactly(2));
315+
_cache.Verify(s => s.Add(It.Is<string>(x => x == "webapi.outputcache.v2.tests.testcontrollers.ignorecontroller-cached"), It.IsAny<object>(), It.Is<DateTimeOffset>(x => x <= DateTime.Now.AddSeconds(100)), null), Times.Once());
316+
_cache.Verify(s => s.Add(It.Is<string>(x => x == "webapi.outputcache.v2.tests.testcontrollers.ignorecontroller-cached:application/json; charset=utf-8"), It.IsAny<object>(), It.Is<DateTimeOffset>(x => x <= DateTime.Now.AddSeconds(100)), It.Is<string>(x => x == "webapi.outputcache.v2.tests.testcontrollers.ignorecontroller-cached")), Times.Once());
317+
}
318+
319+
[Test]
320+
public void will_not_cache_if_cacheouput_present_on_controller_but_action_has_ignorecacheouputattibute()
321+
{
322+
var client = new HttpClient(_server);
323+
var result = client.GetAsync("http://www.strathweb.com/api/ignore/uncached").Result;
324+
325+
_cache.Verify(s => s.Contains(It.IsAny<string>()), Times.Never());
326+
_cache.Verify(s => s.Add(It.IsAny<string>(), It.IsAny<object>(), It.IsAny<DateTimeOffset>(), It.IsAny<string>()), Times.Never());
327+
_cache.Verify(s => s.Add(It.IsAny<string>(), It.IsAny<object>(), It.IsAny<DateTimeOffset>(), It.IsAny<string>()), Times.Never());
328+
}
308329

309330
//[Test]
310331
//public void must_add_querystring_to_cache_params()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Web.Http;
2+
3+
namespace WebApi.OutputCache.V2.Tests.TestControllers
4+
{
5+
[CacheOutput(ClientTimeSpan = 100, ServerTimeSpan = 100)]
6+
public class IgnoreController : ApiController
7+
{
8+
[HttpGet]
9+
public string Cached()
10+
{
11+
return "test";
12+
}
13+
14+
[HttpGet]
15+
[IgnoreCacheOutput]
16+
public string NotCached()
17+
{
18+
return "test";
19+
}
20+
}
21+
}

test/WebApi.OutputCache.V2.Tests/WebApi.OutputCache.V2.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
<Compile Include="TestControllers\AutoInvalidateController.cs" />
9696
<Compile Include="TestControllers\AutoInvalidateWithTypeController.cs" />
9797
<Compile Include="TestControllers\CacheKeyController.cs" />
98+
<Compile Include="TestControllers\IgnoreController.cs" />
9899
<Compile Include="TestControllers\InlineInvalidateController.cs" />
99100
<Compile Include="Properties\AssemblyInfo.cs" />
100101
<Compile Include="TestControllers\SampleController.cs">

0 commit comments

Comments
 (0)