コード例 #1
0
        public void RouteGeneratorReturnsNullWhenNotAllParametersFilledIn()
        {
            var route = new RegexRoute(@"(?<Controller>[a-zA-Z]+)(_(?<Action>[a-zA-Z]+))?(_?<Id>\d+)?",
                                       "{Controller}_{Action}_{Id}", handler);
            RouteData       routeData = route.GetRouteData("Products_View_0");
            VirtualPathData pathData  = route.GetVirtualPath(new RequestContext(mr.PartialMock <HttpContextBase>(), routeData),
                                                             new RouteValueDictionary(
                                                                 new { Controller = "Accounts", Action = "Delete" }));

            Assert.IsNull(pathData);
        }
コード例 #2
0
        public void RouteGeneratorGeneratesValidRouteWithoutDefaults()
        {
            var route = new RegexRoute(@"(?<Controller>[a-zA-Z]+)(_(?<Action>[a-zA-Z]+))?(_?<Id>\d+)?",
                                       "{Controller}_{Action}_{Id}", handler);
            RouteData       routeData = route.GetRouteData("Products_View_0");
            VirtualPathData pathData  = route.GetVirtualPath(new RequestContext(mr.PartialMock <HttpContextBase>(), routeData),
                                                             new RouteValueDictionary(
                                                                 new { Controller = "Accounts", Action = "Delete", Id = 0 }));

            Assert.AreEqual("Accounts_Delete_0", pathData.VirtualPath);
        }
コード例 #3
0
        public void RouteGeneratorCallsCustomFunctionIfProvided()
        {
            bool                 called           = false;
            RequestContext       innerContext     = null;
            RouteValueDictionary innerRouteValues = null;
            RegexRoute           innerRoute       = null;
            VirtualPathData      innerPathData    = null;
            var route = new RegexRoute(
                @"(?<Controller>[a-zA-Z]+)(_(?<Action>[a-zA-Z]+))?(_?<Id>\d+)?",
                delegate(RequestContext context, RouteValueDictionary routeValues, RegexRoute thisRoute)
            {
                called           = true;
                innerContext     = context;
                innerRouteValues = routeValues;
                innerRoute       = thisRoute;
                innerPathData    = new VirtualPathData(thisRoute, "");
                return(innerPathData);
            },
                handler);
            RouteData       routeData      = route.GetRouteData("Products_View_0");
            var             values         = new RouteValueDictionary(new { Controller = "Accounts", Action = "Delete", Id = 0 });
            var             requestContext = new RequestContext(mr.PartialMock <HttpContextBase>(), routeData);
            VirtualPathData pathData       = route.GetVirtualPath(
                requestContext,
                values);

            Assert.IsTrue(called);
            Assert.IsNotNull(innerContext);
            Assert.AreSame(requestContext, innerContext);
            Assert.IsNotNull(innerRouteValues);
            Assert.AreSame(values, innerRouteValues);
            Assert.IsNotNull(innerRoute);
            Assert.AreSame(route, innerRoute);
            Assert.IsNotNull(pathData);
            Assert.AreSame(pathData, innerPathData);
        }