mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-25 04:59:01 +08:00
test(property): 添加测试清理方法并改进比较器测试
- 添加TearDown方法重置默认比较器 - 修改WithComparer测试使用新的比较器验证机制 - 添加比较器调用验证断言 - 更新测试逻辑以正确验证比较器行为
This commit is contained in:
parent
1783245d22
commit
77502e1b91
@ -6,6 +6,12 @@ namespace GFramework.Core.Tests.property;
|
|||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class BindablePropertyTests
|
public class BindablePropertyTests
|
||||||
{
|
{
|
||||||
|
[TearDown]
|
||||||
|
public void TearDown()
|
||||||
|
{
|
||||||
|
BindableProperty<string>.Comparer = (a, b) => a?.Equals(b) ?? b == null;
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Value_Get_Should_Return_Default_Value()
|
public void Value_Get_Should_Return_Default_Value()
|
||||||
{
|
{
|
||||||
@ -85,15 +91,25 @@ public class BindablePropertyTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void WithComparer_Should_Use_Custom_Comparer()
|
public void WithComparer_Should_Use_Custom_Comparer()
|
||||||
{
|
{
|
||||||
var property = new BindableProperty<string>("test").WithComparer((a, b) => a.Length == b.Length);
|
var comparerWasCalled = false;
|
||||||
|
var comparisonResult = false;
|
||||||
|
|
||||||
|
BindableProperty<string>.Comparer = (a, b) =>
|
||||||
|
{
|
||||||
|
comparerWasCalled = true;
|
||||||
|
comparisonResult = a.Length == b.Length;
|
||||||
|
return comparisonResult;
|
||||||
|
};
|
||||||
|
|
||||||
|
var property = new BindableProperty<string>("test");
|
||||||
var count = 0;
|
var count = 0;
|
||||||
|
|
||||||
property.Register(_ => { count++; });
|
property.Register(_ => { count++; });
|
||||||
|
property.Value = "test";
|
||||||
|
|
||||||
property.Value = "hello";
|
Assert.That(comparerWasCalled, Is.True, "自定义比较器应该被调用");
|
||||||
|
Assert.That(comparisonResult, Is.True, "比较结果应该是true(相同长度)");
|
||||||
// "test" 和 "hello" 长度都是 4,所以不应该触发事件
|
Assert.That(count, Is.EqualTo(0), "不应该触发事件");
|
||||||
Assert.That(count, Is.EqualTo(0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user