85b362e8cd
- add the standalone HrynCo.Common solution and projects - include the shared common library source and tests - add package metadata and a repo gitignore
42 lines
1.2 KiB
C#
42 lines
1.2 KiB
C#
namespace HrynCo.Common.Tests;
|
|
|
|
using HrynCo.Common.Caching;
|
|
using FluentAssertions;
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
using Xunit;
|
|
|
|
public sealed class CachingTests
|
|
{
|
|
[Fact]
|
|
public async Task SessionCredentialStore_ShouldSaveGetAndRemoveValues()
|
|
{
|
|
using var cache = new MemoryCache(new MemoryCacheOptions());
|
|
var store = new InMemorySessionCredentialStore(cache);
|
|
Guid userId = Guid.NewGuid();
|
|
|
|
await store.SaveAsync(userId, "github", "secret", TimeSpan.FromMinutes(5));
|
|
|
|
(await store.GetAsync(userId, "github")).Should().Be("secret");
|
|
|
|
await store.RemoveAsync(userId, "github");
|
|
|
|
(await store.GetAsync(userId, "github")).Should().BeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task SessionPromptStore_ShouldSaveGetAndRemoveValues()
|
|
{
|
|
using var cache = new MemoryCache(new MemoryCacheOptions());
|
|
var store = new InMemorySessionPromptStore(cache);
|
|
Guid userId = Guid.NewGuid();
|
|
|
|
await store.SaveAsync(userId, "openai", "prompt", TimeSpan.FromMinutes(5));
|
|
|
|
(await store.GetAsync(userId, "openai")).Should().Be("prompt");
|
|
|
|
await store.RemoveAsync(userId, "openai");
|
|
|
|
(await store.GetAsync(userId, "openai")).Should().BeNull();
|
|
}
|
|
}
|