Esempio n. 1
0
        private RoadNetworkView Given(Messages.RoadSegmentAdded @event)
        {
            var id    = new RoadSegmentId(@event.Id);
            var start = new RoadNodeId(@event.StartNodeId);
            var end   = new RoadNodeId(@event.EndNodeId);

            var attributeHash = AttributeHash.None
                                .With(RoadSegmentAccessRestriction.Parse(@event.AccessRestriction))
                                .With(RoadSegmentCategory.Parse(@event.Category))
                                .With(RoadSegmentMorphology.Parse(@event.Morphology))
                                .With(RoadSegmentStatus.Parse(@event.Status))
                                .WithLeftSide(@event.LeftSide.StreetNameId.HasValue
                    ? new CrabStreetnameId(@event.LeftSide.StreetNameId.Value)
                    : new CrabStreetnameId?())
                                .WithRightSide(@event.RightSide.StreetNameId.HasValue
                    ? new CrabStreetnameId(@event.RightSide.StreetNameId.Value)
                    : new CrabStreetnameId?())
                                .With(new OrganizationId(@event.MaintenanceAuthority.Code));

            var segment = new RoadSegment(
                id,
                GeometryTranslator.Translate(@event.Geometry),
                start,
                end,
                attributeHash);

            return(new RoadNetworkView(
                       _nodes
                       .TryReplace(start, node => node.ConnectWith(id))
                       .TryReplace(end, node => node.ConnectWith(id)),
                       _segments.Add(id, segment),
                       _maximumNodeId,
                       RoadSegmentId.Max(id, _maximumSegmentId),
                       _maximumGradeSeparatedJunctionId,
                       _maximumEuropeanRoadAttributeId,
                       _maximumNationalRoadAttributeId,
                       _maximumNumberedRoadAttributeId,
                       @event.Lanes.Length != 0
                    ? AttributeId.Max(
                           new AttributeId(@event.Lanes.Max(_ => _.AttributeId)),
                           _maximumLaneAttributeId)
                    : _maximumLaneAttributeId,
                       @event.Widths.Length != 0
                    ? AttributeId.Max(
                           new AttributeId(@event.Widths.Max(_ => _.AttributeId)),
                           _maximumWidthAttributeId)
                    : _maximumWidthAttributeId,
                       @event.Surfaces.Length != 0
                    ? AttributeId.Max(
                           new AttributeId(@event.Surfaces.Max(_ => _.AttributeId)),
                           _maximumSurfaceAttributeId)
                    : _maximumSurfaceAttributeId,
                       _segmentReusableLaneAttributeIdentifiers.AddOrMergeDistinct(id, @event.Lanes.Select(lane => new AttributeId(lane.AttributeId))),
                       _segmentReusableWidthAttributeIdentifiers.AddOrMergeDistinct(id, @event.Widths.Select(width => new AttributeId(width.AttributeId))),
                       _segmentReusableSurfaceAttributeIdentifiers.AddOrMergeDistinct(id, @event.Surfaces.Select(surface => new AttributeId(surface.AttributeId)))
                       ));
        }
        public void SelectOppositeNodeReturnsExpectedResult(
            int start,
            int end,
            int node,
            int[] opposite
            )
        {
            var sut = new RoadSegment(
                _id,
                _geometry,
                new RoadNodeId(start),
                new RoadNodeId(end),
                _attributeHash);

            var result = sut.SelectOppositeNode(new RoadNodeId(node)).ToArray();

            var expected = Array.ConvertAll(opposite, value => new RoadNodeId(value));

            Assert.Equal(expected, result);
        }
        public RoadSegmentTests()
        {
            var fixture = new Fixture();

            fixture.CustomizePolylineM();
            fixture.CustomizeRoadNodeId();
            fixture.CustomizeRoadSegmentId();
            fixture.CustomizeRoadSegmentCategory();
            fixture.CustomizeRoadSegmentMorphology();
            fixture.CustomizeRoadSegmentStatus();
            fixture.CustomizeRoadSegmentAccessRestriction();
            fixture.CustomizeOrganizationId();
            fixture.CustomizeAttributeHash();
            _id            = fixture.Create <RoadSegmentId>();
            _start         = fixture.Create <RoadNodeId>();
            _end           = fixture.Create <RoadNodeId>();
            _geometry      = fixture.Create <MultiLineString>();
            _attributeHash = fixture.Create <AttributeHash>();
            _sut           = new RoadSegment(_id, _geometry, _start, _end, _attributeHash);
        }