public void FindPrevNode_should_return_the_parent_node_of_the_first_segment_and_throw_in_debug_build()
        {
            const int row        = 100;
            const int lane       = 3;
            var       parentNode = new RevisionGraphRevision(GitUIPluginInterfaces.ObjectId.WorkTreeId, 0);
            var       childNode  = new RevisionGraphRevision(GitUIPluginInterfaces.ObjectId.WorkTreeId, 0);
            var       segment    = new RevisionGraphSegment(parentNode, childNode);
            var       laneNode   = SetupLaneRow(row, lane, laneCount: lane + 1, firstSegment: segment);

#if !DEBUG
            // innermost "return" in RELEASE build
            _laneNodeLocator.FindPrevNode(row, lane).Should().Be((parentNode, false));
#else
            try
            {
                // Exception before innermost "return" in DEBUG build
                _laneNodeLocator.FindPrevNode(row, lane).Should().Be((parentNode, false));
                throw new AssertionException("The debug build should throw an exception!");
            }
            catch (Exception x)
            {
                x.Message.Should().Be(string.Format("All segments for a lane should have the same parent.\n"
                                                    + "Not fulfilled for rowIndex {0} lane {1} with {2} segments.",
                                                    row, lane, 2));
            }
#endif
        }
Exemplo n.º 2
0
        public LaneInfo(RevisionGraphSegment startSegment, LaneInfo?derivedFrom)
        {
            StartRevision = derivedFrom is null ? startSegment.Child : startSegment.Parent;

            int colorSeed = StartRevision.Objectid.GetHashCode();

            if (derivedFrom is null)
            {
                colorSeed ^= startSegment.Parent.Objectid.GetHashCode();
            }

            do
            {
                Color = RevisionGraphLaneColor.GetColorForLane(colorSeed);
                ++colorSeed;
            }while (Color == derivedFrom?.Color);
        }
        private RevisionGraphRevision SetupLaneRow(int row, int lane, int laneCount, int nodeLane = -1, RevisionGraphSegment firstSegment = null)
        {
            var node             = new RevisionGraphRevision(GitUIPluginInterfaces.ObjectId.WorkTreeId, 0);
            var revisionGraphRow = Substitute.For <IRevisionGraphRow>();

            var segments = new List <RevisionGraphSegment>();

            if (firstSegment != null)
            {
                segments.Add(firstSegment);
            }

            if (lane < laneCount)
            {
                revisionGraphRow.GetSegmentsForIndex(lane).Returns(segments);
            }

            revisionGraphRow.GetCurrentRevisionLane().Returns(nodeLane);
            if (lane == nodeLane)
            {
                revisionGraphRow.Revision.Returns(node);
            }
            else
            {
                segments.Add(new RevisionGraphSegment(node, null));
            }

            _revisionGraphRowProvider.GetSegmentsForRow(row).Returns(x => revisionGraphRow);
            return(node);
        }