Пример #1
0
        public void GetUrl_WithoutAllRequiredValues_GeneratesUrl()
        {
            // Arrange
            var template = new RoutePatternTemplate(BinderFactory.Create("api/products/{id}"));

            // Act
            var url = template.GetUrl(new DispatcherValueCollection(new { name = "billy" }));

            // Assert
            Assert.Null(url);
        }
Пример #2
0
        public void GetUrl_WithAllRequiredValues_GeneratesUrl()
        {
            // Arrange
            var template = new RoutePatternTemplate(BinderFactory.Create("api/products/{id}"));

            // Act
            var url = template.GetUrl(new DispatcherValueCollection(new { id = 17 }));

            // Assert
            Assert.Equal("/api/products/17", url);
        }
Пример #3
0
        public void GetUrl_WithAmbientValues_GeneratesUrl()
        {
            // Arrange
            var template = new RoutePatternTemplate(BinderFactory.Create("api/products/{id}/{name}"));

            var httpContext = new DefaultHttpContext();

            httpContext.Features.Set <IDispatcherFeature>(new DispatcherFeature()
            {
                Values = new DispatcherValueCollection(new { id = 17 }),
            });

            // Act
            var url = template.GetUrl(httpContext, new DispatcherValueCollection(new { name = "billy" }));

            // Assert
            Assert.Equal("/api/products/17/billy", url);
        }