2020-12-20 08:36:11 +01:00
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
|
|
|
|
using System;
|
2018-06-29 19:52:40 +02:00
|
|
|
using System.Threading;
|
|
|
|
|
using NUnit.Framework;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Cache;
|
|
|
|
|
using Umbraco.Extensions;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2021-02-18 11:06:02 +01:00
|
|
|
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Cache
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2019-01-18 08:14:08 +01:00
|
|
|
public abstract class RuntimeAppCacheTests : AppCacheTests
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2019-01-18 08:14:08 +01:00
|
|
|
internal abstract IAppPolicyCache AppPolicyCache { get; }
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
[Explicit("Testing for timeouts cannot work on VSTS.")]
|
|
|
|
|
public void Can_Add_And_Expire_Struct_Strongly_Typed_With_Null()
|
|
|
|
|
{
|
|
|
|
|
var now = DateTime.Now;
|
2019-01-18 08:14:08 +01:00
|
|
|
AppPolicyCache.Insert("DateTimeTest", () => now, new TimeSpan(0, 0, 0, 0, 200));
|
|
|
|
|
Assert.AreEqual(now, AppCache.GetCacheItem<DateTime>("DateTimeTest"));
|
|
|
|
|
Assert.AreEqual(now, AppCache.GetCacheItem<DateTime?>("DateTimeTest"));
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
Thread.Sleep(300); // sleep longer than the cache expiration
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2019-01-18 08:14:08 +01:00
|
|
|
Assert.AreEqual(default(DateTime), AppCache.GetCacheItem<DateTime>("DateTimeTest"));
|
|
|
|
|
Assert.AreEqual(null, AppCache.GetCacheItem<DateTime?>("DateTimeTest"));
|
2018-06-29 19:52:40 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|