public void AddWithNullAction()
        {
            var collection = ScheduleActionStorage.CreateInstanceWithoutTimeline();

            Assert.Throws <ArgumentNullException>(
                () => collection.Add(null, "a", "b"));
        }
        public void UpdateWithNullAction()
        {
            var collection = ScheduleActionStorage.CreateInstanceWithoutTimeline();
            var action     = new Mock <IScheduleAction>();

            var info = collection.Add(action.Object, "a", "b");

            Assert.Throws <ArgumentNullException>(() => collection.Update(info.Id, null));
        }
        public void UpdateWithUnknownId()
        {
            var collection = ScheduleActionStorage.CreateInstanceWithoutTimeline();
            var action     = new Mock <IScheduleAction>();

            collection.Add(action.Object, "a", "b");
            var otherAction = new Mock <IScheduleAction>();

            Assert.Throws <UnknownScheduleActionException>(() => collection.Update(new ScheduleElementId(), otherAction.Object));
        }
        public void Add()
        {
            var collection = ScheduleActionStorage.CreateInstanceWithoutTimeline();
            var action     = new Mock <IScheduleAction>();

            var info = collection.Add(action.Object, "a", "b");

            Assert.AreSame(info, collection.Information(info.Id));
            Assert.AreSame(action.Object, collection.Action(info.Id));
        }
        public void Contains()
        {
            var collection = ScheduleActionStorage.CreateInstanceWithoutTimeline();
            var action     = new Mock <IScheduleAction>();

            var info = collection.Add(action.Object, "a", "b");

            Assert.IsTrue(collection.Contains(info.Id));
            Assert.IsFalse(collection.Contains(new ScheduleElementId()));
            Assert.IsFalse(collection.Contains(null));
        }
        public void Update()
        {
            var collection = ScheduleActionStorage.CreateInstanceWithoutTimeline();
            var action     = new Mock <IScheduleAction>();

            var info = collection.Add(action.Object, "a", "b");

            Assert.AreSame(action.Object, collection.Action(info.Id));

            var otherAction = new Mock <IScheduleAction>();

            collection.Update(info.Id, otherAction.Object);
            var otherInfo = collection.Information(info.Id);

            Assert.AreEqual(info.Id, otherInfo.Id);
            Assert.AreEqual(info.Name, otherInfo.Name);
            Assert.AreEqual(info.Description, otherInfo.Description);

            Assert.AreSame(otherAction.Object, collection.Action(info.Id));
        }
예제 #7
0
        public void RunWithActionVertex()
        {
            var action = new Mock <IScheduleAction>();
            {
                action.Setup(a => a.Execute(It.IsAny <CancellationToken>()))
                .Verifiable();
            }

            var collection = ScheduleActionStorage.CreateInstanceWithoutTimeline();
            var info       = collection.Add(
                action.Object,
                "a",
                "b");

            var schedule = BuildThreeVertexSchedule(new ExecutingActionVertex(3, info.Id));

            using (var executionInfo = new ScheduleExecutionInfo(new CurrentThreadTaskScheduler()))
            {
                using (var executor = new ScheduleExecutor(
                           new List <IProcesExecutableScheduleVertices>
                {
                    new StartVertexProcessor(),
                    new EndVertexProcessor(),
                    new ActionVertexProcessor(collection),
                },
                           ScheduleConditionStorage.CreateInstanceWithoutTimeline(),
                           schedule,
                           new ScheduleId(),
                           executionInfo))
                {
                    var state = ScheduleExecutionState.None;
                    executor.OnFinish += (s, e) => { state = e.State; };

                    executor.Start();
                    Assert.AreEqual(ScheduleExecutionState.Completed, state);
                    action.Verify(a => a.Execute(It.IsAny <CancellationToken>()), Times.Once());
                }
            }
        }
