Created
October 12, 2015 18:35
-
-
Save KevM/6a0bdbf77907cd853fb6 to your computer and use it in GitHub Desktop.
IObservable extensions for testing
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
public static class ObservableExtensions | |
{ | |
public static Func<bool> WasObserved<T>(this IObservable<T> o, T expected) | |
{ | |
var wasExpectedObserved = false; | |
var result = o.Subscribe(s => | |
{ | |
wasExpectedObserved = s.Equals(expected); | |
}); | |
return () => | |
{ | |
result.Dispose(); | |
return wasExpectedObserved; | |
}; | |
} | |
public static Func<IEnumerable<T>> CaptureObserved<T>(this IObservable<T> o) | |
{ | |
var result = new List<T>(); | |
var sub = o.Subscribe(s => | |
{ | |
result.Add(s); | |
}); | |
return () => | |
{ | |
sub.Dispose(); | |
return result; | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment