diff --git a/src/R3/Operators/AsObservable.cs b/src/R3/Operators/AsObservable.cs index 1bfed5ce..abcac956 100644 --- a/src/R3/Operators/AsObservable.cs +++ b/src/R3/Operators/AsObservable.cs @@ -2,8 +2,6 @@ public static partial class ObservableExtensions { - // TODO: test - public static Observable AsObservable(this Observable source) { if (source is AsObservable) // already hide diff --git a/src/R3/Operators/_Operators.cs b/src/R3/Operators/_Operators.cs index ffaca00b..4d1732a3 100644 --- a/src/R3/Operators/_Operators.cs +++ b/src/R3/Operators/_Operators.cs @@ -20,7 +20,7 @@ public static partial class ObservableExtensions // Buffer + BUfferFrame => Chunk, ChunkFrame // Rx Merging: - //CombineLatest, Merge, Zip, WithLatestFrom, ZipLatest, Switch + // CombineLatest, Zip, WithLatestFrom, ZipLatest, Switch // Standard Query: // Distinct, DistinctBy, DistinctUntilChanged, Scan diff --git a/tests/R3.Tests/OperatorTests/AsObservableTest.cs b/tests/R3.Tests/OperatorTests/AsObservableTest.cs new file mode 100644 index 00000000..e160da49 --- /dev/null +++ b/tests/R3.Tests/OperatorTests/AsObservableTest.cs @@ -0,0 +1,74 @@ +namespace R3.Tests.OperatorTests; + +public class AsObservableTest +{ + [Fact] + public void AsObservable() + { + var p = new Subject(); + + 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(); + var l = new List(); + 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(); + var l = new List(); + 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(); + var l = new List(); + 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(); + } + } +} diff --git a/tests/R3.Tests/OperatorTests/OnErrorResumeAsFailureTest.cs b/tests/R3.Tests/OperatorTests/OnErrorResumeAsFailureTest.cs new file mode 100644 index 00000000..f67e0503 --- /dev/null +++ b/tests/R3.Tests/OperatorTests/OnErrorResumeAsFailureTest.cs @@ -0,0 +1,21 @@ +namespace R3.Tests.OperatorTests; + +public class OnErrorResumeAsFailureTest +{ + + [Fact] + public void OnErrorResumeAsFailure() + { + var subject = new Subject(); + 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"); + + } +}