mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.9 KiB
67 lines
1.9 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using Xunit;
|
|
|
|
namespace Squidex.Infrastructure.Caching
|
|
{
|
|
public class LRUCacheTests
|
|
{
|
|
private readonly LRUCache sut = new LRUCache(10);
|
|
private readonly string key = "Key";
|
|
|
|
[Fact]
|
|
public void Should_always_override_when_setting_value()
|
|
{
|
|
sut.Set(key, 1);
|
|
sut.Set(key, 2);
|
|
|
|
Assert.True(sut.TryGetValue(key, out var value));
|
|
Assert.True(sut.Contains(key));
|
|
|
|
Assert.Equal(2, value);
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_remove_old_items_when_capacity_reached()
|
|
{
|
|
for (var i = 0; i < 15; i++)
|
|
{
|
|
sut.Set(i.ToString(), i);
|
|
}
|
|
|
|
for (var i = 0; i < 5; i++)
|
|
{
|
|
Assert.False(sut.TryGetValue(i.ToString(), out var value));
|
|
Assert.Null(value);
|
|
}
|
|
|
|
for (var i = 5; i < 15; i++)
|
|
{
|
|
Assert.True(sut.TryGetValue(i.ToString(), out var value));
|
|
Assert.NotNull(value);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_return_false_when_item_to_remove_does_not_exist()
|
|
{
|
|
Assert.False(sut.Remove(key));
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_remove_inserted_item()
|
|
{
|
|
sut.Set(key, 2);
|
|
|
|
Assert.True(sut.Remove(key));
|
|
Assert.False(sut.Contains(key));
|
|
Assert.False(sut.TryGetValue(key, out var value));
|
|
Assert.Null(value);
|
|
}
|
|
}
|
|
}
|