示例#1
0
        public void TestChildSequencing()
        {
            Model model = new Model();

            model.AddService <ITaskManagementService>(new TaskManagementService());

            TestTask parent = new TestTask(model, "Parent");

            TaskProcessor tp = new TaskProcessor(model, "TP", parent)
            {
                KeepGraphContexts = true
            };

            model.GetService <ITaskManagementService>().AddTaskProcessor(tp);


            TestTask[] children = new TestTask[5];
            for (int i = 0; i < children.Length; i++)
            {
                children[i] = new TestTask(model, "Child" + i, TimeSpan.FromHours(i));
                if (i > 0)
                {
                    children[i].AddPredecessor(children[i - 1]);
                }
                parent.AddChildEdge(children[i]);
            }

            model.Start();

            IDictionary gc = (IDictionary)tp.GraphContexts[0];

            Assert.AreEqual(new DateTime(1, 1, 1, 0, 0, 0), parent.GetStartTime(gc), "Parent task did't start at the correct time.");
            Assert.AreEqual(new DateTime(1, 1, 1, 0, 0, 0), children[0].GetStartTime(gc), "Child task 1 did't start at the correct time.");
            Assert.AreEqual(new DateTime(1, 1, 1, 0, 0, 0), children[1].GetStartTime(gc), "Child task 2 did't start at the correct time.");
            Assert.AreEqual(new DateTime(1, 1, 1, 1, 0, 0), children[2].GetStartTime(gc), "Child task 3 did't start at the correct time.");
            Assert.AreEqual(new DateTime(1, 1, 1, 3, 0, 0), children[3].GetStartTime(gc), "Child task 4 did't start at the correct time.");
            Assert.AreEqual(new DateTime(1, 1, 1, 6, 0, 0), children[4].GetStartTime(gc), "Child task 5 did't start at the correct time.");
            Assert.AreEqual(new DateTime(1, 1, 1, 0, 0, 0), children[0].GetFinishTime(gc), "Child task 1 did't finish at the correct time.");
            Assert.AreEqual(new DateTime(1, 1, 1, 1, 0, 0), children[1].GetFinishTime(gc), "Child task 2 did't finish at the correct time.");
            Assert.AreEqual(new DateTime(1, 1, 1, 3, 0, 0), children[2].GetFinishTime(gc), "Child task 3 did't finish at the correct time.");
            Assert.AreEqual(new DateTime(1, 1, 1, 6, 0, 0), children[3].GetFinishTime(gc), "Child task 4 did't finish at the correct time.");
            Assert.AreEqual(new DateTime(1, 1, 1, 10, 0, 0), children[4].GetFinishTime(gc), "Child task 5 did't finish at the correct time.");
            Assert.AreEqual(new DateTime(1, 1, 1, 10, 0, 0), parent.GetFinishTime(gc), "Parent task did't finish at the correct time.");
        }