public void Create()
        {
            var variable = new Mock <IScheduleVariable>();

            var index     = 10;
            var variables = new List <IScheduleVariable> {
                variable.Object
            };
            var vertex = new SynchronizationStartVertex(index, variables);

            Assert.AreEqual(index, vertex.Index);
            Assert.AreSame(variables, vertex.VariablesToSynchronizeOn);
        }
        public void AddSynchronizationEndPoint()
        {
            var owner = new Mock<IOwnScheduleDefinitions>();

            SynchronizationStartVertex startVertex = null;
            var scheduleBuilder = new Mock<IBuildFixedSchedules>();
            {
                scheduleBuilder.Setup(s => s.AddSynchronizationEnd(It.IsAny<SynchronizationStartVertex>()))
                    .Callback<SynchronizationStartVertex>(s => startVertex = s)
                    .Returns<SynchronizationStartVertex>(s => new SynchronizationEndVertex(0));
            }

            var builder = new ScheduleDefinitionBuilder(owner.Object, scheduleBuilder.Object);

            var inputVertex = new SynchronizationStartVertex(
                0,
                new List<IScheduleVariable> { new Mock<IScheduleVariable>().Object });
            var vertex = builder.AddSynchronizationEnd(inputVertex);

            Assert.IsNotNull(vertex);
            Assert.AreSame(inputVertex, startVertex);
        }
        /// <summary>
        /// Adds a vertex that indicates the start of a synchronization block over which the given variables 
        /// should be synchronized when the block ends.
        /// </summary>
        /// <param name="variables">The collection of variables that should be synchronized.</param>
        /// <returns>The vertex that contains the synchronization information.</returns>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="variables"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="CannotCreateASynchronizationBlockWithoutVariablesException">
        ///     Thrown if <paramref name="variables"/> is an empty collection.
        /// </exception>
        public SynchronizationStartVertex AddSynchronizationStart(IEnumerable<IScheduleVariable> variables)
        {
            {
                Lokad.Enforce.Argument(() => variables);
                Lokad.Enforce.With<CannotCreateASynchronizationBlockWithoutVariablesException>(
                    variables.Any(),
                    Resources.Exceptions_Messages_CannotCreateASynchronizationBlockWithoutVariables);
            }

            var result = new SynchronizationStartVertex(m_Schedule.VertexCount, variables);
            m_Schedule.AddVertex(result);

            return result;
        }
        /// <summary>
        /// Adds a vertex that indicates the end of a synchronization block.
        /// </summary>
        /// <param name="startPoint">The vertex that forms the start point of the block.</param>
        /// <returns>The vertex that indicates the end of a synchronization block.</returns>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="startPoint"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="UnknownScheduleVertexException">
        ///     Thrown if <paramref name="startPoint"/> is not part of the current schedule.
        /// </exception>
        public SynchronizationEndVertex AddSynchronizationEnd(SynchronizationStartVertex startPoint)
        {
            {
                Lokad.Enforce.Argument(() => startPoint);
                Lokad.Enforce.With<UnknownScheduleVertexException>(
                    m_Schedule.ContainsVertex(startPoint),
                    Resources.Exceptions_Messages_UnknownScheduleVertex);
            }

            var result = new SynchronizationEndVertex(m_Schedule.VertexCount);
            m_Schedule.AddVertex(result);

            return result;
        }
 /// <summary>
 /// Adds a vertex that indicates the end of a synchronization block.
 /// </summary>
 /// <param name="startPoint">The vertex that forms the start point of the block.</param>
 /// <returns>The vertex that indicates the end of a synchronization block.</returns>
 public SynchronizationEndVertex AddSynchronizationEnd(SynchronizationStartVertex startPoint)
 {
     return m_Builder.AddSynchronizationEnd(startPoint);
 }
        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;
        }