public void ShouldKeepCountOfSubscriptions() { var coursier = new Coursier(); var subOne = coursier.Subscribe <TestMessageOne>(msg => { }); coursier.Subscribe <TestMessageOne>(msg => { }); Assert.Equal(2, coursier.SubscriptionCount <TestMessageOne>()); coursier.Unsubscribe <TestMessageOne>(subOne); Assert.Equal(1, coursier.SubscriptionCount <TestMessageOne>()); }
public void ShouldClearAllSubscriptions() { var coursier = new Coursier(); var msgOneReceived = false; var msgTwoReceived = false; coursier.Subscribe <TestMessageOne>(msg => { msgOneReceived = true; }); coursier.Subscribe <TestMessageTwo>(msg => { msgTwoReceived = true; }); coursier.ClearAllSubscriptions(); coursier.Publish(new TestMessageOne(this)); coursier.Publish(new TestMessageTwo(this)); Assert.False(msgOneReceived); Assert.False(msgTwoReceived); }
public void ShouldPublishMessage() { var coursier = new Coursier(); var msgReceived = false; coursier.Subscribe <TestMessageOne>(msg => { msgReceived = true; }); coursier.Publish(new TestMessageOne(this)); Assert.True(msgReceived); }
public void ShouldNotReceiveMessageIfUnSubscribed() { var coursier = new Coursier(); var msgReceived = false; var token = coursier.Subscribe <TestMessageOne>(msg => { msgReceived = true; }); coursier.Unsubscribe <TestMessageOne>(token); coursier.Publish(new TestMessageOne(this)); Assert.False(msgReceived); }
public void ShouldRegisterAndInvokeAsyncHandler() { var coursier = new Coursier(); var msgReceived = false; coursier.Subscribe <TestMessageOne>(async msg => { await Task.Run(() => { msgReceived = true; }); }); coursier.Publish(new TestMessageOne(this)); Thread.Sleep(1000); Assert.True(msgReceived); }
public void ShouldThrowIfSubscribingToBaseMessage() { var coursier = new Coursier(); Assert.Throws <InvalidOperationException>(() => coursier.Subscribe <BaseMessage>(msg => { })); }