本文整理汇总了C#中BehaviorSubject.OnError方法的典型用法代码示例。如果您正苦于以下问题:C# BehaviorSubject.OnError方法的具体用法?C# BehaviorSubject.OnError怎么用?C# BehaviorSubject.OnError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BehaviorSubject
的用法示例。
在下文中一共展示了BehaviorSubject.OnError方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Should_Complete_When_Source_Observable_Errors
public void Should_Complete_When_Source_Observable_Errors()
{
var source = new BehaviorSubject<object>(1);
var target = new ExpressionObserver(source, "Foo");
var completed = false;
target.Subscribe(_ => { }, () => completed = true);
source.OnError(new Exception());
Assert.True(completed);
}
示例2: errors_are_sent_through_scheduler
public void errors_are_sent_through_scheduler()
{
ManualScheduler scheduler = new ManualScheduler();
BehaviorSubject<int> subject = new BehaviorSubject<int>(0, scheduler);
StatsObserver<int> stats = new StatsObserver<int>();
subject.OnError(new Exception());
subject.Subscribe(stats);
Assert.IsFalse(stats.ErrorCalled);
scheduler.RunNext();
Assert.IsTrue(stats.ErrorCalled);
}
示例3: BehaviorSubject
public void BehaviorSubject()
{
// OnCompletedPattern
{
var subject = new BehaviorSubject<int>(3333);
var onNext = new List<int>();
var exception = new List<Exception>();
int onCompletedCallCount = 0;
var _ = subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
onNext.IsCollection(3333);
subject.OnNext(1);
subject.OnNext(10);
subject.OnNext(100);
subject.OnNext(1000);
onNext.IsCollection(3333, 1, 10, 100, 1000);
// re subscription
onNext.Clear();
_.Dispose();
subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
onNext.IsCollection(1000);
subject.OnCompleted();
onCompletedCallCount.Is(1);
subject.OnNext(1);
subject.OnNext(10);
subject.OnNext(100);
onNext.Count.Is(1);
subject.OnCompleted();
subject.OnError(new Exception());
exception.Count.Is(0);
onCompletedCallCount.Is(1);
// ++subscription
onNext.Clear();
onCompletedCallCount = 0;
subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
onNext.Count.Is(0);
exception.Count.Is(0);
onCompletedCallCount.Is(1);
}
// OnErrorPattern
{
var subject = new BehaviorSubject<int>(3333);
var onNext = new List<int>();
var exception = new List<Exception>();
int onCompletedCallCount = 0;
subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
subject.OnNext(1);
subject.OnNext(10);
subject.OnNext(100);
subject.OnNext(1000);
onNext.IsCollection(3333, 1, 10, 100, 1000);
subject.OnError(new Exception());
exception.Count.Is(1);
subject.OnNext(1);
subject.OnNext(10);
subject.OnNext(100);
onNext.Count.Is(5);
subject.OnCompleted();
subject.OnError(new Exception());
exception.Count.Is(1);
onCompletedCallCount.Is(0);
// ++subscription
onNext.Clear();
exception.Clear();
onCompletedCallCount = 0;
subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
onNext.Count.Is(0);
exception.Count.Is(1);
onCompletedCallCount.Is(0);
}
}
示例4: Value_ThrowsAfterOnError
public void Value_ThrowsAfterOnError()
{
var s = new BehaviorSubject<int>(42);
Assert.AreEqual(42, s.Value);
s.OnError(new InvalidOperationException());
Assert.Fail("Should not be able to read Value: {0}", s.Value);
}
示例5: HasObservers_OnError
public void HasObservers_OnError()
{
var s = new BehaviorSubject<int>(42);
Assert.IsFalse(s.HasObservers);
var d = s.Subscribe(_ => { }, ex => { });
Assert.IsTrue(s.HasObservers);
s.OnNext(42);
Assert.IsTrue(s.HasObservers);
s.OnError(new Exception());
Assert.IsFalse(s.HasObservers);
}
示例6: 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);
}
}
示例7: Value_ThrowsAfterOnError
public void Value_ThrowsAfterOnError()
{
var s = new BehaviorSubject<int>(42);
Assert.AreEqual(42, s.Value);
s.OnError(new InvalidOperationException());
ReactiveAssert.Throws<InvalidOperationException>(() =>
{
var ignored = s.Value;
});
ReactiveAssert.Throws<InvalidOperationException>(() =>
{
var x = default(int);
s.TryGetValue(out x);
});
}
示例8: replays_no_values_when_errored
public void replays_no_values_when_errored()
{
BehaviorSubject<int> subject = new BehaviorSubject<int>(0);
StatsObserver<int> stats = new StatsObserver<int>();
subject.OnNext(1);
subject.OnNext(2);
subject.OnNext(3);
subject.OnError(new Exception());
subject.Subscribe(stats);
Assert.AreEqual(0, stats.NextCount);
Assert.IsTrue(stats.ErrorCalled);
}
示例9: replays_error_sequence
public void replays_error_sequence()
{
BehaviorSubject<int> subject = new BehaviorSubject<int>(0);
StatsObserver<int> stats = new StatsObserver<int>();
subject.OnError(new Exception());
subject.Subscribe(stats);
Assert.IsTrue(stats.ErrorCalled);
}