private void AppendMenuItem(DropDownMenuRenderingContext renderingContext, StringBuilder stringBuilder, WebMenuItem menuItem, int menuItemIndex)
        {
            string href   = "null";
            string target = "null";

            bool isCommandEnabled = true;

            if (menuItem.Command != null)
            {
                bool isActive = menuItem.Command.Show == CommandShow.Always ||
                                renderingContext.Control.IsReadOnly && menuItem.Command.Show == CommandShow.ReadOnly ||
                                !renderingContext.Control.IsReadOnly && menuItem.Command.Show == CommandShow.EditMode;

                isCommandEnabled = isActive && menuItem.Command.Type != CommandType.None;
                if (isCommandEnabled)
                {
                    bool isPostBackCommand = menuItem.Command.Type == CommandType.Event ||
                                             menuItem.Command.Type == CommandType.WxeFunction;
                    if (isPostBackCommand)
                    {
                        // Clientside script creates an anchor with href="#" and onclick=function
                        string argument = menuItemIndex.ToString();
                        href = renderingContext.Control.Page.ClientScript.GetPostBackClientHyperlink(renderingContext.Control, argument);
                        href = ScriptUtility.EscapeClientScript(href);
                        href = "'" + href + "'";
                    }
                    else if (menuItem.Command.Type == CommandType.Href)
                    {
                        href   = menuItem.Command.HrefCommand.FormatHref(menuItemIndex.ToString(), menuItem.ItemID);
                        href   = "'" + renderingContext.Control.ResolveClientUrl(href) + "'";
                        target = "'" + menuItem.Command.HrefCommand.Target + "'";
                    }
                }
            }

            bool showIcon = menuItem.Style == WebMenuItemStyle.Icon || menuItem.Style == WebMenuItemStyle.IconAndText;
            bool showText = menuItem.Style == WebMenuItemStyle.Text || menuItem.Style == WebMenuItemStyle.IconAndText;

            string icon         = GetIconUrl(renderingContext, menuItem, showIcon);
            string disabledIcon = GetDisabledIconUrl(renderingContext, menuItem, showIcon);
            string text         = showText ? "'" + menuItem.Text + "'" : "null";

            bool isDisabled = !menuItem.EvaluateEnabled() || !isCommandEnabled;

            stringBuilder.AppendFormat(
                "\t\tnew DropDownMenu_ItemInfo ('{0}', '{1}', {2}, {3}, {4}, {5}, {6}, {7}, {8})",
                menuItemIndex,
                menuItem.Category,
                text,
                icon,
                disabledIcon,
                (int)menuItem.RequiredSelection,
                isDisabled ? "true" : "false",
                href,
                target);
        }
        public void EvaluateFalse_FromFalseAndWithCommandSetNull()
        {
            WebMenuItem menuItem = CreateWebMenuItemWithoutCommand();

            menuItem.IsDisabled = true;

            bool isEnabled = menuItem.EvaluateEnabled();

            Assert.That(isEnabled, Is.False);
        }
        public void EvaluateFalse_FromFalse()
        {
            WebMenuItem menuItem = CreateWebMenuItem();

            menuItem.IsDisabled = true;
            _mocks.ReplayAll();

            bool isEnabled = menuItem.EvaluateEnabled();

            _mocks.VerifyAll();
            Assert.That(isEnabled, Is.False);
        }
        public void EvaluateFalse_FromTrueAndWithAccessDenied()
        {
            WebMenuItem menuItem = CreateWebMenuItem();

            menuItem.IsDisabled = false;
            Expect.Call(_mockCommand.HasAccess(_mockSecurableObject)).Return(false);
            _mocks.ReplayAll();

            bool isEnabled = menuItem.EvaluateEnabled();

            _mocks.VerifyAll();
            Assert.That(isEnabled, Is.False);
        }
        public void EvaluateFalse_FromFalseAndWithMissingPermissionBehaviorSetToInvisible()
        {
            WebMenuItem menuItem = CreateWebMenuItem();

            menuItem.MissingPermissionBehavior = MissingPermissionBehavior.Invisible;
            menuItem.IsDisabled = true;
            Expect.Call(_mockCommand.HasAccess(_mockSecurableObject)).Repeat.Never();
            _mocks.ReplayAll();

            bool isEnabled = menuItem.EvaluateEnabled();

            _mocks.VerifyAll();
            Assert.That(isEnabled, Is.False);
        }
        private void AppendMenuItem(DropDownMenuRenderingContext renderingContext, StringBuilder stringBuilder, WebMenuItem menuItem, int menuItemIndex)
        {
            string href   = "null";
            string target = "null";

            bool isCommandEnabled = true;
            var  diagnosticMetadataTriggersNavigation = false;
            var  diagnosticMetadataTriggersPostBack   = false;

            if (menuItem.Command != null)
            {
                bool isActive = menuItem.Command.Show == CommandShow.Always ||
                                renderingContext.Control.IsReadOnly && menuItem.Command.Show == CommandShow.ReadOnly ||
                                !renderingContext.Control.IsReadOnly && menuItem.Command.Show == CommandShow.EditMode;

                isCommandEnabled = isActive && menuItem.Command.Type != CommandType.None;
                if (isCommandEnabled)
                {
                    bool isPostBackCommand = menuItem.Command.Type == CommandType.Event ||
                                             menuItem.Command.Type == CommandType.WxeFunction;
                    if (isPostBackCommand)
                    {
                        // Clientside script creates an anchor with href="#" and onclick=function
                        string argument = menuItemIndex.ToString();
                        href = renderingContext.Control.Page.ClientScript.GetPostBackClientHyperlink(renderingContext.Control, argument);
                        href = ScriptUtility.EscapeClientScript(href);
                        href = "'" + href + "'";

                        diagnosticMetadataTriggersPostBack = true;
                    }
                    else if (menuItem.Command.Type == CommandType.Href)
                    {
                        href   = menuItem.Command.HrefCommand.FormatHref(menuItemIndex.ToString(), menuItem.ItemID);
                        href   = "'" + renderingContext.Control.ResolveClientUrl(href) + "'";
                        target = "'" + menuItem.Command.HrefCommand.Target + "'";

                        diagnosticMetadataTriggersNavigation = true;
                    }
                }
            }

            bool showIcon = menuItem.Style == WebMenuItemStyle.Icon || menuItem.Style == WebMenuItemStyle.IconAndText;
            bool showText = menuItem.Style == WebMenuItemStyle.Text || menuItem.Style == WebMenuItemStyle.IconAndText;

            string icon                   = GetIconUrl(renderingContext, menuItem, showIcon);
            string disabledIcon           = GetDisabledIconUrl(renderingContext, menuItem, showIcon);
            string text                   = showText ? "'" + menuItem.Text + "'" : "null";
            string diagnosticMetadataText = showText ? menuItem.Text : "";

            var diagnosticMetadataJson = "null";

            if (IsDiagnosticMetadataRenderingEnabled)
            {
                var htmlID = renderingContext.Control.ClientID + "_" + menuItemIndex;
                // Note: the output of diagnosticMetadataText is enclosed by single quotes, as it may contain double quotes.
                diagnosticMetadataJson = string.Format(
                    "{{\"{0}\":\"{1}\", \"{2}\":\"{3}\", \"{4}\":\"{5}\", \"{6}\":\"{7}\", \"{8}\":'{9}'}}",
                    HtmlTextWriterAttribute.Id,
                    htmlID,
                    DiagnosticMetadataAttributes.TriggersNavigation,
                    diagnosticMetadataTriggersNavigation.ToString().ToLower(),
                    DiagnosticMetadataAttributes.TriggersPostBack,
                    diagnosticMetadataTriggersPostBack.ToString().ToLower(),
                    DiagnosticMetadataAttributes.ItemID,
                    menuItem.ItemID,
                    DiagnosticMetadataAttributes.Content,
                    HtmlUtility.StripHtmlTags(diagnosticMetadataText ?? ""));
            }

            bool isDisabled = !menuItem.EvaluateEnabled() || !isCommandEnabled;

            stringBuilder.AppendFormat(
                "\t\tnew DropDownMenu_ItemInfo ('{0}', '{1}', {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9})",
                menuItemIndex,
                menuItem.Category,
                text,
                icon,
                disabledIcon,
                (int)menuItem.RequiredSelection,
                isDisabled ? "true" : "false",
                href,
                target,
                diagnosticMetadataJson);
        }