public void AddMessage_WhenCalled_CanAddMessageToChannel() { const string channelName = "channel-01"; const string channelEvent = "event-01"; const string message = "hello world"; var inMemoryLiteMessageBusService = new InMemoryLiteMessageBusService(); inMemoryLiteMessageBusService.AddMessage <string>(channelName, channelEvent, message); // As no exception occurs, the method runs successfully. Assert.Pass(); }
static void Main(string[] args) { Console.WriteLine("App started"); var inMemoryMessageBus = new InMemoryLiteMessageBusService(); inMemoryMessageBus.HookMessageChannel <string>(MessageChannelConstants.Ui, MessageEventConstants.SendMessage) .Subscribe(message => Console.WriteLine( $"[IN-MEMORY] {DateTime.UtcNow:yyyy-MM-dd HH:mm:ss} - Message received: {message}")); //const string appId = "875585"; //const string appKey = "7924946bbbd2fc014135"; //const string appSecret = "a6c2c1f9ae29637d995a"; //const string cluster = "ap1"; //var pusherServerOptions = new PusherServer.PusherOptions(); //pusherServerOptions.Cluster = cluster; //pusherServerOptions.Encrypted = true; //var pusherClientOptions = new PusherClient.PusherOptions(); //pusherClientOptions.Cluster = cluster; //pusherClientOptions.Encrypted = true; //var broadcaster = new PusherServer.Pusher(appId, // appKey, appSecret, pusherServerOptions); //var recipient = new PusherClient.Pusher(appKey, pusherClientOptions); //// Pusher message bus initialization. //var pusherMessageBus = new PusherLiteMessageBusService(broadcaster, recipient); //pusherMessageBus // .HookMessageChannel<Item>(MessageChannelConstants.Ui, MessageEventConstants.SendMessage) // .Subscribe(message => // { // Console.WriteLine( // $"[PUSHER] {DateTime.UtcNow:yyyy-MM-dd HH:mm:ss} - Message received: {message}"); // }); //recipient.ConnectAsync().Wait(); //var item = new Item(); //item.Name = "item-name-01"; //item.Quantity = 10; inMemoryMessageBus.AddMessage(MessageChannelConstants.Ui, MessageEventConstants.SendMessage, "Hello world"); //pusherMessageBus.AddMessage(MessageChannelConstants.Ui, MessageEventConstants.SendMessage, item); //Console.WriteLine("App started"); Console.ReadLine(); }
public void AddMessage_WhenCalled_CanHookAddedMessage() { const string channelName = "channel-01"; const string channelEvent = "event-01"; const string message = "hello world"; var loadedMessage = string.Empty; var inMemoryLiteMessageBusService = new InMemoryLiteMessageBusService(); // Hook to message channel first. var hooker = inMemoryLiteMessageBusService.HookMessageChannel <string>(channelName, channelEvent); hooker.Subscribe(innerMessage => loadedMessage = innerMessage); // Add message to channel. inMemoryLiteMessageBusService.AddMessage(channelName, channelEvent, message); Assert.That(loadedMessage, Is.EqualTo(message).After(2000, 500)); }
public void DeleteMessage_WhenCalled_CannotGetDeletedMessage() { const string channelName = "channel-01"; const string channelEvent = "event-01"; const string message = "hello world"; var actualMessage = string.Empty; var inMemoryLiteMessageBusService = new InMemoryLiteMessageBusService(); inMemoryLiteMessageBusService.AddMessage(channelName, channelEvent, message); // Delete the message. inMemoryLiteMessageBusService.DeleteMessage(channelName, channelEvent); // Hook to the message channel. var hooker = inMemoryLiteMessageBusService.HookMessageChannel <string>(channelName, channelEvent); hooker.Subscribe(m => actualMessage = m); Assert.That(actualMessage, Is.Not.EqualTo(message).After(2000, 500)); }
public void DeleteMessages_WhenCalled_CannotSubscribeToChannelsDeletedMessages() { const string channelName = "channel-01"; const string channelEvent = "event-01"; const string message = "hello world"; var hasChannelSubscribed = false; var inMemoryLiteMessageBusService = new InMemoryLiteMessageBusService(); inMemoryLiteMessageBusService.AddMessage(channelName, channelEvent, message); // Delete the message. inMemoryLiteMessageBusService.DeleteMessages(); // Hook to the message channel. var hooker = inMemoryLiteMessageBusService.HookMessageChannel <string>(channelName, channelEvent); hooker.Subscribe(_ => hasChannelSubscribed = true); Assert.That(hasChannelSubscribed, Is.Not.True.After(2000, 500)); }