public void GetActionTitle_GetsTitle()
        {
            String expected = MvcTemplate.Resources.Shared.Actions.Create;
            String actual   = ResourceProvider.GetActionTitle("Create");

            Assert.AreEqual(expected, actual);
        }
Exemple #2
0
        public static MvcHtmlString WidgetButton(this HtmlHelper html, String action, String iconClass)
        {
            String controller = html.ViewContext.RouteData.Values["controller"] as String;
            String accountId  = html.ViewContext.HttpContext.User.Identity.Name;
            String area       = html.ViewContext.RouteData.Values["area"] as String;
            Object idValue    = html.ViewContext.RouteData.Values["id"];

            if (Authorization.Provider != null && !Authorization.Provider.IsAuthorizedFor(accountId, area, controller, action))
            {
                return(MvcHtmlString.Empty);
            }

            UrlHelper  urlHelper  = new UrlHelper(html.ViewContext.RequestContext);
            TagBuilder textSpan   = new TagBuilder("span");
            TagBuilder actionLink = new TagBuilder("a");
            TagBuilder icon       = new TagBuilder("i");

            textSpan.InnerHtml = ResourceProvider.GetActionTitle(action);
            actionLink.AddCssClass("btn");
            textSpan.AddCssClass("text");
            icon.AddCssClass(iconClass);

            actionLink.MergeAttribute("href", urlHelper.Action(action, new { id = idValue }).ToString());
            actionLink.InnerHtml = icon.ToString() + textSpan;

            return(new MvcHtmlString(actionLink.ToString()));
        }
Exemple #3
0
        public void LanguageLink_FormsLanguageLink()
        {
            RouteValueDictionary routeValues = html.ViewContext.RequestContext.RouteData.Values;
            String action = routeValues["action"].ToString();

            String actual   = html.LanguageLink().ToString();
            String expected = String.Format(
                "<a class=\"dropdown-toggle\" data-toggle=\"dropdown\">" +
                "<i class=\"fa fa-flag\"></i>{0}<span class=\"caret\"></span>" +
                "</a>" +
                "<ul class=\"dropdown-menu\" role=\"menu\">" +
                "<li>" +
                "<a href=\"{1}\"><img src=\"{3}\" alt=\"\" />English</a>" +
                "</li>" +
                "<li>" +
                "<a href=\"{2}\"><img src=\"{4}\" alt=\"\" />Lietuvių</a>" +
                "</li>" +
                "</ul>",
                ResourceProvider.GetActionTitle("Language"),
                urlHelper.Action(action, new { area = routeValues["area"], language = "en", p = "1" }),
                urlHelper.Action(action, new { area = routeValues["area"], language = "lt", p = "1" }),
                urlHelper.Content("~/Images/Flags/en.gif"),
                urlHelper.Content("~/Images/Flags/lt.gif"));

            Assert.AreEqual(expected, actual);
        }
Exemple #4
0
        public void ProfileLink_FormsProfileLink()
        {
            String actual   = html.ProfileLink().ToString();
            String expected = String.Format(
                "<a href=\"{0}\"><i class=\"fa fa-user\"></i><span>{1}</span></a>",
                urlHelper.Action("Edit", "Profile", new { area = String.Empty }),
                ResourceProvider.GetActionTitle("Profile"));

            Assert.AreEqual(expected, actual);
        }
Exemple #5
0
        public static MvcHtmlString ProfileLink(this HtmlHelper html)
        {
            TagBuilder span = new TagBuilder("span");
            TagBuilder icon = new TagBuilder("i");

            icon.AddCssClass("fa fa-user");

            span.InnerHtml = ResourceProvider.GetActionTitle("Profile");

            return(new MvcHtmlString(String.Format(html.ActionLink("{0}{1}", "Edit", "Profile", new { area = String.Empty }, null).ToString(), icon, span)));
        }
Exemple #6
0
        private static String FormTitleButtons(HtmlHelper html, IEnumerable <LinkAction> actions)
        {
            String controller = html.ViewContext.RouteData.Values["controller"] as String;
            String accountId  = html.ViewContext.HttpContext.User.Identity.Name;
            String area       = html.ViewContext.RouteData.Values["area"] as String;
            String buttons    = String.Empty;

            foreach (LinkAction action in actions)
            {
                if (Authorization.Provider != null && !Authorization.Provider.IsAuthorizedFor(accountId, area, controller, action.ToString()))
                {
                    continue;
                }

                TagBuilder icon = new TagBuilder("i");
                switch (action)
                {
                case LinkAction.Create:
                    icon.AddCssClass("fa fa-file-o");
                    break;

                case LinkAction.Details:
                    icon.AddCssClass("fa fa-info");
                    break;

                case LinkAction.Edit:
                    icon.AddCssClass("fa fa-pencil");
                    break;

                case LinkAction.Delete:
                    icon.AddCssClass("fa fa-times");
                    break;
                }

                TagBuilder span = new TagBuilder("span");
                span.InnerHtml = ResourceProvider.GetActionTitle(action.ToString());

                String button = String.Format(
                    html
                    .ActionLink(
                        "{0}{1}",
                        action.ToString(),
                        new { id = html.ViewContext.RouteData.Values["id"] },
                        new { @class = "btn" })
                    .ToString(),
                    icon,
                    span);

                buttons += button;
            }

            return(buttons);
        }
