Ejemplo n.º 1
0
        public void ExtractFromKey_ShouldReturnCorrectValue_WhenFromPageIsUsed(Type fromPageType, string expectedFromKey)
        {
            var attr = new BreadcrumbAttribute
            {
                FromPage = fromPageType
            };

            Assert.Equal(expectedFromKey, attr.ExtractFromKey(null));
        }
Ejemplo n.º 2
0
        public void ExtractFromKey_ShouldReturnCorrectValue_WhenActionAndControllerAreUsed()
        {
            var attr = new BreadcrumbAttribute
            {
                FromAction     = "MyAction",
                FromController = typeof(TestController)
            };

            Assert.Equal("Test.MyAction", attr.ExtractFromKey(null));
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
 internal BreadcrumbNode(BreadcrumbAttribute attr) :
     this(attr.Title, attr.OverwriteTitleOnExactMatch, attr.IconClasses, attr.AreaName, attr.RouteValueKeys)
 {
 }
Ejemplo n.º 11
0
 internal RazorPageBreadcrumbNode(string path, BreadcrumbAttribute attr) : base(attr)
 {
     Path = path;
 }
Ejemplo n.º 12
0
 internal MvcBreadcrumbNode(string action, string controller, BreadcrumbAttribute attr) : base(attr)
 {
     Action     = action;
     Controller = controller;
 }
 internal MvcControllerBreadcrumbNode(string controller, BreadcrumbAttribute attr) : base(attr)
 {
     Controller = controller;
 }
Ejemplo n.º 14
0
 internal MvcRouteBreadcrumbNode(string routeName, BreadcrumbAttribute attr) : base(attr)
 {
     RouteName = routeName;
 }