WaitTest.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT 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 Microsoft.VisualStudio.TestTools.UnitTesting;
  9. using Assert = Xunit.Assert;
  10. namespace ReactiveTests.Tests
  11. {
  12. [TestClass]
  13. public class WaitTest : ReactiveTest
  14. {
  15. [TestMethod]
  16. public void Wait_ArgumentChecking()
  17. {
  18. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.Wait(default(IObservable<int>)));
  19. }
  20. #if !NO_THREAD
  21. [TestMethod]
  22. public void Wait_Return()
  23. {
  24. var x = 42;
  25. var xs = Observable.Return(x, ThreadPoolScheduler.Instance);
  26. var res = xs.Wait();
  27. Assert.Equal(x, res);
  28. }
  29. #endif
  30. [TestMethod]
  31. public void Wait_Empty()
  32. {
  33. ReactiveAssert.Throws<InvalidOperationException>(() => Observable.Empty<int>().Wait());
  34. }
  35. [TestMethod]
  36. public void Wait_Throw()
  37. {
  38. var ex = new Exception();
  39. var xs = Observable.Throw<int>(ex);
  40. ReactiveAssert.Throws(ex, () => xs.Wait());
  41. }
  42. #if !NO_THREAD
  43. [TestMethod]
  44. public void Wait_Range()
  45. {
  46. var n = 42;
  47. var xs = Observable.Range(1, n, ThreadPoolScheduler.Instance);
  48. var res = xs.Wait();
  49. Assert.Equal(n, res);
  50. }
  51. #endif
  52. }
  53. }