-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
96 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
namespace R3.Tests.OperatorTests; | ||
|
||
public class AsObservableTest | ||
{ | ||
[Fact] | ||
public void AsObservable() | ||
{ | ||
var p = new Subject<int>(); | ||
|
||
var l = p.AsObservable().AsObservable().ToLiveList(); | ||
p.OnNext(1); | ||
p.OnNext(2); | ||
p.OnNext(3); | ||
p.OnCompleted(); | ||
|
||
l.AssertEqual([1, 2, 3]); | ||
l.AssertIsCompleted(); | ||
} | ||
|
||
[Fact] | ||
public void AsIObservable() | ||
{ | ||
|
||
{ | ||
var p = new Subject<int>(); | ||
var l = new List<int>(); | ||
Exception? ex = null; | ||
bool completed = false; | ||
p.AsIObservable().Subscribe(l.Add, e => ex = e, () => completed = true); | ||
|
||
p.OnNext(1); | ||
p.OnNext(2); | ||
p.OnNext(3); | ||
p.OnCompleted(); | ||
|
||
l.Should().Equal([1, 2, 3]); | ||
completed.Should().BeTrue(); | ||
} | ||
{ | ||
// error complete | ||
var p = new Subject<int>(); | ||
var l = new List<int>(); | ||
Exception? ex = null; | ||
bool completed = false; | ||
p.AsIObservable().Subscribe(l.Add, e => ex = e, () => completed = true); | ||
|
||
p.OnNext(1); | ||
p.OnNext(2); | ||
p.OnNext(3); | ||
p.OnCompleted(new Exception("aaa")); | ||
|
||
l.Should().Equal([1, 2, 3]); | ||
ex!.Message.Should().Be("aaa"); | ||
completed.Should().BeFalse(); | ||
} | ||
{ | ||
// error resume | ||
var p = new Subject<int>(); | ||
var l = new List<int>(); | ||
Exception? ex = null; | ||
bool completed = false; | ||
p.AsIObservable().Subscribe(l.Add, e => ex = e, () => completed = true); | ||
|
||
p.OnNext(1); | ||
p.OnNext(2); | ||
p.OnNext(3); | ||
p.OnErrorResume(new Exception("bbb")); | ||
|
||
l.Should().Equal([1, 2, 3]); | ||
ex!.Message.Should().Be("bbb"); | ||
completed.Should().BeFalse(); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
tests/R3.Tests/OperatorTests/OnErrorResumeAsFailureTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace R3.Tests.OperatorTests; | ||
|
||
public class OnErrorResumeAsFailureTest | ||
{ | ||
|
||
[Fact] | ||
public void OnErrorResumeAsFailure() | ||
{ | ||
var subject = new Subject<int>(); | ||
var list = subject.OnErrorResumeAsFailure().ToLiveList(); | ||
|
||
|
||
subject.OnNext(10); | ||
subject.OnErrorResume(new Exception("foo")); | ||
|
||
list.AssertEqual([10]); | ||
list.AssertIsCompleted(); | ||
list.CompletedValue.Exception!.Message.Should().Be("foo"); | ||
|
||
} | ||
} |