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));
        }
Пример #2
0
        public void IsTemplatedShouldReturnCorrectValue(bool isTemplated)
        {
            LinkRequest request = LinkRequestBuilder.CreateWithRouteName(TestRouteName).Set(IsTemplatedEnricher.TemplatedKey, isTemplated);

            var result = request.IsTemplated();

            result.Should().Be(isTemplated);
        }
Пример #3
0
        public void IsTemplatedShouldReturnFalseWhenRequestContainsAnInvalidTemplatedValue()
        {
            LinkRequest request = LinkRequestBuilder.CreateWithRouteName(TestRouteName).Set(IsTemplatedEnricher.TemplatedKey, "yes");

            var result = request.IsTemplated();

            result.Should().BeFalse();
        }
Пример #4
0
        public void IsTemplatedShouldReturnFalseWhenRequestDoesNotContainAValueForTemplated()
        {
            LinkRequest request = LinkRequestBuilder.CreateWithRouteName(TestRouteName);

            var result = request.IsTemplated();

            result.Should().BeFalse();
        }
Пример #5
0
        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);
            }
        }