本文整理汇总了C#中Subject.ToObservableChangeSet方法的典型用法代码示例。如果您正苦于以下问题:C# Subject.ToObservableChangeSet方法的具体用法?C# Subject.ToObservableChangeSet怎么用?C# Subject.ToObservableChangeSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Subject
的用法示例。
在下文中一共展示了Subject.ToObservableChangeSet方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LimitSizeTo
public void LimitSizeTo()
{
var subject = new Subject<Person>();
var scheduler = new TestScheduler();
var results = subject.ToObservableChangeSet<Person>(limitSizeTo: 100,scheduler: scheduler).AsAggregator();
var items = Enumerable.Range(1, 200).Select(i => new Person("p" + i.ToString("000"), i)).ToArray();
foreach (var person in items)
{
subject.OnNext(person);
}
scheduler.AdvanceBy(100000);
Assert.AreEqual(300, results.Messages.Count, "Should be 300 messages");
Assert.AreEqual(200, results.Messages.Sum(x => x.Adds), "Should be 200 adds");
Assert.AreEqual(100, results.Messages.Sum(x => x.Removes), "Should be 100 removes");
Assert.AreEqual(100, results.Data.Count, "Should be 1 item in the cache");
var expected = items.Skip(100).ToArray().OrderBy(p => p.Name).ToArray();
var actual = results.Data.Items.OrderBy(p => p.Name).ToArray();
CollectionAssert.AreEqual(expected, actual,"Only second hundred should be in the cache");
}
示例2: OnNextFiresAdd
public void OnNextFiresAdd()
{
var subject = new Subject<Person>();
var results = subject.ToObservableChangeSet().AsAggregator();
var person = new Person("A", 1);
subject.OnNext(person);
Assert.AreEqual(1, results.Messages.Count, "Should be 1 updates");
Assert.AreEqual(1, results.Data.Count, "Should be 1 item in the cache");
Assert.AreEqual(person, results.Data.Items.First(), "Should be same person");
}
示例3: ExpireAfterTime
public void ExpireAfterTime()
{
var subject = new Subject<IEnumerable<Person>>();
var scheduler = new TestScheduler();
var results = subject.ToObservableChangeSet<Person>(expireAfter: t => TimeSpan.FromMinutes(1), scheduler: scheduler).AsAggregator();
var people = Enumerable.Range(1, 200).Select(i => new Person("p" + i.ToString("000"), i)).ToArray();
subject.OnNext(people);
scheduler.AdvanceBy(TimeSpan.FromSeconds(61).Ticks);
//scheduler.Start();
Assert.AreEqual(2, results.Messages.Count, "Should be 300 messages");
Assert.AreEqual(200, results.Messages.Sum(x => x.Adds), "Should be 200 adds");
Assert.AreEqual(200, results.Messages.Sum(x => x.Removes), "Should be 100 removes");
Assert.AreEqual(0, results.Data.Count, "Should be no data in the cache");
}
示例4: OnNextProducesAnAddChangeForEnumerableSource
public void OnNextProducesAnAddChangeForEnumerableSource()
{
var subject = new Subject<IEnumerable<Person>>();
var results = subject.ToObservableChangeSet<Person>().AsAggregator();
var people = new[]
{
new Person("A", 1),
new Person("B", 2),
new Person("C", 3)
};
subject.OnNext(people);
Assert.AreEqual(1, results.Messages.Count, "Should be 1 updates");
Assert.AreEqual(3, results.Data.Count, "Should be 1 item in the cache");
CollectionAssert.AreEquivalent(people, results.Data.Items, "Lists should be equivalent");
}