public void LinkToWithExistingCondition()
        {
            var owner = new Mock <IOwnScheduleDefinitions>();

            ScheduleElementId id = null;
            var scheduleBuilder  = new Mock <IBuildFixedSchedules>();
            {
                scheduleBuilder.Setup(
                    s => s.LinkTo(
                        It.IsAny <IScheduleVertex>(),
                        It.IsAny <IScheduleVertex>(),
                        It.IsAny <ScheduleElementId>()))
                .Callback <IScheduleVertex, IScheduleVertex, ScheduleElementId>(
                    (s, e, c) => id = c);
            }

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

            var condition = new ScheduleConditionRegistrationId(typeof(string), 0, "a");

            builder.LinkTo(new MarkHistoryVertex(0), new InsertVertex(1), condition);

            Assert.IsNotNull(id);

            var firstId = id;

            builder.LinkTo(new MarkHistoryVertex(2), new InsertVertex(3), condition);

            Assert.IsNotNull(id);
            Assert.AreSame(firstId, id);
        }
        /// <summary>
        /// Links the given vertex to the end point of the schedule.
        /// </summary>
        /// <param name="source">The vertex.</param>
        /// <param name="traverseCondition">
        /// The ID of the condition that determines if it is possible to move from <paramref name="source"/> to the end point.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="source"/> is <see langword="null" />.
        /// </exception>
        public void LinkToEnd(IScheduleVertex source, ScheduleConditionRegistrationId traverseCondition = null)
        {
            {
                Lokad.Enforce.Argument(() => source);
            }

            ScheduleElementId condition = ToScheduleCondition(traverseCondition);

            m_Builder.LinkToEnd(source, condition);
        }
        /// <summary>
        /// Links the start point of the schedule to the given vertex.
        /// </summary>
        /// <param name="target">The vertex.</param>
        /// <param name="traverseCondition">
        /// The ID of the condition that determines if it is possible to move from the start point to <paramref name="target"/>.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="target"/> is <see langword="null" />.
        /// </exception>
        public void LinkFromStart(IScheduleVertex target, ScheduleConditionRegistrationId traverseCondition = null)
        {
            {
                Lokad.Enforce.Argument(() => target);
            }

            ScheduleElementId condition = ToScheduleCondition(traverseCondition);

            m_Builder.LinkFromStart(target, condition);
        }
        public void Register()
        {
            var graph = new BidirectionalGraph <IScheduleVertex, ScheduleEdge>();

            var start = new StartVertex(1);

            graph.AddVertex(start);

            var end = new EndVertex(2);

            graph.AddVertex(end);
            graph.AddEdge(new ScheduleEdge(start, end));

            var schedule        = new Schedule(graph, start, end);
            var scheduleBuilder = new Mock <IBuildFixedSchedules>();
            {
                scheduleBuilder.Setup(s => s.Build())
                .Returns(schedule);
                scheduleBuilder.Setup(s => s.AddExecutingAction(It.IsAny <ScheduleElementId>()))
                .Returns <ScheduleElementId>(s => new ExecutingActionVertex(0, s));
            }

            var actionId    = new ScheduleActionRegistrationId(typeof(string), 0, "a");
            var conditionId = new ScheduleConditionRegistrationId(typeof(string), 0, "a");
            var owner       = new Mock <IOwnScheduleDefinitions>();
            {
                owner.Setup(
                    o => o.StoreSchedule(
                        It.IsAny <ISchedule>(),
                        It.IsAny <Dictionary <ScheduleActionRegistrationId, ScheduleElementId> >(),
                        It.IsAny <Dictionary <ScheduleConditionRegistrationId, ScheduleElementId> >()))
                .Callback <ISchedule, Dictionary <ScheduleActionRegistrationId, ScheduleElementId>, Dictionary <ScheduleConditionRegistrationId, ScheduleElementId> >(
                    (s, a, c) =>
                {
                    Assert.That(a.Keys, Is.EquivalentTo(new List <ScheduleActionRegistrationId> {
                        actionId
                    }));
                    Assert.That(c.Keys, Is.EquivalentTo(new List <ScheduleConditionRegistrationId> {
                        conditionId
                    }));
                });
            }

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

            builder.LinkToEnd(vertex, conditionId);
            builder.Register();
        }
        private ScheduleElementId ToScheduleCondition(ScheduleConditionRegistrationId traverseCondition = null)
        {
            ScheduleElementId condition = null;

            if (traverseCondition != null)
            {
                if (!m_Conditions.ContainsKey(traverseCondition))
                {
                    m_Conditions.Add(traverseCondition, new ScheduleElementId());
                }

                condition = m_Conditions[traverseCondition];
            }

            return(condition);
        }
        public void LinkToEndWithCondition()
        {
            var owner = new Mock <IOwnScheduleDefinitions>();

            ScheduleElementId id = null;
            var scheduleBuilder  = new Mock <IBuildFixedSchedules>();
            {
                scheduleBuilder.Setup(
                    s => s.LinkToEnd(
                        It.IsAny <IScheduleVertex>(),
                        It.IsAny <ScheduleElementId>()))
                .Callback <IScheduleVertex, ScheduleElementId>(
                    (s, c) => id = c);
            }

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

            var condition = new ScheduleConditionRegistrationId(typeof(string), 0, "a");

            builder.LinkToEnd(new InsertVertex(1), condition);

            Assert.IsNotNull(id);
        }
        public void Register()
        {
            var graph = new BidirectionalGraph<IScheduleVertex, ScheduleEdge>();

            var start = new StartVertex(1);
            graph.AddVertex(start);

            var end = new EndVertex(2);
            graph.AddVertex(end);
            graph.AddEdge(new ScheduleEdge(start, end));

            var schedule = new Schedule(graph, start, end);
            var scheduleBuilder = new Mock<IBuildFixedSchedules>();
            {
                scheduleBuilder.Setup(s => s.Build())
                    .Returns(schedule);
                scheduleBuilder.Setup(s => s.AddExecutingAction(It.IsAny<ScheduleElementId>()))
                    .Returns<ScheduleElementId>(s => new ExecutingActionVertex(0, s));
            }

            var actionId = new ScheduleActionRegistrationId(typeof(string), 0, "a");
            var conditionId = new ScheduleConditionRegistrationId(typeof(string), 0, "a");
            var owner = new Mock<IOwnScheduleDefinitions>();
            {
                owner.Setup(
                    o => o.StoreSchedule(
                        It.IsAny<ISchedule>(),
                        It.IsAny<Dictionary<ScheduleActionRegistrationId, ScheduleElementId>>(),
                        It.IsAny<Dictionary<ScheduleConditionRegistrationId, ScheduleElementId>>()))
                    .Callback<ISchedule, Dictionary<ScheduleActionRegistrationId, ScheduleElementId>, Dictionary<ScheduleConditionRegistrationId, ScheduleElementId>>(
                        (s, a, c) =>
                        {
                            Assert.That(a.Keys, Is.EquivalentTo(new List<ScheduleActionRegistrationId> { actionId }));
                            Assert.That(c.Keys, Is.EquivalentTo(new List<ScheduleConditionRegistrationId> { conditionId }));
                        });
            }

            var builder = new ScheduleDefinitionBuilder(owner.Object, scheduleBuilder.Object);
            var vertex = builder.AddExecutingAction(actionId);
            builder.LinkToEnd(vertex, conditionId);
            builder.Register();
        }
        public void LinkToWithExistingCondition()
        {
            var owner = new Mock<IOwnScheduleDefinitions>();

            ScheduleElementId id = null;
            var scheduleBuilder = new Mock<IBuildFixedSchedules>();
            {
                scheduleBuilder.Setup(
                        s => s.LinkTo(
                            It.IsAny<IScheduleVertex>(),
                            It.IsAny<IScheduleVertex>(),
                            It.IsAny<ScheduleElementId>()))
                    .Callback<IScheduleVertex, IScheduleVertex, ScheduleElementId>(
                        (s, e, c) => id = c);
            }

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

            var condition = new ScheduleConditionRegistrationId(typeof(string), 0, "a");
            builder.LinkTo(new MarkHistoryVertex(0), new InsertVertex(1), condition);

            Assert.IsNotNull(id);

            var firstId = id;
            builder.LinkTo(new MarkHistoryVertex(2), new InsertVertex(3), condition);

            Assert.IsNotNull(id);
            Assert.AreSame(firstId, id);
        }
        public void LinkToEndWithCondition()
        {
            var owner = new Mock<IOwnScheduleDefinitions>();

            ScheduleElementId id = null;
            var scheduleBuilder = new Mock<IBuildFixedSchedules>();
            {
                scheduleBuilder.Setup(
                        s => s.LinkToEnd(
                            It.IsAny<IScheduleVertex>(),
                            It.IsAny<ScheduleElementId>()))
                    .Callback<IScheduleVertex, ScheduleElementId>(
                        (s, c) => id = c);
            }

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

            var condition = new ScheduleConditionRegistrationId(typeof(string), 0, "a");
            builder.LinkToEnd(new InsertVertex(1), condition);

            Assert.IsNotNull(id);
        }
