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);
        }
        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 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 AddInsertPointWithCount()
        {
            var owner = new Mock <IOwnScheduleDefinitions>();

            var scheduleBuilder = new Mock <IBuildFixedSchedules>();
            {
                scheduleBuilder.Setup(s => s.AddInsertPoint(It.IsAny <int>()))
                .Returns <int>(i => new InsertVertex(0, i));
            }

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

            Assert.AreEqual(10, vertex.RemainingInserts);
        }
        public void AddInsertPoint()
        {
            var owner = new Mock <IOwnScheduleDefinitions>();

            var insertVertex    = new InsertVertex(0);
            var scheduleBuilder = new Mock <IBuildFixedSchedules>();
            {
                scheduleBuilder.Setup(s => s.AddInsertPoint())
                .Returns(insertVertex);
            }

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

            Assert.AreSame(insertVertex, vertex);
        }
        public void AddHistoryMarkingPoint()
        {
            var owner = new Mock <IOwnScheduleDefinitions>();

            MarkHistoryVertex startVertex = new MarkHistoryVertex(0);
            var scheduleBuilder           = new Mock <IBuildFixedSchedules>();
            {
                scheduleBuilder.Setup(s => s.AddHistoryMarkingPoint())
                .Returns(startVertex);
            }

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

            Assert.AreSame(startVertex, vertex);
        }
        public void LinkToEndWithoutCondition()
        {
            var owner = new Mock <IOwnScheduleDefinitions>();

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

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

            builder.LinkToEnd(new MarkHistoryVertex(0));
        }
        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 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);
        }
        public void AddSynchronizationStartPoint()
        {
            var owner = new Mock <IOwnScheduleDefinitions>();

            IEnumerable <IScheduleVariable> variables = null;
            var scheduleBuilder = new Mock <IBuildFixedSchedules>();
            {
                scheduleBuilder.Setup(s => s.AddSynchronizationStart(It.IsAny <IEnumerable <IScheduleVariable> >()))
                .Callback <IEnumerable <IScheduleVariable> >(s => variables = s)
                .Returns <IEnumerable <IScheduleVariable> >(s => new SynchronizationStartVertex(0, s));
            }

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

            var synchronizationVariables = new List <IScheduleVariable> {
                new Mock <IScheduleVariable>().Object
            };
            var vertex = builder.AddSynchronizationStart(synchronizationVariables);

            Assert.IsNotNull(vertex);
            Assert.That(variables, Is.EquivalentTo(synchronizationVariables));
        }
        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 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);
        }
        public void AddInsertPoint()
        {
            var owner = new Mock<IOwnScheduleDefinitions>();

            var insertVertex = new InsertVertex(0);
            var scheduleBuilder = new Mock<IBuildFixedSchedules>();
            {
                scheduleBuilder.Setup(s => s.AddInsertPoint())
                    .Returns(insertVertex);
            }

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

            Assert.AreSame(insertVertex, vertex);
        }
        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);
        }
        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);
        }
        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 AddSynchronizationStartPoint()
        {
            var owner = new Mock<IOwnScheduleDefinitions>();

            IEnumerable<IScheduleVariable> variables = null;
            var scheduleBuilder = new Mock<IBuildFixedSchedules>();
            {
                scheduleBuilder.Setup(s => s.AddSynchronizationStart(It.IsAny<IEnumerable<IScheduleVariable>>()))
                    .Callback<IEnumerable<IScheduleVariable>>(s => variables = s)
                    .Returns<IEnumerable<IScheduleVariable>>(s => new SynchronizationStartVertex(0, s));
            }

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

            var synchronizationVariables = new List<IScheduleVariable> { new Mock<IScheduleVariable>().Object };
            var vertex = builder.AddSynchronizationStart(synchronizationVariables);

            Assert.IsNotNull(vertex);
            Assert.That(variables, Is.EquivalentTo(synchronizationVariables));
        }
        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 LinkToWithoutCondition()
        {
            var owner = new Mock<IOwnScheduleDefinitions>();

            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) => Assert.IsNull(c));
            }

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

            var start = new MarkHistoryVertex(0);
            var end = new InsertVertex(1);
            builder.LinkTo(start, end);
        }
        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 AddHistoryMarkingPoint()
        {
            var owner = new Mock<IOwnScheduleDefinitions>();

            MarkHistoryVertex startVertex = new MarkHistoryVertex(0);
            var scheduleBuilder = new Mock<IBuildFixedSchedules>();
            {
                scheduleBuilder.Setup(s => s.AddHistoryMarkingPoint())
                    .Returns(startVertex);
            }

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

            Assert.AreSame(startVertex, vertex);
        }
        public void AddInsertPointWithCount()
        {
            var owner = new Mock<IOwnScheduleDefinitions>();

            var scheduleBuilder = new Mock<IBuildFixedSchedules>();
            {
                scheduleBuilder.Setup(s => s.AddInsertPoint(It.IsAny<int>()))
                    .Returns<int>(i => new InsertVertex(0, i));
            }

            var builder = new ScheduleDefinitionBuilder(owner.Object, scheduleBuilder.Object);
            var vertex = builder.AddInsertPoint(10);
            Assert.AreEqual(10, vertex.RemainingInserts);
        }