public void ReturnFalse_GivenNoMessagesInQueue() { var sut = new MessageDispatcher(); var result = sut.CheckMessages(62); Assert.IsFalse(result); }
public void AddMessagesToQueueIfItsTimeToDispatch() { var sut = new MessageDispatcher(); sut.Publish(new RepeatingMessage(60, "Hello!")); var result = sut.CheckMessages(62); Assert.IsTrue(result); }
public void AddOneMessageToTheQueue_IfTimeToDispatch() { var sut = new MessageDispatcher(); sut.Publish(new AlwaysReadyMessage()); sut.CheckMessages(10); Assert.IsNotEmpty(sut.QueuedMessages); }
public void ReturnFalse_GivenMessagesToSendInFuture() { var sut = new MessageDispatcher(); sut.Publish(new RepeatingMessage(120, "Hello from future!")); var result = sut.CheckMessages(62); Assert.IsFalse(result); }
public void PopOffMessageFromQueue_AfterReturningMessage() { var sut = new MessageDispatcher(); sut.Publish(new AlwaysReadyMessage()); sut.CheckMessages(10); sut.TryDequeueMessage(out _); Assert.AreEqual(0, sut.QueuedMessages.Count); }
public void ReturnTrue_AfterReturningMessage() { var sut = new MessageDispatcher(); sut.Publish(new AlwaysReadyMessage()); sut.CheckMessages(10); var result = sut.TryDequeueMessage(out _); Assert.IsTrue(result); }
public void AddOnlyOneMessageToTheQueue_GivenManyMesages_OnlyOneReady() { var sut = new MessageDispatcher(); sut.Publish(new AlwaysReadyMessage()); sut.Publish(new RepeatingMessage(120, "Häpp")); sut.Publish(new RepeatingMessage(70, "Hupp")); sut.CheckMessages(10); Assert.AreEqual(1, sut.QueuedMessages.Count); }
public void ReturnQueuedMessage() { var sut = new MessageDispatcher(); var alwaysReadyMessage = new AlwaysReadyMessage(); sut.Publish(alwaysReadyMessage); sut.CheckMessages(10); sut.TryDequeueMessage(out var actual); Assert.AreEqual(alwaysReadyMessage.Message, actual); }
// ReSharper disable once FunctionNeverReturns private void BeginLoop() { var sw = Stopwatch.StartNew(); Task.Run(() => { while (_tokenSource.IsCancellationRequested != true) { _dispatcher.CheckMessages((int)sw.ElapsedMilliseconds); while (_dispatcher.TryDequeueMessage(out var message)) { foreach (var c in _chatClients) { c.SendMessage(message); } } Thread.Sleep(REFRESH_INTERVAL); } }); }