IsEmptyTest.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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.Linq;
  6. using Microsoft.Reactive.Testing;
  7. using Xunit;
  8. namespace ReactiveTests.Tests
  9. {
  10. public class IsEmptyTest : ReactiveTest
  11. {
  12. [Fact]
  13. public void IsEmpty_ArgumentChecking()
  14. {
  15. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.IsEmpty(default(IObservable<int>)));
  16. }
  17. [Fact]
  18. public void IsEmpty_Empty()
  19. {
  20. var scheduler = new TestScheduler();
  21. var xs = scheduler.CreateHotObservable(
  22. OnNext(150, 1),
  23. OnCompleted<int>(250)
  24. );
  25. var res = scheduler.Start(() =>
  26. xs.IsEmpty()
  27. );
  28. res.Messages.AssertEqual(
  29. OnNext(250, true),
  30. OnCompleted<bool>(250)
  31. );
  32. xs.Subscriptions.AssertEqual(
  33. Subscribe(200, 250)
  34. );
  35. }
  36. [Fact]
  37. public void IsEmpty_Return()
  38. {
  39. var scheduler = new TestScheduler();
  40. var xs = scheduler.CreateHotObservable(
  41. OnNext(150, 1),
  42. OnNext(210, 2),
  43. OnCompleted<int>(250)
  44. );
  45. var res = scheduler.Start(() =>
  46. xs.IsEmpty()
  47. );
  48. res.Messages.AssertEqual(
  49. OnNext(210, false),
  50. OnCompleted<bool>(210)
  51. );
  52. xs.Subscriptions.AssertEqual(
  53. Subscribe(200, 210)
  54. );
  55. }
  56. [Fact]
  57. public void IsEmpty_Throw()
  58. {
  59. var ex = new Exception();
  60. var scheduler = new TestScheduler();
  61. var xs = scheduler.CreateHotObservable(
  62. OnNext(150, 1),
  63. OnError<int>(210, ex)
  64. );
  65. var res = scheduler.Start(() =>
  66. xs.IsEmpty()
  67. );
  68. res.Messages.AssertEqual(
  69. OnError<bool>(210, ex)
  70. );
  71. xs.Subscriptions.AssertEqual(
  72. Subscribe(200, 210)
  73. );
  74. }
  75. [Fact]
  76. public void IsEmpty_Never()
  77. {
  78. var ex = new Exception();
  79. var scheduler = new TestScheduler();
  80. var xs = scheduler.CreateHotObservable(
  81. OnNext(150, 1)
  82. );
  83. var res = scheduler.Start(() =>
  84. xs.IsEmpty()
  85. );
  86. res.Messages.AssertEqual(
  87. );
  88. xs.Subscriptions.AssertEqual(
  89. Subscribe(200, 1000)
  90. );
  91. }
  92. }
  93. }