예제 #8
0
        public void RunWithInnerAndOuterLoop()
        {
            bool outerLoopPassThrough = false;
            var  outerLoopCondition   = new Mock <IScheduleCondition>();
            {
                outerLoopCondition.Setup(c => c.CanTraverse(It.IsAny <CancellationToken>()))
                .Returns(() => outerLoopPassThrough);
            }

            bool innerLoopPassThrough = false;
            var  innerLoopCondition   = new Mock <IScheduleCondition>();
            {
                innerLoopCondition.Setup(c => c.CanTraverse(It.IsAny <CancellationToken>()))
                .Returns(() => innerLoopPassThrough);
            }

            var conditionStorage       = ScheduleConditionStorage.CreateInstanceWithoutTimeline();
            var outerLoopConditionInfo = conditionStorage.Add(
                outerLoopCondition.Object,
                "a",
                "b");
            var innerLoopConditionInfo = conditionStorage.Add(
                innerLoopCondition.Object,
                "a",
                "b");

            var outerLoopAction = new Mock <IScheduleAction>();
            {
                outerLoopAction.Setup(a => a.Execute(It.IsAny <CancellationToken>()))
                .Callback(() => outerLoopPassThrough = true);
            }

            var innerLoopAction = new Mock <IScheduleAction>();
            {
                innerLoopAction.Setup(a => a.Execute(It.IsAny <CancellationToken>()))
                .Callback(() => innerLoopPassThrough = true);
            }

            var collection    = ScheduleActionStorage.CreateInstanceWithoutTimeline();
            var outerLoopInfo = collection.Add(
                outerLoopAction.Object,
                "a",
                "b");
            var innerLoopInfo = collection.Add(
                innerLoopAction.Object,
                "a",
                "b");

            // Making a schedule that looks like:
            // start -> node1 --> node2 -> end
            //            ^           |
            //            |-- node3 <-|
            //                ^  |
            //         node5--|  |->  node4
            //           ^              |
            //           |--------------|
            Schedule schedule;

            {
                schedule = CreateScheduleGraphWithOuterAndInnerLoop(outerLoopConditionInfo, innerLoopConditionInfo, outerLoopInfo, innerLoopInfo);
            }

            using (var info = new ScheduleExecutionInfo(new CurrentThreadTaskScheduler()))
            {
                using (var executor = new ScheduleExecutor(
                           new List <IProcesExecutableScheduleVertices>
                {
                    new StartVertexProcessor(),
                    new EndVertexProcessor(),
                    new InsertVertexProcessor(),
                    new ActionVertexProcessor(collection),
                },
                           conditionStorage,
                           schedule,
                           new ScheduleId(),
                           info))
                {
                    var executionOrder = new List <int>();
                    executor.OnVertexProcess += (s, e) => executionOrder.Add(e.Vertex);

                    executor.Start();
                    Assert.That(executionOrder, Is.EquivalentTo(new[] { 1, 3, 4, 5, 6, 7, 5, 3, 4, 2 }));
                }
            }
        }
예제 #9
0
        public void RunWithLoop()
        {
            bool passThrough = false;
            var  condition   = new Mock <IScheduleCondition>();
            {
                condition.Setup(c => c.CanTraverse(It.IsAny <CancellationToken>()))
                .Returns(() => passThrough);
            }

            var conditionStorage = ScheduleConditionStorage.CreateInstanceWithoutTimeline();
            var conditionInfo    = conditionStorage.Add(condition.Object, "a", "b");

            var action = new Mock <IScheduleAction>();
            {
                action.Setup(a => a.Execute(It.IsAny <CancellationToken>()))
                .Callback(() => passThrough = true);
            }

            var collection = ScheduleActionStorage.CreateInstanceWithoutTimeline();
            var info       = collection.Add(
                action.Object,
                "a",
                "b");

            // Making a schedule that looks like:
            // start -> node1 --> node2 -> end
            //            ^           |
            //            |-- node3 <-|
            Schedule schedule;

            {
                var graph = new BidirectionalGraph <IScheduleVertex, ScheduleEdge>();
                var start = new StartVertex(1);
                graph.AddVertex(start);

                var end = new EndVertex(2);
                graph.AddVertex(end);

                var vertex1 = new InsertVertex(3);
                graph.AddVertex(vertex1);

                var vertex2 = new InsertVertex(4);
                graph.AddVertex(vertex2);

                var vertex3 = new ExecutingActionVertex(5, info.Id);
                graph.AddVertex(vertex3);

                graph.AddEdge(new ScheduleEdge(start, vertex1));
                graph.AddEdge(new ScheduleEdge(vertex1, vertex2));

                graph.AddEdge(new ScheduleEdge(vertex2, end, conditionInfo.Id));
                graph.AddEdge(new ScheduleEdge(vertex2, vertex3));

                graph.AddEdge(new ScheduleEdge(vertex3, vertex1));

                schedule = new Schedule(graph, start, end);
            }

            using (var executionInfo = new ScheduleExecutionInfo(new CurrentThreadTaskScheduler()))
            {
                using (var executor = new ScheduleExecutor(
                           new List <IProcesExecutableScheduleVertices>
                {
                    new StartVertexProcessor(),
                    new EndVertexProcessor(),
                    new InsertVertexProcessor(),
                    new ActionVertexProcessor(collection),
                },
                           conditionStorage,
                           schedule,
                           new ScheduleId(),
                           executionInfo))
                {
                    var executionOrder = new List <int>();
                    executor.OnVertexProcess += (s, e) => executionOrder.Add(e.Vertex);

                    executor.Start();
                    Assert.That(executionOrder, Is.EquivalentTo(new[] { 1, 3, 4, 5, 3, 4, 2 }));
                }
            }
        }
        public void RemoveWithNullId()
        {
            var collection = ScheduleActionStorage.CreateInstanceWithoutTimeline();

            Assert.DoesNotThrow(() => collection.Remove(null));
        }