Files

34 lines
1.3 KiB
C#

using WxAgent.Core;
using Xunit;
namespace WxAgent.Core.Tests;
public sealed class AccountBindingMatcherTests
{
[Fact]
public void PrefersExactWechatIdOverNickname()
{
var result = AccountBindingMatcher.Match(new UiAccountIdentity("wxid-a", "Same"),
[new("db-1", "wxid-a", "Other"), new("db-2", "wxid-b", "Same")]);
Assert.True(result.IsMatched); Assert.Equal("db-1", result.AccountId); Assert.Equal("wechatId", result.Strategy);
}
[Fact]
public void UsesUniqueNicknameOnlyWhenWechatIdIsUnavailable()
{
var result = AccountBindingMatcher.Match(new UiAccountIdentity(null, " Alice "),
[new("db-1", null, "Alice"), new("db-2", null, "Bob")]);
Assert.True(result.IsMatched); Assert.Equal("db-1", result.AccountId); Assert.Equal("nickname", result.Strategy);
}
[Fact]
public void RejectsDuplicateNicknameAndConflictingDuplicateWechatId()
{
var duplicateName = AccountBindingMatcher.Match(new UiAccountIdentity(null, "Alice"),
[new("db-1", null, "Alice"), new("db-2", null, "Alice")]);
var duplicateId = AccountBindingMatcher.Match(new UiAccountIdentity("wxid-a", "Alice"),
[new("db-1", "wxid-a", "One"), new("db-2", "wxid-a", "Two")]);
Assert.False(duplicateName.IsMatched); Assert.False(duplicateId.IsMatched);
}
}