WaitTest.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Reactive;
  10. using System.Reactive.Concurrency;
  11. using System.Reactive.Linq;
  12. using Microsoft.Reactive.Testing;
  13. using Xunit;
  14. using ReactiveTests.Dummies;
  15. using System.Reflection;
  16. namespace ReactiveTests.Tests
  17. {
  18. public class WaitTest : ReactiveTest
  19. {
  20. [Fact]
  21. public void Wait_ArgumentChecking()
  22. {
  23. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.Wait(default(IObservable<int>)));
  24. }
  25. #if !NO_THREAD
  26. [Fact]
  27. public void Wait_Return()
  28. {
  29. var x = 42;
  30. var xs = Observable.Return(x, ThreadPoolScheduler.Instance);
  31. var res = xs.Wait();
  32. Assert.Equal(x, res);
  33. }
  34. #endif
  35. [Fact]
  36. public void Wait_Empty()
  37. {
  38. ReactiveAssert.Throws<InvalidOperationException>(() => Observable.Empty<int>().Wait());
  39. }
  40. [Fact]
  41. public void Wait_Throw()
  42. {
  43. var ex = new Exception();
  44. var xs = Observable.Throw<int>(ex);
  45. ReactiveAssert.Throws(ex, () => xs.Wait());
  46. }
  47. #if !NO_THREAD
  48. [Fact]
  49. public void Wait_Range()
  50. {
  51. var n = 42;
  52. var xs = Observable.Range(1, n, ThreadPoolScheduler.Instance);
  53. var res = xs.Wait();
  54. Assert.Equal(n, res);
  55. }
  56. #endif
  57. }
  58. }