public void GetUmbracoRouteValues_Returns_Default() { var router = new UmbracoRouter(Mock.Of <IRouter>()); var httpCtxAccessor = new Mock <IHttpContextAccessor>(); var httpContext = new Mock <HttpContext>(); httpContext.Setup(context => context.Request).Returns(Mock.Of <HttpRequest>()); httpCtxAccessor.Setup(accessor => accessor.HttpContext).Returns(httpContext.Object); var umbCtx = new UmbracoContext(httpCtxAccessor.Object); var urlProvider = new UrlProvider(umbCtx, Enumerable.Empty <IUrlProvider>()); var routingCtx = new RoutingContext(Enumerable.Empty <IContentFinder>(), Mock.Of <ILastChanceContentFinder>(), urlProvider); var pcr = new PublishedContentRequest(routingCtx, Mock.Of <ITemplateService>(), Mock.Of <ILoggerFactory>(), httpCtxAccessor.Object) { PublishedContent = new PublishedContent() }; umbCtx.Initialize(pcr); var actionDescriptors = new Mock <IActionDescriptorsCollectionProvider>(); actionDescriptors.Setup(provider => provider.ActionDescriptors).Returns(new ActionDescriptorsCollection(new List <ActionDescriptor>(), 0)); var result = router.GetUmbracoRouteValues(umbCtx, new UmbracoControllerTypeCollection(actionDescriptors.Object)); Assert.Equal("Umbraco", result.ControllerName); Assert.Equal("Index", result.ActionName); }
internal async Task<bool> RouteUmbracoContentAsync(UmbracoContext umbCtx, PublishedContentRequest pcr, RouteData routeData) { //Initialize the context, this will be called a few times but the initialize logic // only executes once. There might be a nicer way to do this but the RouteContext and // other request scoped instances are not available yet. umbCtx.Initialize(pcr); //Prepare the request if it hasn't already been done if (pcr.IsPrepared == false) { if (await pcr.PrepareAsync(routeData)) { if (umbCtx.HasContent == false) return false; } } return umbCtx.HasContent; }
public bool Accept(ActionConstraintContext context) { //Initialize the context, this will be called a few times but the initialize logic // only executes once. There might be a nicer way to do this but the RouteContext and // other request scoped instances are not available yet. _umbCtx.Initialize(context.RouteContext.RouteData); if (_umbCtx.HasContent == false) { return(false); } //Is this a POST if (context.RouteContext.HttpContext.Request.Method.Equals("POST", StringComparison.InvariantCultureIgnoreCase)) { if (((ControllerActionDescriptor)context.CurrentCandidate.Action).ControllerName == "TestSurface") { return(true); } } ////NOTE: This get's bound currently //context.RouteContext.RouteData.Values["txtFile"] = filePath; //string actionNameRequest = // context.RouteContext.HttpContext.Request.Query["actionName"] ?? //"Index"; //object controllerNameFound; //if (context.CurrentCandidate.Action.Properties.TryGetValue("controllerName", out controllerNameFound)) //{ // if ((string)controllerNameFound == controllerNameRequest) // { // return true; // } //} //OR You could do this: if (((ControllerActionDescriptor)context.CurrentCandidate.Action).ControllerName == _umbCtx.AltTemplate) { return(true); } return(false); }
public void GetUmbracoRouteValues_Find_Custom_Controller() { var router = new UmbracoRouter(Mock.Of <IRouter>()); var httpCtxAccessor = new Mock <IHttpContextAccessor>(); var httpContext = new Mock <HttpContext>(); httpContext.Setup(context => context.Request).Returns(Mock.Of <HttpRequest>()); httpCtxAccessor.Setup(accessor => accessor.HttpContext).Returns(httpContext.Object); var umbCtx = new UmbracoContext(httpCtxAccessor.Object); var urlProvider = new UrlProvider(umbCtx, Enumerable.Empty <IUrlProvider>()); var routingCtx = new RoutingContext(Enumerable.Empty <IContentFinder>(), Mock.Of <ILastChanceContentFinder>(), urlProvider); var templateService = new Mock <ITemplateService>(); templateService.Setup(service => service.GetTemplate("Hello")).Returns(Mock.Of <ITemplate>(template => template.Alias == "Hello")); var pcr = new PublishedContentRequest(routingCtx, templateService.Object, Mock.Of <ILoggerFactory>(), httpCtxAccessor.Object) { PublishedContent = new PublishedContent() { ContentType = "Custom" } }; pcr.TrySetTemplate("Hello"); umbCtx.Initialize(pcr); var actionDescriptors = new Mock <IActionDescriptorsCollectionProvider>(); actionDescriptors.Setup(provider => provider.ActionDescriptors).Returns(new ActionDescriptorsCollection( new List <ActionDescriptor>() { new ControllerActionDescriptor() { Name = "Hello", ControllerName = "Custom", ControllerTypeInfo = typeof(UmbracoController).GetTypeInfo() } }, 0)); var result = router.GetUmbracoRouteValues(umbCtx, new UmbracoControllerTypeCollection(actionDescriptors.Object)); Assert.Equal("Custom", result.ControllerName); Assert.Equal("Hello", result.ActionName); }
internal async Task <bool> RouteUmbracoContentAsync(UmbracoContext umbCtx, PublishedContentRequest pcr, RouteData routeData) { //Initialize the context, this will be called a few times but the initialize logic // only executes once. There might be a nicer way to do this but the RouteContext and // other request scoped instances are not available yet. umbCtx.Initialize(pcr); //Prepare the request if it hasn't already been done if (pcr.IsPrepared == false) { if (await pcr.PrepareAsync(routeData)) { if (umbCtx.HasContent == false) { return(false); } } } return(umbCtx.HasContent); }
public bool Accept(ActionConstraintContext context) { //Initialize the context, this will be called a few times but the initialize logic // only executes once. There might be a nicer way to do this but the RouteContext and // other request scoped instances are not available yet. _umbCtx.Initialize(context.RouteContext.RouteData); if (_umbCtx.HasContent == false) { return(false); } //NOTE: This was for testing at some point! //if (((ControllerActionDescriptor)context.CurrentCandidate.Action) // .ControllerName == "TestSurface") //{ // return true; //} return(false); }