Пример #1
0
            public bool Equals(ExecutingScheduleKey other)
            {
                if (ReferenceEquals(this, other))
                {
                    return(true);
                }

                // Check if other is a null reference by using ReferenceEquals because
                // we overload the == operator. If other isn't actually null then
                // we get an infinite loop where we're constantly trying to compare to null.
                return(!ReferenceEquals(other, null) &&
                       m_Id.Equals(other.m_Id) &&
                       (((m_Variables == null) && (other.m_Variables == null)) ||
                        ((m_Variables != null) && (other.m_Variables != null) && m_Variables.SequenceEqual(other.m_Variables))));
            }
Пример #2
0
        public void IsEqual()
        {
            var id = new ScheduleId("A12345", new DateTime(2019, 1, 2), StpIndicator.P, RecordAction.Create);

            Assert.True(_test.Equals(id));
        }
Пример #3
0
        public void NestedSubScheduleWithLinkBackToRootSchedule()
        {
            var id = new ScheduleId();

            var       subSubScheduleId = new ScheduleId();
            ISchedule subSubSchedule;
            {
                var subGraph = new BidirectionalGraph <IScheduleVertex, ScheduleEdge>();
                var start    = new StartVertex(1);
                var end      = new EndVertex(2);
                var vertex1  = new SubScheduleVertex(3, id);
                subGraph.AddVertex(start);
                subGraph.AddVertex(end);
                subGraph.AddVertex(vertex1);
                subGraph.AddEdge(new ScheduleEdge(start, vertex1));
                subGraph.AddEdge(new ScheduleEdge(vertex1, end));
                subSubSchedule = new Schedule(subGraph, start, end);
            }

            var       subScheduleId = new ScheduleId();
            ISchedule subSchedule;
            {
                var subGraph = new BidirectionalGraph <IScheduleVertex, ScheduleEdge>();
                var start    = new StartVertex(1);
                var end      = new EndVertex(2);
                var vertex1  = new SubScheduleVertex(3, subSubScheduleId);
                subGraph.AddVertex(start);
                subGraph.AddVertex(end);
                subGraph.AddVertex(vertex1);
                subGraph.AddEdge(new ScheduleEdge(start, vertex1));
                subGraph.AddEdge(new ScheduleEdge(vertex1, end));
                subSchedule = new Schedule(subGraph, start, end);
            }

            IScheduleVertex errorVertex;
            Schedule        schedule;
            {
                var graph   = new BidirectionalGraph <IScheduleVertex, ScheduleEdge>();
                var start   = new StartVertex(1);
                var end     = new EndVertex(2);
                var vertex1 = new SubScheduleVertex(3, subScheduleId);
                graph.AddVertex(start);
                graph.AddVertex(end);
                graph.AddVertex(vertex1);
                graph.AddEdge(new ScheduleEdge(start, vertex1));
                graph.AddEdge(new ScheduleEdge(vertex1, end));
                schedule = new Schedule(graph, start, end);

                errorVertex = vertex1;
            }

            var knownSchedules = new Mock <IStoreSchedules>();
            {
                knownSchedules.Setup(s => s.Contains(It.IsAny <ScheduleId>()))
                .Returns <ScheduleId>(scheduleId => subScheduleId.Equals(scheduleId) || subSubScheduleId.Equals(scheduleId));
                knownSchedules.Setup(s => s.Schedule(It.IsAny <ScheduleId>()))
                .Returns <ScheduleId>(
                    scheduleId =>
                {
                    return(subSubScheduleId.Equals(scheduleId) ? subSubSchedule : subSchedule);
                });
            }

            var failures = new List <Tuple <ScheduleIntegrityFailureType, IScheduleVertex> >();

            var verifier = new ScheduleVerifier(knownSchedules.Object);
            var result   = verifier.IsValid(
                id,
                schedule,
                (f, v) => failures.Add(new Tuple <ScheduleIntegrityFailureType, IScheduleVertex>(f, v)));

            Assert.IsFalse(result);
            Assert.AreEqual(1, failures.Count);
            Assert.AreEqual(ScheduleIntegrityFailureType.SubScheduleLinksBackToParentSchedule, failures[0].Item1);
            Assert.AreSame(errorVertex, failures[0].Item2);
        }
Пример #4
0
        public void NestedSubScheduleWithLinkBackToRootSchedule()
        {
            var id = new ScheduleId();

            var subSubScheduleId = new ScheduleId();
            ISchedule subSubSchedule;
            {
                var subGraph = new BidirectionalGraph<IScheduleVertex, ScheduleEdge>();
                var start = new StartVertex(1);
                var end = new EndVertex(2);
                var vertex1 = new SubScheduleVertex(3, id);
                subGraph.AddVertex(start);
                subGraph.AddVertex(end);
                subGraph.AddVertex(vertex1);
                subGraph.AddEdge(new ScheduleEdge(start, vertex1));
                subGraph.AddEdge(new ScheduleEdge(vertex1, end));
                subSubSchedule = new Schedule(subGraph, start, end);
            }

            var subScheduleId = new ScheduleId();
            ISchedule subSchedule;
            {
                var subGraph = new BidirectionalGraph<IScheduleVertex, ScheduleEdge>();
                var start = new StartVertex(1);
                var end = new EndVertex(2);
                var vertex1 = new SubScheduleVertex(3, subSubScheduleId);
                subGraph.AddVertex(start);
                subGraph.AddVertex(end);
                subGraph.AddVertex(vertex1);
                subGraph.AddEdge(new ScheduleEdge(start, vertex1));
                subGraph.AddEdge(new ScheduleEdge(vertex1, end));
                subSchedule = new Schedule(subGraph, start, end);
            }

            IScheduleVertex errorVertex;
            Schedule schedule;
            {
                var graph = new BidirectionalGraph<IScheduleVertex, ScheduleEdge>();
                var start = new StartVertex(1);
                var end = new EndVertex(2);
                var vertex1 = new SubScheduleVertex(3, subScheduleId);
                graph.AddVertex(start);
                graph.AddVertex(end);
                graph.AddVertex(vertex1);
                graph.AddEdge(new ScheduleEdge(start, vertex1));
                graph.AddEdge(new ScheduleEdge(vertex1, end));
                schedule = new Schedule(graph, start, end);

                errorVertex = vertex1;
            }

            var knownSchedules = new Mock<IStoreSchedules>();
            {
                knownSchedules.Setup(s => s.Contains(It.IsAny<ScheduleId>()))
                    .Returns<ScheduleId>(scheduleId => subScheduleId.Equals(scheduleId) || subSubScheduleId.Equals(scheduleId));
                knownSchedules.Setup(s => s.Schedule(It.IsAny<ScheduleId>()))
                    .Returns<ScheduleId>(
                        scheduleId =>
                        {
                            return subSubScheduleId.Equals(scheduleId) ? subSubSchedule : subSchedule;
                        });
            }

            var failures = new List<Tuple<ScheduleIntegrityFailureType, IScheduleVertex>>();

            var verifier = new ScheduleVerifier(knownSchedules.Object);
            var result = verifier.IsValid(
                id,
                schedule,
                (f, v) => failures.Add(new Tuple<ScheduleIntegrityFailureType, IScheduleVertex>(f, v)));

            Assert.IsFalse(result);
            Assert.AreEqual(1, failures.Count);
            Assert.AreEqual(ScheduleIntegrityFailureType.SubScheduleLinksBackToParentSchedule, failures[0].Item1);
            Assert.AreSame(errorVertex, failures[0].Item2);
        }