Ejemplo n.º 1
0
        public void TestEnqueueAndDelete100Tasks()
        {
            var client = new QueueClient();

            for (var i = 0; i < 100; i++)
            {
                client.Enqueue(new TaskMessage
                {
                    Parameters = "params",
                    Queue      = "TestQueue"
                });
            }

            Assert.AreEqual(client.AllTasks("TestQueue").Count, 100);

            var deletedTasks = 0;

            while (client.AllTasks("TestQueue").Count > 0)
            {
                client.RemoveTask(client.AllTasks("TestQueue")[0]);
                deletedTasks++;
            }

            Assert.AreEqual(deletedTasks, 100);
        }
Ejemplo n.º 2
0
        public void TestModifyTaskOnCollectionThenAssertModificationDoesNotWork()
        {
            using (var client = new QueueClient())
            {
                // first enqueue a simple task.
                client.Enqueue(new TaskMessage
                {
                    Parameters = "Test Params",
                    Queue      = "TestQueue"
                });

                // now modify the task from within the collection.
                client.PendingTasks("TestQueue")[0].Parameters = "Test Params 2";
            }

            // Dispose of the previous client to ensure modifications dont persist in its memory.
            using (var client = new QueueClient())
            {
                // using a new client, read the task again.
                var task = client.PendingTasks("TestQueue")[0];

                Assert.AreEqual(task.Parameters, "Test Params");

                client.RemoveTask(client.AllTasks("TestQueue")[0]);
            }
        }
Ejemplo n.º 3
0
        public void TestCantReserveMultipleTasksAtOnce()
        {
            using (var client = new QueueClient())
            {
                client.Enqueue(new TaskMessage
                {
                    Parameters = "params",
                    Queue      = "TestQueue"
                });

                client.Enqueue(new TaskMessage
                {
                    Parameters = "params",
                    Queue      = "TestQueue"
                });

                client.Reserve("TestQueue");
                Assert.Throws <TaskAlreadyReservedException>(() => client.Reserve("TestQueue"));

                client.Fail(string.Empty);
                client.RemoveTask(client.AllTasks("TestQueue")[0]);
                client.RemoveTask(client.AllTasks("TestQueue")[0]);
            }
        }
		public void TestCachingCreatesAFile()
		{
			using (var client = new QueueClient())
			{
				var homemadeTask = new TaskMessage
				{
					Parameters = "params",
					Queue = "TestQueue"
				};

				client.Enqueue(homemadeTask);
				var retrievedTask = client.Reserve("TestQueue");

				Assert.That(File.Exists("redisCache.bin"));

				client.Fail(string.Empty);
				client.RemoveTask(client.AllTasks("TestQueue")[0]);
			}
		}
Ejemplo n.º 5
0
        public void TestCachingCreatesAFile()
        {
            using (var client = new QueueClient())
            {
                var homemadeTask = new TaskMessage
                {
                    Parameters = "params",
                    Queue      = "TestQueue"
                };

                client.Enqueue(homemadeTask);
                var retrievedTask = client.Reserve("TestQueue");

                Assert.That(File.Exists("redisCache.bin"));

                client.Fail(string.Empty);
                client.RemoveTask(client.AllTasks("TestQueue")[0]);
            }
        }
		public void TestCanEnqueueTaskInRedisAndReadItBack()
		{
			using(var client = new QueueClient())
			{
				var homemadeTask = new TaskMessage
				{
					Parameters = "params", 
					Queue = "TestQueue"
				};

				client.Enqueue(homemadeTask);
				var retrievedTask = client.Reserve("TestQueue");
			
				Assert.AreEqual(retrievedTask.Parameters, homemadeTask.Parameters);
				Assert.AreEqual(retrievedTask.Queue, homemadeTask.Queue);

				client.Fail(string.Empty);
				client.RemoveTask(client.AllTasks("TestQueue")[0]);
			}
		}
