-
No results found.
Try your search with a different keyword or use * as a wildcard.
MemoryCacheManagerTests.cs
using FluentAssertions;
using Nop.Core.Caching;
using NUnit.Framework;
namespace Nop.Tests.Nop.Core.Tests.Caching;
[TestFixture]
public class MemoryCacheManagerTests : BaseNopTest
{
private MemoryCacheManager _staticCacheManager;
[OneTimeSetUp]
public void Setup()
{
_staticCacheManager = GetService() as MemoryCacheManager;
}
[TearDown]
public async Task TaskTearDown()
{
await _staticCacheManager.ClearAsync();
}
[Test]
public async Task CanSetAndGetObjectFromCache()
{
await _staticCacheManager.SetAsync(new CacheKey("some_key_1"), 3);
var rez = await _staticCacheManager.GetAsync(new CacheKey("some_key_1"), () => 0);
rez.Should().Be(3);
}
[Test]
public async Task DoesNotIgnoreKeyCase()
{
await _staticCacheManager.SetAsync(new CacheKey("Some_Key_1"), 3);
var rez = await _staticCacheManager.GetAsync(new CacheKey("some_key_1"), () => 0);
rez.Should().Be(0);
}
[Test]
public async Task CanValidateWhetherObjectIsCached()
{
await _staticCacheManager.SetAsync(new CacheKey("some_key_1"), 3);
await _staticCacheManager.SetAsync(new CacheKey("some_key_2"), 4);
var rez = await _staticCacheManager.GetAsync(new CacheKey("some_key_1"), () => 2);
rez.Should().Be(3);
rez = await _staticCacheManager.GetAsync(new CacheKey("some_key_2"), () => 2);
rez.Should().Be(4);
}
[Test]
public async Task CanClearCache()
{
await _staticCacheManager.SetAsync(new CacheKey("some_key_1"), 3);
await _staticCacheManager.ClearAsync();
var rez = await _staticCacheManager.GetAsync