mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 18:57:39 -07:00
added new in memory cache.
This commit is contained in:
parent
d1eec340e0
commit
098036d49a
7 changed files with 202 additions and 0 deletions
74
NzbDrone.Common.Test/CacheTests/CachedFixture.cs
Normal file
74
NzbDrone.Common.Test/CacheTests/CachedFixture.cs
Normal file
|
@ -0,0 +1,74 @@
|
|||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Cache;
|
||||
|
||||
namespace NzbDrone.Common.Test.CacheTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class CachedFixture
|
||||
{
|
||||
private Cached<string> _cachedString = new Cached<string>();
|
||||
private Worker _worker;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_cachedString = new Cached<string>();
|
||||
_worker = new Worker();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_call_function_once()
|
||||
{
|
||||
_cachedString.Get("Test", _worker.GetString);
|
||||
_cachedString.Get("Test", _worker.GetString);
|
||||
|
||||
_worker.HitCount.Should().Be(1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
public void multiple_calls_should_return_same_result()
|
||||
{
|
||||
var first = _cachedString.Get("Test", _worker.GetString);
|
||||
var second = _cachedString.Get("Test", _worker.GetString);
|
||||
|
||||
first.Should().Be(second);
|
||||
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_remove_value_from_set()
|
||||
{
|
||||
_cachedString.Get("Test", _worker.GetString);
|
||||
|
||||
_cachedString.Remove("Test");
|
||||
|
||||
_cachedString.Get("Test", _worker.GetString);
|
||||
|
||||
|
||||
_worker.HitCount.Should().Be(2);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void remove_none_existing_should_break_things()
|
||||
{
|
||||
_cachedString.Remove("Test");
|
||||
}
|
||||
}
|
||||
|
||||
public class Worker
|
||||
{
|
||||
public int HitCount { get; private set; }
|
||||
|
||||
public string GetString()
|
||||
{
|
||||
HitCount++;
|
||||
return "Hit count is " + HitCount;
|
||||
}
|
||||
}
|
||||
}
|
33
NzbDrone.Common.Test/CacheTests/CachedManagerFixture.cs
Normal file
33
NzbDrone.Common.Test/CacheTests/CachedManagerFixture.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
using System;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Cache;
|
||||
|
||||
namespace NzbDrone.Common.Test.CacheTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class CachedManagerFixture
|
||||
{
|
||||
[Test]
|
||||
public void should_return_proper_type_of_cache()
|
||||
{
|
||||
var result = CacheManger.GetCache<DateTime>(typeof(string));
|
||||
|
||||
result.Should().BeOfType<Cached<DateTime>>();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void multiple_calls_should_get_the_same_cache()
|
||||
{
|
||||
var result1 = CacheManger.GetCache<DateTime>(typeof(string));
|
||||
var result2 = CacheManger.GetCache<DateTime>(typeof(string));
|
||||
|
||||
result1.Should().BeSameAs(result2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue