public void When_Additional_Properties_Exists_Ignore_When_IncludeExtra_False()
        {
            // Act
            var descriptor = new ApiOperationDescriptor(typeof(LinkGeneratorTestsOperation), "tests");
            var link       = new ApiOperationLink(descriptor, "/users", "a.rel");

            // Assert
            link.CreateRelativeUrl(new { sortBy = "name", page = 2 }, false).Should().Be("users");
        }
        public void When_Placeholder_Specifies_Alternate_Property_And_Followed_By_Another_Placeholder_Then_Uses_That_Property_From_Instance_Values()
        {
            // Act
            var descriptor = new ApiOperationDescriptor(typeof(LinkGeneratorTestsOperation), "tests");
            var link       = new ApiOperationLink(descriptor, "/aUrl/{clientid:id}/{category}", "a.rel");

            // Assert
            link.CreateRelativeUrl(new { id = 15484, category = "value" }).Should().EndWith("aUrl/15484/value");
        }
        public void When_Placeholder_Followed_By_Static_Then_Includes_All()
        {
            // Act
            var descriptor = new ApiOperationDescriptor(typeof(LinkGeneratorTestsOperation), "tests");
            var link       = new ApiOperationLink(descriptor, "/aUrl/{clientid:id}/some-more", "a.rel");

            // Assert
            link.CreateRelativeUrl(new { id = 15484 }).Should().EndWith("aUrl/15484/some-more");
        }
        public void When_Url_With_Placeholder_Then_Returns_Null_If_Property_Is_Null()
        {
            // Act
            var descriptor = new ApiOperationDescriptor(typeof(LinkGeneratorTestsOperation), "tests");
            var link       = new ApiOperationLink(descriptor, "/aUrl/{category}", "a.rel");

            // Assert
            link.CreateRelativeUrl(new { category = (string)null }).Should().BeNull();
        }
        public void When_Url_With_Placeholder_Requiring_Encoding_Then_CreateUrl_Replaces_With_Encoded_Property_In_PropValues()
        {
            // Act
            var descriptor = new ApiOperationDescriptor(typeof(LinkGeneratorTestsOperation), "tests");
            var link       = new ApiOperationLink(descriptor, "/aUrl/{category}", "a.rel");

            // Assert
            link.CreateRelativeUrl(new { category = "all dogs" }).Should().EndWith("aUrl/all%20dogs");
        }
        public void When_Url_No_Placeholders_CreateUrl_Returns_Url_As_Is()
        {
            // Arrange
            var descriptor = new ApiOperationDescriptor(typeof(LinkGeneratorTestsOperation), "tests");
            var link       = new ApiOperationLink(descriptor, "/aUrl", "a.rel");

            // Assert
            link.CreateRelativeUrl(new object()).Should().EndWith("aUrl");
        }
        public void When_Placeholder_Has_Format_Then_CreateUrl_Uses_Format()
        {
            // Act
            var descriptor = new ApiOperationDescriptor(typeof(LinkGeneratorTestsOperation), "tests");
            var date       = new DateTime(2012, 04, 21);
            var link       = new ApiOperationLink(descriptor, "/aUrl/{date(yyyy-MM-dd)}", "a.rel");

            // Assert
            link.CreateRelativeUrl(new { date }).Should().EndWith("aUrl/2012-04-21");
        }
        public void When_Additional_Properties_And_Placeholders_Exists_Adds_As_QueryString_When_IncludeExtra_True()
        {
            // Act
            var descriptor = new ApiOperationDescriptor(typeof(LinkGeneratorTestsOperation), "tests");
            var link       = new ApiOperationLink(descriptor, "/clients/{clientId}/users", "a.rel");

            // Act
            var url = link.CreateRelativeUrl(new LinkGeneratorTestsOperation {
                ClientId = 12, SortBy = "name", Page = 2
            }, true);

            // Assert
            url.Should().Be("clients/12/users?SortBy=name&Page=2");
        }
Esempio n. 9
0
        /// <inheritdoc />
        public string CreateUrl(ApiOperationLink link, object result = null)
        {
            // We can short-circuit in the (relatively uncommon case) of no placeholders
            if (!link.HasPlaceholders())
            {
                return(this._baseUri + link.UrlFormat);
            }

            var relativeUrl = link.CreateRelativeUrl(result);

            // We cannot create a full URL if the relative link is null
            if (relativeUrl == null)
            {
                return(null);
            }

            // baseUri always has / at end, relative never has at start
            return(this._baseUri + relativeUrl);
        }