WaitTest.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. [TestMethod]
  21. public void Wait_Return()
  22. {
  23. var x = 42;
  24. var xs = Observable.Return(x, ThreadPoolScheduler.Instance);
  25. var res = xs.Wait();
  26. Assert.Equal(x, res);
  27. }
  28. [TestMethod]
  29. public void Wait_Empty()
  30. {
  31. ReactiveAssert.Throws<InvalidOperationException>(() => Observable.Empty<int>().Wait());
  32. }
  33. [TestMethod]
  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. [TestMethod]
  41. public void Wait_Range()
  42. {
  43. var n = 42;
  44. var xs = Observable.Range(1, n, ThreadPoolScheduler.Instance);
  45. var res = xs.Wait();
  46. Assert.Equal(n, res);
  47. }
  48. }
  49. }