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

            ScheduleElementId id = null;
            var scheduleBuilder  = new Mock <IBuildFixedSchedules>();
            {
                scheduleBuilder.Setup(s => s.AddExecutingAction(It.IsAny <ScheduleElementId>()))
                .Callback <ScheduleElementId>(s => id = s)
                .Returns <ScheduleElementId>(s => new ExecutingActionVertex(0, s));
            }

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

            var firstRegistration  = new ScheduleActionRegistrationId(typeof(string), 0, "a");
            var secondRegistration = new ScheduleActionRegistrationId(typeof(string), 0, "a");
            var firstVertex        = builder.AddExecutingAction(firstRegistration);

            var first = id;

            id = null;
            var secondVertex = builder.AddExecutingAction(secondRegistration);

            Assert.IsNotNull(firstVertex);
            Assert.IsNotNull(secondVertex);
            Assert.AreEqual(first, id);
        }
        public void AddActionWithExistingAction()
        {
            var owner = new Mock<IOwnScheduleDefinitions>();

            ScheduleElementId id = null;
            var scheduleBuilder = new Mock<IBuildFixedSchedules>();
            {
                scheduleBuilder.Setup(s => s.AddExecutingAction(It.IsAny<ScheduleElementId>()))
                    .Callback<ScheduleElementId>(s => id = s)
                    .Returns<ScheduleElementId>(s => new ExecutingActionVertex(0, s));
            }

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

            var firstRegistration = new ScheduleActionRegistrationId(typeof(string), 0, "a");
            var secondRegistration = new ScheduleActionRegistrationId(typeof(string), 0, "a");
            var firstVertex = builder.AddExecutingAction(firstRegistration);

            var first = id;
            id = null;
            var secondVertex = builder.AddExecutingAction(secondRegistration);
            Assert.IsNotNull(firstVertex);
            Assert.IsNotNull(secondVertex);
            Assert.AreEqual(first, id);
        }
        private ScheduleElementId ToScheduleAction(ScheduleActionRegistrationId action)
        {
            if (!m_Actions.ContainsKey(action))
            {
                m_Actions.Add(action, new ScheduleElementId());
            }

            return(m_Actions[action]);
        }
        /// <summary>
        /// Adds the executing action with the specified ID to the schedule.
        /// </summary>
        /// <param name="action">The ID of the action that should be added.</param>
        /// <returns>The vertex that contains the information about the given action.</returns>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="action"/> is <see langword="null" />.
        /// </exception>
        public ExecutingActionVertex AddExecutingAction(ScheduleActionRegistrationId action)
        {
            {
                Lokad.Enforce.Argument(() => action);
            }

            var scheduleAction = ToScheduleAction(action);
            return m_Builder.AddExecutingAction(scheduleAction);
        }
        /// <summary>
        /// Adds the executing action with the specified ID to the schedule.
        /// </summary>
        /// <param name="action">The ID of the action that should be added.</param>
        /// <returns>The vertex that contains the information about the given action.</returns>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="action"/> is <see langword="null" />.
        /// </exception>
        public ExecutingActionVertex AddExecutingAction(ScheduleActionRegistrationId action)
        {
            {
                Lokad.Enforce.Argument(() => action);
            }

            var scheduleAction = ToScheduleAction(action);

            return(m_Builder.AddExecutingAction(scheduleAction));
        }
        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 AddAction()
        {
            var owner = new Mock <IOwnScheduleDefinitions>();

            ScheduleElementId id = null;
            var scheduleBuilder  = new Mock <IBuildFixedSchedules>();
            {
                scheduleBuilder.Setup(s => s.AddExecutingAction(It.IsAny <ScheduleElementId>()))
                .Callback <ScheduleElementId>(s => id = s)
                .Returns <ScheduleElementId>(s => new ExecutingActionVertex(0, s));
            }

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

            var registrationId = new ScheduleActionRegistrationId(typeof(string), 0, "a");
            var vertex         = builder.AddExecutingAction(registrationId);

            Assert.IsNotNull(vertex);
            Assert.IsNotNull(id);
        }
        public void AddAction()
        {
            var owner = new Mock<IOwnScheduleDefinitions>();

            ScheduleElementId id = null;
            var scheduleBuilder = new Mock<IBuildFixedSchedules>();
            {
                scheduleBuilder.Setup(s => s.AddExecutingAction(It.IsAny<ScheduleElementId>()))
                    .Callback<ScheduleElementId>(s => id = s)
                    .Returns<ScheduleElementId>(s => new ExecutingActionVertex(0, s));
            }

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

            var registrationId = new ScheduleActionRegistrationId(typeof(string), 0, "a");
            var vertex = builder.AddExecutingAction(registrationId);

            Assert.IsNotNull(vertex);
            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();
        }
Пример #10
0
 /// <summary>
 /// Returns the action definition that was registered with the given ID.
 /// </summary>
 /// <param name="id">The ID of the action.</param>
 /// <returns>The requested action definition.</returns>
 public ScheduleActionDefinition Action(ScheduleActionRegistrationId id)
 {
     return(m_Actions[id]);
 }
Пример #11
0
 /// <summary>
 /// Returns the action definition that was registered with the given ID.
 /// </summary>
 /// <param name="id">The ID of the action.</param>
 /// <returns>The requested action definition.</returns>
 public ScheduleActionDefinition Action(ScheduleActionRegistrationId id)
 {
     return m_Actions[id];
 }
        private ScheduleElementId ToScheduleAction(ScheduleActionRegistrationId action)
        {
            if (!m_Actions.ContainsKey(action))
            {
                m_Actions.Add(action, new ScheduleElementId());
            }

            return m_Actions[action];
        }