public void Does_not_match_tasks_if_namespace_incorrect()
        {
            var matcher = new NamespaceMatcher("test", "No.Such.Tasks");
            var matchResult = matcher.TryMatch(PersistentTask.Instance);

            Assert.That(matchResult.Matched, Is.False);
        }
        public void Matches_tasks_by_filter(string namespaceFilter)
        {
            var matcher = new NamespaceMatcher("test", namespaceFilter);

            var matchResult = matcher.TryMatch(PersistentTask.Instance);

            Assert.That(matchResult.Matched, Is.True);
        }
        public void Should_match_and_return_results_from_different_matchers()
        {
            var nsMatcher = new NamespaceMatcher("byNamespace", typeof (PersistentTask).Namespace);
            var funcMatcher = new FuncMatcher("byFunc", task => task.GetType() == typeof (LongRunningTask));

            var matcher = new AggregateMatcher(nsMatcher, funcMatcher);

            var namespaceMatch = matcher.TryMatch(PersistentTask.Instance);

            Assert.That(namespaceMatch.Matched, Is.True);
            Assert.That(namespaceMatch.Value, Is.EqualTo("byNamespace"));

            var anotherTask = new LongRunningTask(false);
            var funcMatch = matcher.TryMatch(anotherTask);

            Assert.That(funcMatch.Matched, Is.True);
            Assert.That(funcMatch.Value, Is.EqualTo("byFunc"));
        }
        public void Ordered_tasks_are_executed_serially()
        {
            var taskQueueSettings = new QueuedExecutorSettings{Name = "test"};
            var taskQueue = new QueuedExecutor(taskQueueSettings, NullPersister.Instance);
            var matcher = new NamespaceMatcher(taskQueue.Name, NamespaceMatcher.AnyWildCard);
            var taskRouter = new TaskRouter(matcher, new IExecutorImplementation[]{taskQueue });
            var dispatcher = new TaskDispatcher(2, new IExecutionQueue[] {taskQueue});
            var executor = new Executor(taskRouter, dispatcher, new DefaultReleaser());

            var tasks = Enumerable.Range(1, 2).Select(x => new LongRunningTask(true) {Name = "Task" + x}).ToArray();

            foreach (var task in tasks)
            {
                executor.Execute(task);
            }

            Assert.That(tasks[0].WaitForStart(1000), Is.True, "First task should start");

            Assert.That(tasks[1].WaitForStart(1000), Is.False, "Second task should not start");
        }