Exemple #7
0
        public static MvcHtmlString LogoutLink(this HtmlHelper html)
        {
            MvcHtmlString actionLink = html.ActionLink("{0}{1}", "Logout", "Auth", new { area = String.Empty }, null);
            TagBuilder    span       = new TagBuilder("span");
            TagBuilder    icon       = new TagBuilder("i");

            icon.AddCssClass("fa fa-share");

            span.InnerHtml = ResourceProvider.GetActionTitle("Logout");

            return(new MvcHtmlString(String.Format(actionLink.ToString(), icon, span)));
        }
Exemple #8
0
        public void LogoutLink_FormsLogoutLink()
        {
            String actual   = html.LogoutLink().ToString();
            String expected = String.Format(
                "<a href=\"{0}\">" +
                "<i class=\"fa fa-share\"></i>" +
                "<span>{1}</span>" +
                "</a>",
                urlHelper.Action("Logout", "Auth", new { area = String.Empty }),
                ResourceProvider.GetActionTitle("Logout"));

            Assert.AreEqual(expected, actual);
        }
Exemple #9
0
        public void WidgetButton_OnNullAuthorizationProviderFormsWidgetButton()
        {
            Authorization.Provider = null;

            String actual   = html.WidgetButton("Create", "icon").ToString();
            String expected = String.Format(
                "<a class=\"btn\" href=\"{0}\">" +
                "<i class=\"icon\"></i>" +
                "<span class=\"text\">{1}</span>" +
                "</a>",
                urlHelper.Action("Create"),
                ResourceProvider.GetActionTitle("Create"));

            Assert.AreEqual(expected, actual);
        }
Exemple #10
0
        public void WidgetButton_FormsAuthorizedWidgetButton()
        {
            Authorization.Provider = Substitute.For <IAuthorizationProvider>();
            Authorization.Provider.IsAuthorizedFor(accountId, area, controller, "Delete").Returns(true);

            String actual   = html.WidgetButton("Delete", "icon").ToString();
            String expected = String.Format(
                "<a class=\"btn\" href=\"{0}\">" +
                "<i class=\"icon\"></i>" +
                "<span class=\"text\">{1}</span>" +
                "</a>",
                urlHelper.Action("Delete"),
                ResourceProvider.GetActionTitle("Delete"));

            Assert.AreEqual(expected, actual);
        }
Exemple #11
0
        private String FormTitleButtons(params LinkAction[] actions)
        {
            String buttons = String.Empty;

            foreach (LinkAction action in actions)
            {
                TagBuilder icon = new TagBuilder("i");
                switch (action)
                {
                case LinkAction.Create:
                    icon.AddCssClass("fa fa-file-o");
                    break;

                case LinkAction.Details:
                    icon.AddCssClass("fa fa-info");
                    break;

                case LinkAction.Edit:
                    icon.AddCssClass("fa fa-pencil");
                    break;

                case LinkAction.Delete:
                    icon.AddCssClass("fa fa-times");
                    break;
                }

                TagBuilder span = new TagBuilder("span");
                span.InnerHtml = ResourceProvider.GetActionTitle(action.ToString());

                String button = String.Format(
                    html.ActionLink(
                        "{0}{1}",
                        action.ToString(),
                        new { id = html.ViewContext.RouteData.Values["id"] },
                        new { @class = "btn" })
                    .ToString(),
                    icon,
                    span);

                buttons += button;
            }

            return(buttons);
        }
Exemple #12
0
        public static MvcHtmlString LanguageLink(this HtmlHelper html)
        {
            if (GlobalizationManager.Provider.Languages.Count() < 2)
            {
                return(new MvcHtmlString(String.Empty));
            }

            TagBuilder dropdown = BootstrapExtensions.FormLanguagesDropdown(html);
            TagBuilder span     = new TagBuilder("span");
            TagBuilder action   = new TagBuilder("a");
            TagBuilder icon     = new TagBuilder("i");

            action.MergeAttribute("data-toggle", "dropdown");
            action.AddCssClass("dropdown-toggle");
            icon.AddCssClass("fa fa-flag");
            span.AddCssClass("caret");

            action.InnerHtml = String.Format("{0}{1}{2}", icon, ResourceProvider.GetActionTitle("Language"), span);

            return(new MvcHtmlString(String.Format("{0}{1}", action, dropdown)));
        }
 public void GetActionTitle_OnActionNotFoundReturnsNull()
 {
     Assert.IsNull(ResourceProvider.GetActionTitle(null));
 }