public void PublishTestBeforeRegisterGeneric() { var topic = new MessageTopic <object>(); object objPublished = null; topic.Register <object>().Subscribe(o => objPublished = o); var obj = new object(); topic.Publish(obj); object secondObjPublished = null; topic.Register <object>().Subscribe(o => secondObjPublished = o); Assert.Equal(obj, objPublished); Assert.Null(secondObjPublished); var obj2 = new object(); topic.Publish(obj2); Assert.Equal(obj2, objPublished); Assert.Equal(obj2, secondObjPublished); }
public void PublishTestDifferentMessageTypes() { var topic = new MessageTopic(); object msgPublished = null; var strPublished = false; topic.Register <object>() .Subscribe(o => msgPublished = o); topic.Register <string>() .Subscribe(_ => strPublished = true); var msg = new object(); topic.Publish(msg); Assert.Equal(msg, msgPublished); Assert.False(strPublished); const string msgStr = "TestMsg"; topic.Publish(msgStr); Assert.Equal(msgStr, msgPublished); Assert.True(strPublished); }
public void PublishTest() { var topic = new MessageTopic <object>(); topic.Publish("Test"); Assert.Throws <ArgumentNullException>(() => topic.Publish(null)); }
public void RegisterTest() { var topic = new MessageTopic <object>(); object msgPublished = null; topic.Register().Subscribe(o => msgPublished = o); var msg = new object(); topic.Publish(msg); Assert.Equal(msg, msgPublished); }