2024-08-27 23:28:30 +09:00
|
|
|
using ObservableCollections;
|
|
|
|
|
2024-02-15 14:17:38 +09:00
|
|
|
namespace ObservableCollections.Tests;
|
|
|
|
|
|
|
|
public class ToNotifyCollectionChangedTest
|
|
|
|
{
|
|
|
|
[Fact]
|
|
|
|
public void ToNotifyCollectionChanged()
|
|
|
|
{
|
|
|
|
var list = new ObservableList<int>();
|
|
|
|
|
|
|
|
list.Add(10);
|
2024-02-15 14:36:55 +09:00
|
|
|
list.Add(20);
|
2024-02-15 14:17:38 +09:00
|
|
|
list.Add(30);
|
|
|
|
|
|
|
|
var notify = list.CreateView(x => $"${x}").ToNotifyCollectionChanged();
|
|
|
|
|
|
|
|
list.Add(40);
|
2024-02-15 14:36:55 +09:00
|
|
|
list.Add(50);
|
2024-02-15 14:17:38 +09:00
|
|
|
|
|
|
|
using var e = notify.GetEnumerator();
|
|
|
|
e.MoveNext().Should().BeTrue();
|
|
|
|
e.Current.Should().Be("$10");
|
|
|
|
e.MoveNext().Should().BeTrue();
|
|
|
|
e.Current.Should().Be("$20");
|
|
|
|
e.MoveNext().Should().BeTrue();
|
|
|
|
e.Current.Should().Be("$30");
|
|
|
|
e.MoveNext().Should().BeTrue();
|
|
|
|
e.Current.Should().Be("$40");
|
|
|
|
e.MoveNext().Should().BeTrue();
|
|
|
|
e.Current.Should().Be("$50");
|
|
|
|
e.MoveNext().Should().BeFalse();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void ToNotifyCollectionChanged_Filter()
|
|
|
|
{
|
|
|
|
var list = new ObservableList<int>();
|
|
|
|
|
|
|
|
list.Add(1);
|
|
|
|
list.Add(2);
|
|
|
|
list.Add(5);
|
|
|
|
list.Add(3);
|
|
|
|
|
|
|
|
var view = list.CreateView(x => $"${x}");
|
|
|
|
var notify = view.ToNotifyCollectionChanged();
|
|
|
|
|
2024-08-27 23:28:30 +09:00
|
|
|
view.AttachFilter((value) => value % 2 == 0);
|
2024-02-15 14:17:38 +09:00
|
|
|
|
|
|
|
list.Add(4);
|
|
|
|
|
|
|
|
using var e = notify.GetEnumerator();
|
|
|
|
e.MoveNext().Should().BeTrue();
|
|
|
|
e.Current.Should().Be("$2");
|
|
|
|
e.MoveNext().Should().BeTrue();
|
|
|
|
e.Current.Should().Be("$4");
|
|
|
|
e.MoveNext().Should().BeFalse();
|
|
|
|
}
|
|
|
|
}
|