Files
Umbraco-CMS/src/Umbraco.Tests/Cache/WebCachingAppCacheTests.cs

56 lines
1.6 KiB
C#
Raw Normal View History

2019-01-18 08:14:08 +01:00
using System;
using System.Diagnostics;
using System.Web;
using Moq;
2019-01-18 08:14:08 +01:00
using NUnit.Framework;
using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
using Umbraco.Core.Logging;
using Umbraco.Web.Cache;
2019-01-18 08:14:08 +01:00
namespace Umbraco.Tests.Cache
{
[TestFixture]
public class WebCachingAppCacheTests : RuntimeAppCacheTests
{
private WebCachingAppCache _appCache;
protected override int GetTotalItemCount => HttpRuntime.Cache.Count;
public override void Setup()
{
base.Setup();
var typeFinder = new TypeFinder(Mock.Of<ILogger>());
_appCache = new WebCachingAppCache(HttpRuntime.Cache, typeFinder);
2019-01-18 08:14:08 +01:00
}
internal override IAppCache AppCache => _appCache;
internal override IAppPolicyCache AppPolicyCache => _appCache;
[Test]
public void DoesNotCacheExceptions()
{
string value;
Assert.Throws<Exception>(() => { value = (string)_appCache.Get("key", () => GetValue(1)); });
Assert.Throws<Exception>(() => { value = (string)_appCache.Get("key", () => GetValue(2)); });
// does not throw
value = (string)_appCache.Get("key", () => GetValue(3));
Assert.AreEqual("succ3", value);
// cache
value = (string)_appCache.Get("key", () => GetValue(4));
Assert.AreEqual("succ3", value);
}
private static string GetValue(int i)
{
Debug.Print("get" + i);
if (i < 3)
throw new Exception("fail");
return "succ" + i;
}
}
}