How to make this test pass without using the Subject class or .NET events?
[TestClass]
public class ObservableTests
{
private readonly Subject<Unit> _subject = new Subject<Unit>();
[TestMethod]
public void ObservesMethodCall()
{
var eventCount = 0;
IObservable<Unit> observable = _subject.AsObservable();
observable.Subscribe(u => eventCount++);
Assert.AreEqual(0, eventCount);
Foo();
Assert.AreEqual(1, eventCount);
}
private void Foo()
{
_subject.OnNext(Unit.Default);
}
}
I want to avoid using subjects as they are not recommended. I don't want to use .NET events as RxNet supersedes them.
Related questions:
Firing an event every time a new method is called
It assumes we cannot modify the method being called.
How to create Observable that emits every time a member variable is updated (onCompleted never called)
Uses subjects.
Is there a way to create an observable sequence triggered by method calls without using Subject?
States Subjects are the way to go. However, I still want to learn how to do it without Subjects.
IObserver and IObservable in C# for Observer vs Delegates, Events
Shows how to solve the problem by implementing custom IObservable