wabbajack/Wabbajack.VFS.Test/HashCacheTest.cs

39 lines
1.1 KiB
C#
Raw Permalink Normal View History

2021-09-27 12:42:46 +00:00
using System.Threading;
using System.Threading.Tasks;
using Wabbajack.Hashing.xxHash64;
using Wabbajack.Paths.IO;
using Xunit;
2021-10-23 16:51:17 +00:00
namespace Wabbajack.VFS.Test;
public class HashCacheTest
2021-09-27 12:42:46 +00:00
{
2021-10-23 16:51:17 +00:00
private readonly FileHashCache _cache;
private readonly TemporaryFileManager _manager;
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
public HashCacheTest(FileHashCache cache, TemporaryFileManager manager)
{
_cache = cache;
_manager = manager;
}
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
[Fact]
public async Task CanCacheAndPurgeHashes()
{
var testFile = _manager.CreateFile();
await testFile.Path.WriteAllTextAsync("Cheese for Everyone!");
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
Assert.Equal(Hash.FromBase64("eSIyd+KOG3s="),
await _cache.FileHashCachedAsync(testFile.Path, CancellationToken.None));
Assert.True(_cache.TryGetHashCache(testFile.Path, out var hash));
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
_cache.Purge(testFile.Path);
Assert.False(_cache.TryGetHashCache(testFile.Path, out _));
Assert.Equal(hash, await _cache.FileHashCachedAsync(testFile.Path, CancellationToken.None));
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
Assert.True(_cache.TryGetHashCache(testFile.Path, out _));
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
_cache.VacuumDatabase();
2021-09-27 12:42:46 +00:00
}
}