Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Dec 27, 2023
1 parent 8bbf488 commit c14cbfd
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 3 deletions.
2 changes: 0 additions & 2 deletions src/R3/Operators/AsObservable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

public static partial class ObservableExtensions
{
// TODO: test

public static Observable<T> AsObservable<T>(this Observable<T> source)
{
if (source is AsObservable<T>) // already hide
Expand Down
2 changes: 1 addition & 1 deletion src/R3/Operators/_Operators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
74 changes: 74 additions & 0 deletions tests/R3.Tests/OperatorTests/AsObservableTest.cs
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 tests/R3.Tests/OperatorTests/OnErrorResumeAsFailureTest.cs
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");

}
}

0 comments on commit c14cbfd

Please sign in to comment.