PageRenderTime 49ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/System.Reactive.Tests/System.Reactive.Linq/ObservableInvalidSubscriptionTest.cs

https://github.com/gshackles/mono-reactive
C# | 62 lines | 49 code | 7 blank | 6 comment | 2 complexity | b1b69b69e1e56a379dddeb71b708ab25 MD5 | raw file
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using NUnit.Framework;
  5. using System.Reactive;
  6. using System.Reactive.Concurrency;
  7. using System.Reactive.Linq;
  8. namespace System.Reactive.Linq.Tests
  9. {
  10. // This test fixture is a collection for invalid subscription check
  11. // i.e. they check invalid attempts to subscribe when it should not.
  12. // It is useful to see if things do not enter eager evaluation.
  13. //
  14. // They make use of ExceptionalObservable<T>.
  15. [TestFixture]
  16. public class ObservableInvalidSubscriptionTest
  17. {
  18. void Check<T> (Func<IObservable<T>, IObservable<T>> action, Action wait)
  19. {
  20. Check<T,T> (action, wait);
  21. }
  22. // The argument of the func is ExceptionalObservable, and the return value will be subscribed Console.WriteLine.
  23. void Check<TSource, TResult> (Func<IObservable<TSource>, IObservable<TResult>> action, Action wait)
  24. {
  25. var ret = action (new ExceptionalObservable<TSource> ());
  26. try {
  27. ret.Subscribe (v => Console.WriteLine (v));
  28. if (wait != null)
  29. wait ();
  30. Assert.Fail ("expected to throw ExceptionalObservableException");
  31. } catch (ExceptionalObservableException) {
  32. }
  33. }
  34. [Test]
  35. public void Amb ()
  36. {
  37. Check<int> (o => o.Amb (Observable.Range (1, 3)), null);
  38. }
  39. [Test]
  40. public void Concat ()
  41. {
  42. Check<int> (o => o.Concat (Observable.Return (5)), null);
  43. }
  44. [Test]
  45. public void Do ()
  46. {
  47. Check<int> (o => o.Do (TextWriter.Null.WriteLine), null);
  48. }
  49. [Test]
  50. public void Timestamp ()
  51. {
  52. Check<int, Timestamped<int>> (o => o.Timestamp (Scheduler.Immediate), null);
  53. }
  54. }
  55. }