public void Subscribe_MultipleSubscriptions_HandlersShouldBeCalledWithCorrectMessage() { // Arrange var channel = new EventChannel <string>(); var mockHandler1 = new Mock <ITestHandler <string> >(); var mockHandler2 = new Mock <ITestHandler <string> >(); // Act channel.Subscribe(mockHandler1.Object.Handle); channel.Subscribe(mockHandler2.Object.Handle); channel.Publish("Orange"); // Assert mockHandler1.Verify(h => h.Handle("Orange"), Times.Once()); mockHandler2.Verify(h => h.Handle("Orange"), Times.Once()); }
public void Subscribe_OneSubscription_HandlerShouldBeCalledWithCorrectMessage() { // Arrange var channel = new EventChannel <string>(); var mockHandler = new Mock <ITestHandler <string> >(); // Act channel.Subscribe(mockHandler.Object.Handle); channel.Publish("Apple"); // Assert mockHandler.Verify(h => h.Handle("Apple"), Times.Once()); }
public void BasicTest() { IEventChannel eventChannel = new EventChannel(); using AutoResetEvent reset = new AutoResetEvent(false); void Receive() { reset.Set(); } using Fiber fiber = new Fiber(); eventChannel.Subscribe(fiber, Receive); eventChannel.Trigger(); Assert.IsTrue(reset.WaitOne(TimeSpan.FromSeconds(1))); }
public static ValueTask <ISubscribeResult> Subscribe <T>(EventChannel <T> eventChannel, CancellationToken unsubscribe) { return(new ValueTask <ISubscribeResult>(eventChannel.Subscribe(unsubscribe))); }
public static ISubscribeResult Subscribe <T>(EventChannel <T> eventChannel, CancellationToken unsubscribe) { return(eventChannel.Subscribe(unsubscribe)); }
public ValueTask <ISubscribeResult> JoinAsync(CancellationToken unsubscribe) { return(new ValueTask <ISubscribeResult>(_messageStream.Subscribe(unsubscribe))); }