Ejemplo n.º 7
0
        public void TestCanEnqueueTaskInRedisAndReadItBack()
        {
            using (var client = new QueueClient())
            {
                var homemadeTask = new TaskMessage
                {
                    Parameters = "params",
                    Queue      = "TestQueue"
                };

                client.Enqueue(homemadeTask);
                var retrievedTask = client.Reserve("TestQueue");

                Assert.AreEqual(retrievedTask.Parameters, homemadeTask.Parameters);
                Assert.AreEqual(retrievedTask.Queue, homemadeTask.Queue);

                client.Fail(string.Empty);
                client.RemoveTask(client.AllTasks("TestQueue")[0]);
            }
        }
Ejemplo n.º 8
0
        public void TestCachingCanPreserveTask()
        {
            using (var client = new QueueClient())
            {
                var homemadeTask = new TaskMessage
                {
                    Parameters = "params",
                    Queue      = "TestQueue"
                };

                client.Enqueue(homemadeTask);
                var retrievedTask = client.Reserve("TestQueue");
            }

            using (var client = new QueueClient())
            {
                Assert.That(client.CurrentTask != null);
                client.Fail(string.Empty);
                client.RemoveTask(client.AllTasks("TestQueue")[0]);
            }
        }
Ejemplo n.º 9
0
        public void TestModifyTaskOnCollectionThenAssertModificationDoesNotWork()
        {
            using (var client = new QueueClient())
            {
                // first enqueue a simple task.
                client.Enqueue(new TaskMessage
                {
                    Parameters = "Test Params",
                    Queue = "TestQueue"
                });

                // now modify the task from within the collection.
                client.PendingTasks("TestQueue")[0].Parameters = "Test Params 2";
            }

            // Dispose of the previous client to ensure modifications dont persist in its memory.
            using (var client = new QueueClient())
            {
                // using a new client, read the task again.
                var task = client.PendingTasks("TestQueue")[0];

                Assert.AreEqual(task.Parameters, "Test Params");

                client.RemoveTask(client.AllTasks("TestQueue")[0]);
            }
        }
Ejemplo n.º 10
0
        public void TestCantReserveMultipleTasksAtOnce()
        {
            using (var client = new QueueClient())
            {
                client.Enqueue(new TaskMessage
                {
                    Parameters = "params",
                    Queue = "TestQueue"
                });

                client.Enqueue(new TaskMessage
                {
                    Parameters = "params",
                    Queue = "TestQueue"
                });

                client.Reserve("TestQueue");
                Assert.Throws<TaskAlreadyReservedException>(() => client.Reserve("TestQueue"));

                client.Fail(string.Empty);
                client.RemoveTask(client.AllTasks("TestQueue")[0]);
                client.RemoveTask(client.AllTasks("TestQueue")[0]);
            }
        }
Ejemplo n.º 11
0
        public void TestEnqueueAndDelete100Tasks()
        {
            var client = new QueueClient();
            for (var i = 0; i < 100; i++)
            {
                client.Enqueue(new TaskMessage
                {
                    Parameters = "params",
                    Queue = "TestQueue"
                });
            }

            Assert.AreEqual(client.AllTasks("TestQueue").Count, 100);

            var deletedTasks = 0;
            while (client.AllTasks("TestQueue").Count > 0)
            {
                client.RemoveTask(client.AllTasks("TestQueue")[0]);
                deletedTasks++;
            }

            Assert.AreEqual(deletedTasks, 100);
        }
Ejemplo n.º 12
0
        public void TestCachingCanPreserveTask()
        {
            using (var client = new QueueClient())
            {
                var homemadeTask = new TaskMessage
                {
                    Parameters = "params",
                    Queue = "TestQueue"
                };

                client.Enqueue(homemadeTask);
                var retrievedTask = client.Reserve("TestQueue");
            }

            using (var client = new QueueClient())
            {
                Assert.That(client.CurrentTask != null);
                client.Fail(string.Empty);
                client.RemoveTask(client.AllTasks("TestQueue")[0]);
            }
        }