Example #1
0
        public void Index()
        {
            var index  = 10;
            var vertex = new MarkHistoryVertex(index);

            Assert.AreEqual(index, vertex.Index);
        }
        public void InsertInWithOneInsertAllowed()
        {
            var conditionId1 = new ScheduleElementId();
            var conditionId2 = new ScheduleElementId();

            var builder = new FixedScheduleBuilder();
            var insertVertex = builder.AddInsertPoint(1);
            builder.LinkFromStart(insertVertex, conditionId1);
            builder.LinkToEnd(insertVertex, conditionId2);

            var markHistoryVertex = new MarkHistoryVertex(10);
            builder.InsertIn(insertVertex, markHistoryVertex);
            var schedule = builder.Build();

            int index = 0;
            var vertexTypes = new List<Type>
                {
                    typeof(StartVertex),
                    typeof(MarkHistoryVertex),
                    typeof(EndVertex)
                };
            var conditions = new List<ScheduleElementId>
                {
                    conditionId1,
                    conditionId2
                };

            schedule.TraverseAllScheduleVertices(
                schedule.Start,
                (vertex, edges) =>
                {
                    Assert.AreEqual(vertexTypes[index], vertex.GetType());
                    if (index < conditions.Count)
                    {
                        Assert.AreEqual(1, edges.Count());
                        Assert.AreEqual(conditions[index], edges.First().Item1);
                    }

                    index++;
                    return true;
                });
        }
        public void InsertInWithNoMoreRemainingInserts()
        {
            var builder = new FixedScheduleBuilder();
            var insertVertex = builder.AddInsertPoint(1);
            builder.LinkFromStart(insertVertex);
            builder.LinkToEnd(insertVertex);

            var markHistoryVertex1 = new MarkHistoryVertex(10);
            var newInserts = builder.InsertIn(insertVertex, markHistoryVertex1);
            Assert.IsNull(newInserts.Item1);
            Assert.IsNull(newInserts.Item2);
        }
        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 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 LinkToWithCondition()
        {
            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 start = new MarkHistoryVertex(0);
            var end = new InsertVertex(1);
            var condition = new ScheduleConditionRegistrationId(typeof(string), 0, "a");
            builder.LinkTo(start, end, condition);

            Assert.IsNotNull(id);
        }
        /// <summary>
        /// Adds a vertex which indicates that the current values of all history-enabled data should
        /// be stored in the <see cref="Timeline"/> so that it is possible to revert to the
        /// current point in time later on.
        /// </summary>
        /// <returns>The vertex that indicates that the current state should be stored in the <see cref="Timeline"/>.</returns>
        public MarkHistoryVertex AddHistoryMarkingPoint()
        {
            var result = new MarkHistoryVertex(m_Schedule.VertexCount);
            m_Schedule.AddVertex(result);

            return result;
        }