public Uri Provide(LinkRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } var routeName = request.GetRouteName(); if (string.IsNullOrWhiteSpace(routeName)) { throw new ArgumentException($"Parameter '{nameof(request)}' must contain a '{LinkRequestBuilder.RouteNameKey}' value."); } if (request.IsTemplated()) { var template = GetTemplate(routeName); if (string.IsNullOrWhiteSpace(template)) { throw new InvalidOperationException($"The given '{LinkRequestBuilder.RouteNameKey}' to retrieve the URL template returned a null or empty value. Value of '{LinkRequestBuilder.RouteNameKey}': {routeName}"); } return(new Uri($"/{template}", UriKind.Relative)); } return(nonTemplatedUrlPathProvider.Provide(request)); }
public void IsTemplatedShouldReturnCorrectValue(bool isTemplated) { LinkRequest request = LinkRequestBuilder.CreateWithRouteName(TestRouteName).Set(IsTemplatedEnricher.TemplatedKey, isTemplated); var result = request.IsTemplated(); result.Should().Be(isTemplated); }
public void IsTemplatedShouldReturnFalseWhenRequestContainsAnInvalidTemplatedValue() { LinkRequest request = LinkRequestBuilder.CreateWithRouteName(TestRouteName).Set(IsTemplatedEnricher.TemplatedKey, "yes"); var result = request.IsTemplated(); result.Should().BeFalse(); }
public void IsTemplatedShouldReturnFalseWhenRequestDoesNotContainAValueForTemplated() { LinkRequest request = LinkRequestBuilder.CreateWithRouteName(TestRouteName); var result = request.IsTemplated(); result.Should().BeFalse(); }
public void Enrich(LinkRequest request, LinkDataWriter writer) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (writer == null) { throw new ArgumentNullException(nameof(writer)); } if (request.IsTemplated()) { writer.Write(TemplatedKey, true); } }