Ejemplo n.º 1
0
        static HttpRequest RequestAfterApiVersionConstraintHasBeenMatched(string requestedVersion)
        {
            const string ParmaterName = "version";
            const string ItemKey      = "MS_ApiVersionRequestProperties";
            var          request      = new Mock <HttpRequest>();

            var routeData = new RouteData()
            {
                Values = { [ParmaterName] = requestedVersion }
            };
            var feature = new RoutingFeature()
            {
                RouteData = routeData
            };
            var featureCollection = new Mock <IFeatureCollection>();
            var items             = new Dictionary <object, object>();
            var httpContext       = new Mock <HttpContext>();
            var reader            = new UrlSegmentApiVersionReader();

            featureCollection.SetupGet(fc => fc[typeof(IRoutingFeature)]).Returns(feature);
            httpContext.SetupProperty(c => c.Items, items);
            httpContext.SetupGet(c => c.Features).Returns(featureCollection.Object);

            var properties = new ApiVersionRequestProperties(httpContext.Object)
            {
                RouteParameterName = ParmaterName
            };

            items[ItemKey] = properties;
            request.SetupGet(r => r.HttpContext).Returns(httpContext.Object);

            return(request.Object);
        }
Ejemplo n.º 2
0
        public void read_should_retrieve_version_from_url()
        {
            // arrange
            var requestedVersion = "2";
            var request          = RequestAfterApiVersionConstraintHasBeenMatched(requestedVersion);
            var reader           = new UrlSegmentApiVersionReader();

            // act
            var version = reader.Read(request);

            // assert
            version.Should().Be(requestedVersion);
        }
Ejemplo n.º 3
0
        public void read_should_retrieve_version_from_url()
        {
            // arrange
            var requestedVersion = "2";
            var constraint       = new ApiVersionRouteConstraint();
            var reader           = new UrlSegmentApiVersionReader();
            var request          = RequestAfterApiVersionConstraintHasBeenMatched(requestedVersion, reader);
            var httpContext      = request.HttpContext;
            var route            = default(IRouter);
            var routeData        = ((RoutingFeature)httpContext.Features[typeof(IRoutingFeature)]).RouteData;

            constraint.Match(httpContext, route, "version", routeData.Values, IncomingRequest);

            // act
            var version = reader.Read(request);

            // assert
            version.Should().Be(requestedVersion);
        }