EmptyTest.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 System.Threading;
  8. using Microsoft.Reactive.Testing;
  9. using ReactiveTests.Dummies;
  10. using Xunit;
  11. namespace ReactiveTests.Tests
  12. {
  13. public class EmptyTest : ReactiveTest
  14. {
  15. [Fact]
  16. public void Empty_ArgumentChecking()
  17. {
  18. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.Empty<int>(null));
  19. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.Empty(null, 42));
  20. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.Empty<int>(DummyScheduler.Instance).Subscribe(null));
  21. }
  22. [Fact]
  23. public void Empty_Basic()
  24. {
  25. var scheduler = new TestScheduler();
  26. var res = scheduler.Start(() =>
  27. Observable.Empty<int>(scheduler)
  28. );
  29. res.Messages.AssertEqual(
  30. OnCompleted<int>(201)
  31. );
  32. }
  33. [Fact]
  34. public void Empty_Disposed()
  35. {
  36. var scheduler = new TestScheduler();
  37. var res = scheduler.Start(() =>
  38. Observable.Empty<int>(scheduler),
  39. 200
  40. );
  41. res.Messages.AssertEqual(
  42. );
  43. }
  44. [Fact]
  45. public void Empty_ObserverThrows()
  46. {
  47. var scheduler1 = new TestScheduler();
  48. var xs = Observable.Empty<int>(scheduler1);
  49. xs.Subscribe(x => { }, exception => { }, () => { throw new InvalidOperationException(); });
  50. ReactiveAssert.Throws<InvalidOperationException>(() => scheduler1.Start());
  51. }
  52. [Fact]
  53. public void Empty_DefaultScheduler()
  54. {
  55. Observable.Empty<int>().AssertEqual(Observable.Empty<int>(DefaultScheduler.Instance));
  56. }
  57. [Fact]
  58. public void Empty_Basic_Witness1()
  59. {
  60. var scheduler = new TestScheduler();
  61. var res = scheduler.Start(() =>
  62. Observable.Empty(scheduler, 42)
  63. );
  64. res.Messages.AssertEqual(
  65. OnCompleted<int>(201)
  66. );
  67. }
  68. [Fact]
  69. public void Empty_Basic_Witness2()
  70. {
  71. var e = new ManualResetEvent(false);
  72. Observable.Empty(42).Subscribe(
  73. _ => { Assert.True(false); },
  74. _ => { Assert.True(false); },
  75. () => e.Set()
  76. );
  77. e.WaitOne();
  78. }
  79. }
  80. }