MaterializeTest.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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;
  6. using System.Reactive.Linq;
  7. using Microsoft.Reactive.Testing;
  8. using Microsoft.VisualStudio.TestTools.UnitTesting;
  9. namespace ReactiveTests.Tests
  10. {
  11. [TestClass]
  12. public class MaterializeTest : ReactiveTest
  13. {
  14. [TestMethod]
  15. public void Materialize_ArgumentChecking()
  16. {
  17. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.Materialize<int>(null));
  18. }
  19. [TestMethod]
  20. public void Materialize_Never()
  21. {
  22. var scheduler = new TestScheduler();
  23. var res = scheduler.Start(() =>
  24. Observable.Never<int>().Materialize()
  25. );
  26. res.Messages.AssertEqual(
  27. );
  28. }
  29. [TestMethod]
  30. public void Materialize_Empty()
  31. {
  32. var scheduler = new TestScheduler();
  33. var xs = scheduler.CreateHotObservable(
  34. OnNext(150, 1),
  35. OnCompleted<int>(250)
  36. );
  37. var res = scheduler.Start(() =>
  38. xs.Materialize()
  39. );
  40. res.Messages.AssertEqual(
  41. OnNext(250, Notification.CreateOnCompleted<int>()),
  42. OnCompleted<Notification<int>>(250)
  43. );
  44. xs.Subscriptions.AssertEqual(
  45. Subscribe(200, 250)
  46. );
  47. }
  48. [TestMethod]
  49. public void Materialize_Return()
  50. {
  51. var scheduler = new TestScheduler();
  52. var xs = scheduler.CreateHotObservable(
  53. OnNext(150, 1),
  54. OnNext(210, 2),
  55. OnCompleted<int>(250)
  56. );
  57. var res = scheduler.Start(() =>
  58. xs.Materialize()
  59. );
  60. res.Messages.AssertEqual(
  61. OnNext(210, Notification.CreateOnNext(2)),
  62. OnNext(250, Notification.CreateOnCompleted<int>()),
  63. OnCompleted<Notification<int>>(250)
  64. );
  65. xs.Subscriptions.AssertEqual(
  66. Subscribe(200, 250)
  67. );
  68. }
  69. [TestMethod]
  70. public void Materialize_Throw()
  71. {
  72. var scheduler = new TestScheduler();
  73. var ex = new Exception();
  74. var xs = scheduler.CreateHotObservable(
  75. OnNext(150, 1),
  76. OnError<int>(250, ex)
  77. );
  78. var res = scheduler.Start(() =>
  79. xs.Materialize()
  80. );
  81. res.Messages.AssertEqual(
  82. OnNext(250, Notification.CreateOnError<int>(ex)),
  83. OnCompleted<Notification<int>>(250)
  84. );
  85. xs.Subscriptions.AssertEqual(
  86. Subscribe(200, 250)
  87. );
  88. }
  89. }
  90. }