本文整理汇总了C#中BehaviorSubject.Current方法的典型用法代码示例。如果您正苦于以下问题:C# BehaviorSubject.Current方法的具体用法?C# BehaviorSubject.Current怎么用?C# BehaviorSubject.Current使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BehaviorSubject
的用法示例。
在下文中一共展示了BehaviorSubject.Current方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Observable_Current_returns_latest_element
public async Task Observable_Current_returns_latest_element()
{
var subject = new BehaviorSubject<int>(1);
var asyncEnumerable = subject.Current();
using (var asyncEnumerator = asyncEnumerable.GetEnumerator())
{
subject.OnNext(2);
subject.OnNext(3);
subject.OnNext(4);
Assert.True(await asyncEnumerator.MoveNext(CancellationToken.None));
Assert.Equal(4, asyncEnumerator.Current);
}
}
示例2: Observable_Current_returns_elements_repeatedly
public async Task Observable_Current_returns_elements_repeatedly()
{
var subject = new BehaviorSubject<int>(1);
var asyncEnumerable = subject.Current();
using (var asyncEnumerator = asyncEnumerable.GetEnumerator())
{
for (var i = 0; i < 10; i++)
{
Assert.True(await asyncEnumerator.MoveNext(CancellationToken.None));
Assert.Equal(1, asyncEnumerator.Current);
}
subject.OnNext(2);
for (var i = 0; i < 10; i++)
{
Assert.True(await asyncEnumerator.MoveNext(CancellationToken.None));
Assert.Equal(2, asyncEnumerator.Current);
}
}
}
示例3: Observable_Current_completes_on_source_completion
public async Task Observable_Current_completes_on_source_completion()
{
var subject = new BehaviorSubject<int>(1);
var asyncEnumerable = subject.Current();
using (var asyncEnumerator = asyncEnumerable.GetEnumerator())
{
subject.OnNext(1);
subject.OnNext(2);
subject.OnNext(3);
subject.OnCompleted();
Assert.False(await asyncEnumerator.MoveNext(CancellationToken.None));
}
}
示例4: Observable_Current_propagates_exception
public async Task Observable_Current_propagates_exception()
{
var subject = new BehaviorSubject<int>(1);
var asyncEnumerable = subject.Current();
using (var asyncEnumerator = asyncEnumerable.GetEnumerator())
{
subject.OnNext(1);
subject.OnNext(2);
subject.OnNext(3);
subject.OnError(new InvalidOperationException());
asyncEnumerator
.Awaiting(_ => _.MoveNext(CancellationToken.None))
.ShouldThrowExactly<AggregateException>()
.Where(ex => ex.GetBaseException() is InvalidOperationException);
}
}