public void Create() { var index = 10; var subScheduleId = new ScheduleId(); var vertex = new SubScheduleVertex(index, subScheduleId); Assert.AreEqual(index, vertex.Index); Assert.AreSame(subScheduleId, vertex.ScheduleToExecute); }
public void AddSubSchedule() { var owner = new Mock<IOwnScheduleDefinitions>(); var schedule = new ScheduleId(); ScheduleId storedId = null; var scheduleVertex = new SubScheduleVertex(0, schedule); var scheduleBuilder = new Mock<IBuildFixedSchedules>(); { scheduleBuilder.Setup(s => s.AddSubSchedule(It.IsAny<ScheduleId>())) .Callback<ScheduleId>(s => storedId = s) .Returns(scheduleVertex); } var builder = new ScheduleDefinitionBuilder(owner.Object, scheduleBuilder.Object); var vertex = builder.AddSubSchedule(schedule); Assert.AreSame(scheduleVertex, vertex); Assert.AreSame(schedule, storedId); }
/// <summary> /// Inserts the given schedule in the position of the insert vertex. The given schedule /// will be connected via its start and end vertices. The insert vertex will be removed /// if it has no more inserts left. /// </summary> /// <param name="insertVertex">The vertex which will be replaced.</param> /// <param name="scheduleToInsert">The ID of the schedule that will be inserted.</param> /// <returns> /// A tuple containing newly created sub-schedule vertex and the insert vertices that were place before and after /// the newly inserted sub-schedule vertex. /// </returns> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="insertVertex"/> is <see langword="null" />. /// </exception> /// <exception cref="UnknownScheduleVertexException"> /// Thrown if <paramref name="insertVertex"/> does not exist in the current schedule. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="scheduleToInsert"/> is <see langword="null" />. /// </exception> /// <exception cref="NoInsertsLeftOnVertexException"> /// Thrown if <paramref name="insertVertex"/> has no more inserts left. /// </exception> public Tuple<InsertVertex, SubScheduleVertex, InsertVertex> InsertIn( InsertVertex insertVertex, ScheduleId scheduleToInsert) { var subScheduleVertex = new SubScheduleVertex(m_Schedule.VertexCount, scheduleToInsert); var internalResult = InsertIn(insertVertex, subScheduleVertex); return new Tuple<InsertVertex, SubScheduleVertex, InsertVertex>( internalResult.Item1, subScheduleVertex, internalResult.Item2); }
/// <summary> /// Adds the schedule with the specified ID as a sub-schedule to the current schedule. /// </summary> /// <param name="schedule">The ID of the sub-schedule.</param> /// <returns>The vertex that contains the information about the given sub-schedule.</returns> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="schedule"/> is <see langword="null" />. /// </exception> public SubScheduleVertex AddSubSchedule(ScheduleId schedule) { { Lokad.Enforce.Argument(() => schedule); } var result = new SubScheduleVertex(m_Schedule.VertexCount, schedule); m_Schedule.AddVertex(result); return result; }
public void SubScheduleWithLinkBackToParent() { var id = new ScheduleId(); var subScheduleId = new ScheduleId(); ISchedule subSchedule; { var subGraph = new BidirectionalGraph<IScheduleVertex, ScheduleEdge>(); var start = new StartVertex(1); var end = new EndVertex(2); var vertex1 = new SubScheduleVertex(3, id); subGraph.AddVertex(start); subGraph.AddVertex(end); subGraph.AddVertex(vertex1); subGraph.AddEdge(new ScheduleEdge(start, vertex1)); subGraph.AddEdge(new ScheduleEdge(vertex1, end)); subSchedule = new Schedule(subGraph, start, end); } IScheduleVertex errorVertex; Schedule schedule; { var graph = new BidirectionalGraph<IScheduleVertex, ScheduleEdge>(); var start = new StartVertex(1); var end = new EndVertex(2); var vertex1 = new SubScheduleVertex(3, subScheduleId); graph.AddVertex(start); graph.AddVertex(end); graph.AddVertex(vertex1); graph.AddEdge(new ScheduleEdge(start, vertex1)); graph.AddEdge(new ScheduleEdge(vertex1, end)); schedule = new Schedule(graph, start, end); errorVertex = vertex1; } var knownSchedules = new Mock<IStoreSchedules>(); { knownSchedules.Setup(s => s.Contains(It.IsAny<ScheduleId>())) .Returns<ScheduleId>(subScheduleId.Equals); knownSchedules.Setup(s => s.Schedule(It.IsAny<ScheduleId>())) .Returns<ScheduleId>(scheduleId => subSchedule); } var failures = new List<Tuple<ScheduleIntegrityFailureType, IScheduleVertex>>(); var verifier = new ScheduleVerifier(knownSchedules.Object); var result = verifier.IsValid( id, schedule, (f, v) => failures.Add(new Tuple<ScheduleIntegrityFailureType, IScheduleVertex>(f, v))); Assert.IsFalse(result); Assert.AreEqual(1, failures.Count); Assert.AreEqual(ScheduleIntegrityFailureType.SubScheduleLinksBackToParentSchedule, failures[0].Item1); Assert.AreSame(errorVertex, failures[0].Item2); }
private static Schedule BuildSchedule( ScheduleElementId action1, ScheduleElementId action2, ScheduleId scheduleId, ScheduleElementId exitCondition, ScheduleElementId passThroughCondition) { var variable = new Mock<IScheduleVariable>(); // Making a schedule that looks like: // start --> node1 -----------------------> node2 -> end // ^ | // |-- node5 <-- node4 <-- node3<-| // ^ | // node7--| |-> node6 // ^ | // |--------------| Schedule schedule = null; { 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 ExecutingActionVertex(3, action1); graph.AddVertex(vertex1); var vertex2 = new ExecutingActionVertex(4, action2); graph.AddVertex(vertex2); var vertex3 = new SynchronizationStartVertex(5, new IScheduleVariable[] { variable.Object }); graph.AddVertex(vertex3); var vertex4 = new ExecutingActionVertex(6, action2); graph.AddVertex(vertex4); var vertex5 = new SynchronizationEndVertex(7); graph.AddVertex(vertex5); var vertex6 = new SubScheduleVertex(8, scheduleId); graph.AddVertex(vertex6); var vertex7 = new InsertVertex(9); graph.AddVertex(vertex7); graph.AddEdge(new ScheduleEdge(start, vertex1)); graph.AddEdge(new ScheduleEdge(vertex1, vertex2)); graph.AddEdge(new ScheduleEdge(vertex2, end, exitCondition)); graph.AddEdge(new ScheduleEdge(vertex2, vertex3)); graph.AddEdge(new ScheduleEdge(vertex3, vertex4)); graph.AddEdge(new ScheduleEdge(vertex4, vertex5, passThroughCondition)); graph.AddEdge(new ScheduleEdge(vertex4, vertex6)); graph.AddEdge(new ScheduleEdge(vertex5, vertex1)); graph.AddEdge(new ScheduleEdge(vertex6, vertex7)); graph.AddEdge(new ScheduleEdge(vertex7, vertex4)); schedule = new Schedule(graph, start, end); } return schedule; }