WaitTest.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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.Reactive.Concurrency;
  6. using System.Reactive.Linq;
  7. using Microsoft.Reactive.Testing;
  8. using Xunit;
  9. namespace ReactiveTests.Tests
  10. {
  11. public class WaitTest : ReactiveTest
  12. {
  13. [Fact]
  14. public void Wait_ArgumentChecking()
  15. {
  16. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.Wait(default(IObservable<int>)));
  17. }
  18. #if !NO_THREAD
  19. [Fact]
  20. public void Wait_Return()
  21. {
  22. var x = 42;
  23. var xs = Observable.Return(x, ThreadPoolScheduler.Instance);
  24. var res = xs.Wait();
  25. Assert.Equal(x, res);
  26. }
  27. #endif
  28. [Fact]
  29. public void Wait_Empty()
  30. {
  31. ReactiveAssert.Throws<InvalidOperationException>(() => Observable.Empty<int>().Wait());
  32. }
  33. [Fact]
  34. public void Wait_Throw()
  35. {
  36. var ex = new Exception();
  37. var xs = Observable.Throw<int>(ex);
  38. ReactiveAssert.Throws(ex, () => xs.Wait());
  39. }
  40. #if !NO_THREAD
  41. [Fact]
  42. public void Wait_Range()
  43. {
  44. var n = 42;
  45. var xs = Observable.Range(1, n, ThreadPoolScheduler.Instance);
  46. var res = xs.Wait();
  47. Assert.Equal(n, res);
  48. }
  49. #endif
  50. }
  51. }