public void ExtractFromKey_ShouldReturnCorrectValue_WhenFromPageIsUsed(Type fromPageType, string expectedFromKey) { var attr = new BreadcrumbAttribute { FromPage = fromPageType }; Assert.Equal(expectedFromKey, attr.ExtractFromKey(null)); }
public void ExtractFromKey_ShouldReturnCorrectValue_WhenActionAndControllerAreUsed() { var attr = new BreadcrumbAttribute { FromAction = "MyAction", FromController = typeof(TestController) }; Assert.Equal("Test.MyAction", attr.ExtractFromKey(null)); }
public void ExtractFromKey_ShouldThrowException_WhenFromPageIsntARazorPage() { var fromPageType = typeof(TestClassThree); var attr = new BreadcrumbAttribute { FromPage = fromPageType }; var ex = Assert.Throws <SmartBreadcrumbsException>(() => attr.ExtractFromKey(null)); Assert.Equal($"'{fromPageType.Name}' is used in FromPage but isn't a Razor Page.", ex.Message); }
public void ExtractFromKey_ShouldThrowException_WhenFromControllerIsNullWhileFromActionIsnt() { var type = typeof(TestClassTwo); var attr = new BreadcrumbAttribute { FromAction = "Method" }; var ex = Assert.Throws <SmartBreadcrumbsException>(() => attr.ExtractFromKey(type)); Assert.Equal($"Can't infer FromController as '{type.Name}' is a Razor Page.", ex.Message); }
public void ExtractFromKey_ShouldThrowException_WhenFromActionIsntAMethodInFromController() { var controllerType = typeof(TestController); var attr = new BreadcrumbAttribute { FromAction = "MyActio", FromController = controllerType }; var ex = Assert.Throws <SmartBreadcrumbsException>(() => attr.ExtractFromKey(controllerType)); Assert.Equal($"{controllerType.Name} doesn't contain a valid action named {attr.FromAction}.", ex.Message); }
public void ExtractFromKey_ShouldThrowException_WhenControllerIsntValid() { var controllerType = typeof(TestClassThree); var attr = new BreadcrumbAttribute { FromAction = "Test", FromController = controllerType }; var ex = Assert.Throws <SmartBreadcrumbsException>(() => attr.ExtractFromKey(null)); Assert.Equal($"'{controllerType.Name}' is used in FromController but isn't a Controller.", ex.Message); }
public static string BreadcrumbActionName(this HtmlHelper htmlHelper) { string controller = htmlHelper.ControllerName(); //çağırdığım controllerın adını aldık. string action = htmlHelper.ActionName(); //action name aldık. Type t = Type.GetType("BlogFall.Areas.Admin.Controllers." + controller + "Controller"); //Controllerın classının tipi MethodInfo mi = t.GetMethods().FirstOrDefault(x => x.Name == action); BreadcrumbAttribute ba = mi.GetCustomAttribute(typeof(BreadcrumbAttribute)) as BreadcrumbAttribute; if (ba == null) { return(action); } return(ba.Name); }
private static string BuildBreadcrumb(BreadcrumbAttribute bs, IUrlHelper urlHelper, string parameters) { string link = "<li class='breadcrumb-item'>"; if (!string.IsNullOrEmpty(bs.ActionName) && !string.IsNullOrEmpty(bs.ControllerName)) { link += $"<a href='{urlHelper.AbsoluteAction(bs.ActionName, bs.ControllerName)}{(bs.PassArguments ? parameters : string.Empty)}'>{bs.Label}</a>"; } else { link += bs.Label; } link += "</li>"; return(link); }
public static string BreadcrumbActionName(this HtmlHelper htmlHelper) { string controller = htmlHelper.ControllerName(); string action = htmlHelper.ActionName(); Type t = Type.GetType("ButikBlog.Areas.Admin.Controllers." + controller + "Controller"); MethodInfo mi = t.GetMethods().FirstOrDefault(x => x.Name == action); BreadcrumbAttribute ba = mi.GetCustomAttribute(typeof(BreadcrumbAttribute)) as BreadcrumbAttribute; if (ba == null) { return(action); } return(ba.Name); }
internal BreadcrumbNode(BreadcrumbAttribute attr) : this(attr.Title, attr.OverwriteTitleOnExactMatch, attr.IconClasses, attr.AreaName, attr.RouteValueKeys) { }
internal RazorPageBreadcrumbNode(string path, BreadcrumbAttribute attr) : base(attr) { Path = path; }
internal MvcBreadcrumbNode(string action, string controller, BreadcrumbAttribute attr) : base(attr) { Action = action; Controller = controller; }
internal MvcControllerBreadcrumbNode(string controller, BreadcrumbAttribute attr) : base(attr) { Controller = controller; }
internal MvcRouteBreadcrumbNode(string routeName, BreadcrumbAttribute attr) : base(attr) { RouteName = routeName; }