public void StopAfterMaxWaitTime() { ConsumePendingMessagesBeforeStopExtension extension = new ConsumePendingMessagesBeforeStopExtension(1000, 10); extension.ModuleController = m_moduleController; extension.Attach(); // Not stopping. bool cancel; m_moduleController.RaiseBeforeEnqueueMessageEvent("Test", 77, out cancel); Assert.IsFalse(cancel); m_moduleController.EnqueueMessage(77); Assert.AreEqual(1, m_moduleController.EnquedMessages.Count); // Stopping. DateTime beforeCallDateTime = DateTime.Now; m_moduleController.RaiseBeforeModuleStopEvent(); DateTime afterCallDateTime = DateTime.Now; TimeSpan callTimeSpan = afterCallDateTime - beforeCallDateTime; Assert.IsTrue((callTimeSpan.TotalMilliseconds > 800) && (callTimeSpan.TotalMilliseconds < 1200)); m_moduleController.RaiseBeforeEnqueueMessageEvent("Test", 88, out cancel); Assert.IsTrue(cancel); m_moduleController.RaiseAfterModuleStopEvent(); extension.Detach(); }
public void EmptyMessageQueueOnStop() { ConsumePendingMessagesBeforeStopExtension extension = new ConsumePendingMessagesBeforeStopExtension(1000, 400); extension.ModuleController = m_moduleController; extension.Attach(); // Stopping. DateTime beforeCallDateTime = DateTime.Now; m_moduleController.RaiseBeforeModuleStopEvent(); DateTime afterCallDateTime = DateTime.Now; TimeSpan callTimeSpan = afterCallDateTime - beforeCallDateTime; Assert.IsTrue((callTimeSpan.TotalMilliseconds < 100)); m_moduleController.RaiseAfterModuleStopEvent(); extension.Detach(); }