Enqueue() public method

Adds a task to the queue specified in the task itself and sends a message to the associated channel, notifying any listeners.
public Enqueue ( RedisQueue.Net.Clients.Entities.TaskMessage t ) : void
t RedisQueue.Net.Clients.Entities.TaskMessage
return void
		public void TestMonitorWakesUpOnMessageReceived()
		{
			var task = new TaskMessage
			{
				Parameters = "blah",
				Queue = "TestQueue"
			};

			var performerMock = new Mock<Performer>();
			performerMock.SetupGet(x => x.Status).Returns(new PerformResult
			{
				Data = string.Empty,
				Outcome = Outcome.Success,
				Reason = string.Empty
			});

			performerMock.Setup(x => x.Perform(task.Parameters));

			var monitor = new RedisMonitor();
			monitor.Performer = performerMock.Object;

			var start = DateTime.Now;

			monitor.Start();
			Assert.IsTrue(monitor.Running);

			using (var client = new QueueClient())
				client.Enqueue(task);

			monitor.Stop();
			Assert.IsFalse(monitor.Running);

			var stop = DateTime.Now;
			Assert.Less((stop - start).TotalSeconds, 60);
		}
		public void TestMonitorCanRecoverFromRedisOutage()
		{
			var task = new TaskMessage
			{
				Parameters = "blah",
				Queue = "TestQueue"
			};
			
			var task2 = new TaskMessage
			{
				Parameters = "blah",
				Queue = "TestQueue"
			};

			var performerMock = new Mock<Performer>();
			performerMock.SetupGet(x => x.Status).Returns(new PerformResult
			{
				Data = string.Empty,
				Outcome = Outcome.Success,
				Reason = string.Empty
			});

			performerMock.Setup(x => x.Perform(task.Parameters));
			performerMock.Setup(x => x.Perform(task2.Parameters));

			var monitor = new RedisMonitor();
			monitor.Performer = performerMock.Object;

			monitor.Start();
			Assert.IsTrue(monitor.Running);

			using (var client = new QueueClient())
				client.Enqueue(task);

			Thread.Sleep(1500);
			RedisServer.Kill();
			
			Thread.Sleep(100);
			RedisServer.Start();
			
			Thread.Sleep(2000);
			using (var client = new QueueClient())
				client.Enqueue(task2);

			Thread.Sleep(10000);
			monitor.Stop();

			Assert.IsFalse(monitor.Running);
		}
		public void TestProcessPendingTasksForMultipleTasksMockingPerformerOnly()
		{
			#region Prepare Tasks and mock Performer for processing
			var monitor = new RedisMonitor();
			var performerMock = new Mock<Performer>();

			using (var client = new QueueClient())
			{
				for (var i = 0; i < 10; i++)
				{
					var task = new TaskMessage
					{
						Parameters = "Task " + i,
						Queue = "TestQueue"
					};

					client.Enqueue(task);
					performerMock.Setup(x => x.Perform(task.Parameters));
				}
			}

			// ensure all tasks will be successful.
			performerMock.SetupGet(x => x.Status).Returns(new PerformResult
			{
				Data = string.Empty,
				Outcome = Outcome.Success,
				Reason = string.Empty
			});
			#endregion

			monitor.Performer = performerMock.Object;
			monitor.Start();
			Thread.Sleep(2000);
			monitor.Stop();


			for (var i = 0; i < 10; i++)
				performerMock.Verify(x => x.Perform("Task " + i));

			performerMock.VerifyGet(x => x.TaskStorage);
			performerMock.VerifyGet(x => x.Status);

			using(var client = new QueueClient())
				Assert.AreEqual(client.PendingTasks("TestQueue").Count, 0);
		}