@@ -90,7 +90,37 @@ public static void With(this TestScheduler sched, Action<TestScheduler> block)
90
90
sched . With ( x => { block ( x ) ; return 0 ; } ) ;
91
91
}
92
92
93
+ /// <summary>
94
+ /// WithMessageBus allows you to override the default Message Bus
95
+ /// implementation until the object returned is disposed. If a
96
+ /// message bus is not specified, a default empty one is created.
97
+ /// </summary>
98
+ /// <param name="messageBus">The message bus to use, or null to create
99
+ /// a new one using the default implementation.</param>
100
+ /// <returns>An object that when disposed, restores the original
101
+ /// message bus.</returns>
102
+ public static IDisposable WithMessageBus ( this TestScheduler sched , IMessageBus messageBus = null )
103
+ {
104
+ var origMessageBus = RxApp . MessageBus ;
105
+
106
+ RxApp . MessageBus = messageBus ?? new MessageBus ( ) ;
107
+ return Disposable . Create ( ( ) => RxApp . MessageBus = origMessageBus ) ;
108
+ }
93
109
110
+ /// <summary>
111
+ /// WithMessageBus allows you to override the default Message Bus
112
+ /// implementation for a specified action. If a message bus is not
113
+ /// specified, a default empty one is created.
114
+ /// <param name="block">The action to execute.</param>
115
+ /// <param name="messageBus">The message bus to use, or null to create
116
+ /// a new one using the default implementation.</param>
117
+ public static void WithMessageBus ( this TestScheduler sched , Action < IMessageBus > block , IMessageBus messageBus = null )
118
+ {
119
+ messageBus = messageBus ?? new MessageBus ( ) ;
120
+ using ( var _ = sched . WithMessageBus ( messageBus ) ) {
121
+ block ( messageBus ) ;
122
+ }
123
+ }
94
124
95
125
/// <summary>
96
126
/// RunToMilliseconds moves the TestScheduler to the specified time in
0 commit comments