public void ParseRouteTemplate_ConstraintsDefaultsAndOptionalsInMultipleSections_ParsedCorrectly() { // Arrange & Act var routePattern = RoutePattern.Parse(@"some/url-{p1:int:test(3)=hello}/{p2=abc}/{p3?}"); // Assert var parameters = routePattern.Parameters.ToArray(); var param1 = parameters[0]; Assert.Equal("p1", param1.Name); Assert.Equal("hello", param1.DefaultValue); Assert.False(param1.IsOptional); Assert.Collection(param1.Constraints, constraint => Assert.Equal("int", constraint.Content), constraint => Assert.Equal("test(3)", constraint.Content) ); var param2 = parameters[1]; Assert.Equal("p2", param2.Name); Assert.Equal("abc", param2.DefaultValue); Assert.False(param2.IsOptional); var param3 = parameters[2]; Assert.Equal("p3", param3.Name); Assert.True(param3.IsOptional); }
public RouteTemplate(Other other) { TemplateText = other.RawText; Segments = new List <TemplateSegment>(other.PathSegments.Select(p => new TemplateSegment(p))); Parameters = new List <TemplatePart>(); for (var i = 0; i < Segments.Count; i++) { var segment = Segments[i]; for (var j = 0; j < segment.Parts.Count; j++) { var part = segment.Parts[j]; if (part.IsParameter) { Parameters.Add(part); } } } }