public RoadNetworkView Given(Messages.ImportedRoadSegment @event) { if (@event == null) { throw new ArgumentNullException(nameof(@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, @event.PartOfEuropeanRoads.Length != 0 ? AttributeId.Max( new AttributeId(@event.PartOfEuropeanRoads.Max(_ => _.AttributeId)), _maximumEuropeanRoadAttributeId) : _maximumEuropeanRoadAttributeId, @event.PartOfNationalRoads.Length != 0 ? AttributeId.Max( new AttributeId(@event.PartOfNationalRoads.Max(_ => _.AttributeId)), _maximumNationalRoadAttributeId) : _maximumNationalRoadAttributeId, @event.PartOfNumberedRoads.Length != 0 ? AttributeId.Max( new AttributeId(@event.PartOfNumberedRoads.Max(_ => _.AttributeId)), _maximumNumberedRoadAttributeId) : _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))) )); }