Files
wx-win-agent/tests/node-agent/WxAgent.Service.Tests/AccountBindingStoreTests.cs
T

31 lines
1.1 KiB
C#

using WxAgent.Service;
using Xunit;
namespace WxAgent.Service.Tests;
public sealed class AccountBindingStoreTests
{
[Fact]
public void ReplacesByAccountAndRemovesExplicitBinding()
{
var directory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(directory);
try
{
var store = new AccountBindingStore(new ServiceOptions { DataDirectory = directory, CredentialFile = Path.Combine(directory, "credentials.json") });
store.Replace([
new AccountBinding("a", 10, 20, "wxid-a", "Alice", DateTimeOffset.UtcNow),
new AccountBinding("a", 11, 21, "wxid-a", "Alice", DateTimeOffset.UtcNow),
new AccountBinding("b", 12, 22, "wxid-b", "Bob", DateTimeOffset.UtcNow)
]);
Assert.Equal(11, store.Get("a")!.ProcessId);
Assert.Equal(2, store.ReadAll().Count);
store.Remove("a");
Assert.Null(store.Get("a"));
Assert.Single(store.ReadAll());
}
finally { if (Directory.Exists(directory)) Directory.Delete(directory, true); }
}
}