31 lines
772 B
C#
31 lines
772 B
C#
using VendingMachine.Application.Services;
|
|
|
|
namespace VendingMachine.Tests;
|
|
|
|
/// <summary>
|
|
/// 内存版验证码存储,用于单元测试
|
|
/// </summary>
|
|
public class InMemoryVerificationCodeStore : IVerificationCodeStore
|
|
{
|
|
private readonly Dictionary<string, string> _store = new();
|
|
|
|
public IReadOnlyDictionary<string, string> Store => _store;
|
|
|
|
public Task StoreCodeAsync(string key, string code, TimeSpan expiry)
|
|
{
|
|
_store[key] = code;
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task<string?> GetCodeAsync(string key)
|
|
{
|
|
return Task.FromResult(_store.TryGetValue(key, out var val) ? val : null);
|
|
}
|
|
|
|
public Task DeleteCodeAsync(string key)
|
|
{
|
|
_store.Remove(key);
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|