本文整理汇总了C#中ReactiveList.AutoPersistCollection方法的典型用法代码示例。如果您正苦于以下问题:C# ReactiveList.AutoPersistCollection方法的具体用法?C# ReactiveList.AutoPersistCollection怎么用?C# ReactiveList.AutoPersistCollection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReactiveList
的用法示例。
在下文中一共展示了ReactiveList.AutoPersistCollection方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AutoPersistCollectionDisconnectsOnDispose
public void AutoPersistCollectionDisconnectsOnDispose()
{
(new TestScheduler()).With(sched => {
var manualSave = new Subject<Unit>();
var item = new TestFixture();
var fixture = new ReactiveList<TestFixture> { item };
int timesSaved = 0;
var disp = fixture.AutoPersistCollection(x => { timesSaved++; return Observable.Return(Unit.Default); }, manualSave, TimeSpan.FromMilliseconds(100));
sched.AdvanceByMs(2 * 100);
Assert.Equal(0, timesSaved);
// By being added to collection, AutoPersist is enabled for item
item.IsNotNullString = "Foo";
sched.AdvanceByMs(2 * 100);
Assert.Equal(1, timesSaved);
// Dispose = no save
disp.Dispose();
// Removed from collection = no save
fixture.Clear();
sched.AdvanceByMs(2 * 100);
Assert.Equal(1, timesSaved);
// Item isn't in the collection, it doesn't get persisted anymore
item.IsNotNullString = "Bar";
sched.AdvanceByMs(2 * 100);
Assert.Equal(1, timesSaved);
// Added back item + dispose = no save
fixture.Add(item);
sched.AdvanceByMs(100); // Compensate for scheduling
item.IsNotNullString = "Baz";
sched.AdvanceByMs(2 * 100);
Assert.Equal(1, timesSaved);
// Even if we issue a reset, no save
fixture.Reset();
sched.AdvanceByMs(100); // Compensate for scheduling
item.IsNotNullString = "Bamf";
sched.AdvanceByMs(2 * 100);
Assert.Equal(1, timesSaved);
// Remove by hand = no save
fixture.RemoveAt(0);
item.IsNotNullString = "Blomf";
sched.AdvanceByMs(2 * 100);
Assert.Equal(1, timesSaved);
});
}