예제 #10
0
 /// <summary>
 /// Returns the condition definition that was registered with the given ID.
 /// </summary>
 /// <param name="id">The ID of the condition.</param>
 /// <returns>The requested condition definition.</returns>
 public ScheduleConditionDefinition Condition(ScheduleConditionRegistrationId id)
 {
     return(m_Conditions[id]);
 }
예제 #11
0
 /// <summary>
 /// Returns the condition definition that was registered with the given ID.
 /// </summary>
 /// <param name="id">The ID of the condition.</param>
 /// <returns>The requested condition definition.</returns>
 public ScheduleConditionDefinition Condition(ScheduleConditionRegistrationId id)
 {
     return m_Conditions[id];
 }
        private ScheduleElementId ToScheduleCondition(ScheduleConditionRegistrationId traverseCondition = null)
        {
            ScheduleElementId condition = null;
            if (traverseCondition != null)
            {
                if (!m_Conditions.ContainsKey(traverseCondition))
                {
                    m_Conditions.Add(traverseCondition, new ScheduleElementId());
                }

                condition = m_Conditions[traverseCondition];
            }

            return condition;
        }
        /// <summary>
        /// Links the given vertex to the end point of the schedule.
        /// </summary>
        /// <param name="source">The vertex.</param>
        /// <param name="traverseCondition">
        /// The ID of the condition that determines if it is possible to move from <paramref name="source"/> to the end point.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="source"/> is <see langword="null" />.
        /// </exception>
        public void LinkToEnd(IScheduleVertex source, ScheduleConditionRegistrationId traverseCondition = null)
        {
            {
                Lokad.Enforce.Argument(() => source);
            }

            ScheduleElementId condition = ToScheduleCondition(traverseCondition);
            m_Builder.LinkToEnd(source, condition);
        }
        /// <summary>
        /// Links the start point of the schedule to the given vertex.
        /// </summary>
        /// <param name="target">The vertex.</param>
        /// <param name="traverseCondition">
        /// The ID of the condition that determines if it is possible to move from the start point to <paramref name="target"/>.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="target"/> is <see langword="null" />.
        /// </exception>
        public void LinkFromStart(IScheduleVertex target, ScheduleConditionRegistrationId traverseCondition = null)
        {
            {
                Lokad.Enforce.Argument(() => target);
            }

            ScheduleElementId condition = ToScheduleCondition(traverseCondition);
            m_Builder.LinkFromStart(target, condition);
        }