Exemple #1
0
        public void ViewState_LoadSaveTrack_ReturnsTheSetValue()
        {
            // Arrange:
            //Create the control, start tracking viewstate, then set a new Text value.
            var toolDropDownList = new ToolDropDownList();

            toolDropDownList.EnableSsl = true;
            var privateObject = new PrivateObject(toolDropDownList);

            privateObject.Invoke("TrackViewState");
            toolDropDownList.EnableSsl = false;

            //Save the control's state
            var viewState = privateObject.Invoke("SaveViewState");

            //Create a new control instance and load the state
            //back into it, overriding any existing values
            var dropDownList = new ToolDropDownList();

            toolDropDownList.EnableSsl = true;

            var dropdownPrivateObject = new PrivateObject(dropDownList);

            // Act:
            dropdownPrivateObject.Invoke("LoadViewState", viewState);

            // Assert:
            dropDownList.EnableSsl.
            ShouldBeFalse("Value restored from viewstate does not match the original value we set");
        }
Exemple #2
0
 public void SetUp()
 {
     _shimObject                 = ShimsContext.Create();
     _toolDropDownList           = new ToolDropDownList();
     _privateObject              = new PrivateObject(_toolDropDownList);
     stubToolbar                 = new StubToolbar();
     stubToolbar.ParentGet       = () => null;
     stubToolbar.ImagesDirectory = DummyText;
 }
Exemple #3
0
 public void DataTextOnlyField_DefaultValue_ReturnsEmptyString()
 {
     // Arrange
     using (var testObject = new ToolDropDownList())
     {
         // Act, Assert
         testObject.DataTextOnlyField.ShouldBeEmpty();
     }
 }
Exemple #4
0
        public void Text_SetAndGetValue_ReturnsDefaultValue()
        {
            // Arrange:
            var toolDropDownList = new ToolDropDownList();

            toolDropDownList.ID = DummyId;

            // Act: // Assert:
            toolDropDownList.Text.ShouldBe(DummyId);
        }
Exemple #5
0
        public void BorderWidth_SetAndGetValue_ReturnsTheSetValue()
        {
            // Arrange:
            var toolDropDownList = new ToolDropDownList();

            // Act:
            toolDropDownList.BorderWidth = Unit.Pixel(1);

            // Assert:
            toolDropDownList.BorderWidth.ShouldBe(Unit.Pixel(1));
        }
Exemple #6
0
        public void BorderColorRollOver_SetAndGetValue_ReturnsTheSetValue()
        {
            // Arrange:
            var toolDropDownList = new ToolDropDownList();

            // Act:
            toolDropDownList.BorderColorRollOver = Color.Black;

            // Assert:
            toolDropDownList.BorderColorRollOver.ShouldBe(Color.Black);
        }
Exemple #7
0
        public void ItemAlign_SetAndGetValue_ReturnsTheSetValue()
        {
            // Arrange:
            var toolDropDownList = new ToolDropDownList();

            // Act:
            toolDropDownList.ItemAlign = Align.Center;

            // Assert:
            toolDropDownList.ItemAlign.ShouldBe(Align.Center);
        }
Exemple #8
0
        public void AutoPostBack_SetAndGetValue_ReturnsTheSetValue()
        {
            // Arrange:
            var toolDropDownList = new ToolDropDownList();

            // Act:
            toolDropDownList.AutoPostBack = true;

            // Assert:
            toolDropDownList.AutoPostBack.ShouldBeTrue();
        }
Exemple #9
0
        public void DropDownImage_SetAndGetValue_ReturnsTheSetValue()
        {
            // Arrange:
            var toolDropDownList = new ToolDropDownList();

            // Act:
            toolDropDownList.DropDownImage = DummyDropDownImage;

            // Assert:
            toolDropDownList.DropDownImage.ShouldBe(DummyDropDownImage);
        }
Exemple #10
0
        public void BackColorItems_SetAndGetValue_ReturnsTheSetValue()
        {
            // Arrange:
            var toolDropDownList = new ToolDropDownList();

            // Act:
            toolDropDownList.BackColorItems = Color.Black;

            // Assert:
            toolDropDownList.BackColorItems.ShouldBe(Color.Black);
        }
Exemple #11
0
        public void BorderStyle_SetAndGetValue_ReturnsTheSetValue()
        {
            // Arrange:
            var toolDropDownList = new ToolDropDownList();

            // Act:
            toolDropDownList.BorderStyle = BorderStyle.Solid;

            // Assert:
            toolDropDownList.BorderStyle.ShouldBe(BorderStyle.Solid);
        }
Exemple #12
0
        public void CellSpacing_SetAndGetValue_ReturnsTheSetValue()
        {
            // Arrange:
            var toolDropDownList = new ToolDropDownList();

            // Act:
            toolDropDownList.Cellspacing = Unit.Pixel(1);

            // Assert:
            toolDropDownList.Cellspacing.ShouldBe(Unit.Pixel(1));
        }
Exemple #13
0
        public void Text_SetAndGetValue_ReturnsTheSetValue()
        {
            // Arrange:
            var toolDropDownList = new ToolDropDownList();

            // Act:
            toolDropDownList.Text = DummyText;

            // Assert:
            toolDropDownList.Text.ShouldBe(DummyText);
        }
Exemple #14
0
        public void DataTextOnlyField_SetValue_ReturnsSetValue()
        {
            // Arrange
            using (var testObject = new ToolDropDownList())
            {
                // Act
                testObject.DataTextOnlyField = DummyDropDownImage;

                // Assert
                testObject.DataTextOnlyField.ShouldBe(DummyDropDownImage);
            }
        }
Exemple #15
0
        public void IndentText_SetAndGetValue_ReturnsTheSetValue()
        {
            // Arrange:
            var toolDropDownList = new ToolDropDownList();
            var privateObject    = new PrivateObject(toolDropDownList);

            // Act:
            privateObject.SetFieldOrProperty("IndentText", DummyIndentText);

            // Assert:
            var propertyValue = privateObject.GetFieldOrProperty("IndentText") as string;

            propertyValue.ShouldBe(DummyIndentText);
        }
Exemple #16
0
        public void ChangeToSelectedText_SetAndGetValue_ReturnsTheSetValue()
        {
            // Arrange:
            var toolDropDownList = new ToolDropDownList();
            var privateObject    = new PrivateObject(toolDropDownList);

            // Act:
            privateObject.SetFieldOrProperty("ChangeToSelectedText", SelectedText.Text);

            // Assert:
            var propertyValue = (SelectedText)privateObject.GetFieldOrProperty("ChangeToSelectedText");

            propertyValue.ShouldBe(SelectedText.Text);
        }
Exemple #17
0
        public void ClearSelection_SetItemSelectedTrue_ItemSelectedFalse()
        {
            // Arrange
            var toolDropDownList = new ToolDropDownList();
            var toolItem         = new ToolItem
            {
                Selected = true
            };

            toolDropDownList.Items.Add(toolItem);

            // Act
            toolDropDownList.ClearSelection();

            // Assert
            toolItem.Selected.ShouldBeFalse();
        }
Exemple #18
0
        public void RegisterActiveToolBarScript_ClientScriptInclude_ScriptIncluded()
        {
            // Arrange
            var toolDropDownList = new ToolDropDownList
            {
                Page = new Page()
            };

            using (ShimsContext.Create())
            {
                ShimClientScriptManager.AllInstances.GetWebResourceUrlTypeString = (type, obj1, obj2) => DummyUrl;

                // Act
                toolDropDownList.Page.RegisterActiveToolBarScript(DummyClientSideScript, ActiveToolbarScriptKey);

                // Assert
                toolDropDownList.Page.IsClientScriptBlockRegistered(ActiveToolbarScriptKey).ShouldBeTrue();
            }
        }
Exemple #19
0
        public void DesignDropDownList_ForSelectedIndexValue_WriteOutput()
        {
            // Arrange
            SetUp(indexValue);
            var textWriter = new Moq.Mock <TextWriter>();

            using (var toolDropDownList = new ToolDropDownList())
            {
                var htmlTextWriter = new HtmlTextWriter(textWriter.Object);

                // Act
                ToolDropDownListDesigner.DesignDropDownList(ref htmlTextWriter, toolDropDownList);

                // Assert
                htmlTextWriter.ShouldSatisfyAllConditions(
                    () => htmlTextWriter.Indent.ShouldBe(indentValue),
                    () => htmlTextWriter.NewLine.ShouldBeNull());
            }
        }
Exemple #20
0
        /// <summary>
        /// Gets the HTML that is used to represent the control at design time.
        /// </summary>
        /// <returns>The HTML that is used to represent the control at design time.</returns>
        public override string GetDesignTimeHtml()
        {
            try
            {
                ToolDropDownList ddl = (ToolDropDownList)base.Component;

                StringWriter   stringWriter = new StringWriter();
                HtmlTextWriter writer       = new HtmlTextWriter(stringWriter);

                DesignDropDownList(ref writer, ddl);

                /*StreamWriter sw = new StreamWriter(@"c:\temp\render.txt", false);
                 * sw.Write(stringWriter.ToString());
                 * sw.Close();*/

                return(stringWriter.ToString());
            }

            catch (Exception e)
            {
                return(this.GetErrorDesignTimeHtml(e));
            }
        }
Exemple #21
0
        /// <summary>
        /// Create a DropDownList object at design time.
        /// </summary>
        /// <param name="output">Output stream that contains the HTML used to represent the control.</param>
        /// <param name="ddl"><see cref="DropDownList"/> object to design.</param>
        ///
        public static void DesignDropDownList(ref HtmlTextWriter output, ToolDropDownList ddl)
        {
            IEnumerator enumerator = ddl.Style.Keys.GetEnumerator();

            while (enumerator.MoveNext())
            {
                output.AddStyleAttribute((string)enumerator.Current, ddl.Style[(string)enumerator.Current]);
            }
            ddl.ControlStyle.AddAttributesToRender(output);

            string backImage = string.Empty;

            if (ddl.BackImage != string.Empty)
            {
                if (ddl.Parent != null && ddl.Parent is ActiveUp.WebControls.Toolbar)
                {
                    backImage = "url(" + Utils.ConvertToImageDir(((Toolbar)ddl.Parent).ImagesDirectory, ddl.BackImage) + ")";
                }
                else
                {
                    backImage = "url(" + ddl.BackImage + ")";
                }
            }

            string style = "style=\"";

            if (ddl.BackColor != Color.Empty)
            {
                style += string.Format("background-color:{0};", Utils.Color2Hex(ddl.BackColor));
            }
            if (ddl.BorderColor != Color.Empty)
            {
                style += string.Format("border-color:{0};", Utils.Color2Hex(ddl.BorderColor));
            }
            style += string.Format("border-style:{0};", ddl.BorderStyle.ToString());
            if (ddl.BorderWidth != Unit.Empty)
            {
                style += string.Format("border-width:{0};", ddl.BorderWidth);
            }
            if (backImage != string.Empty)
            {
                style += string.Format("background-image:{0};", backImage);
            }
            style += "\"";

            string table = string.Empty;

            table += "<table";
            if (ddl.Width != Unit.Empty)
            {
                table += string.Format(" width={0}", ddl.Width.ToString());
            }
            if (ddl.Height != Unit.Empty)
            {
                table += string.Format(" height={0}", ddl.Height.ToString());
            }
            table += " cellpadding=0 cellspacing=0";
            table += string.Format(" {0}", style);
            table += ">";
            output.Write(table);

            output.RenderBeginTag(HtmlTextWriterTag.Tr);
            output.Write("\n");

            if (ddl.Width.IsEmpty == true)
            {
                output.AddAttribute(HtmlTextWriterAttribute.Width, "100%");
            }
            else
            {
                output.AddAttribute(HtmlTextWriterAttribute.Width, ddl.Width.Value.ToString());
            }
            output.RenderBeginTag(HtmlTextWriterTag.Td);
            output.AddAttribute(HtmlTextWriterAttribute.Width, "100%");
            output.AddAttribute(HtmlTextWriterAttribute.Height, "100%");
            output.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0");
            output.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0");
            output.AddAttribute(HtmlTextWriterAttribute.Border, "0");
            output.RenderBeginTag(HtmlTextWriterTag.Table);

            output.RenderBeginTag(HtmlTextWriterTag.Tr);
            output.AddAttribute(HtmlTextWriterAttribute.Width, "100%");
            output.AddStyleAttribute("padding", "0px 0px 0px 4px");
            output.AddAttribute(HtmlTextWriterAttribute.Nowrap, null);
            if (ddl.ForeColor != Color.Empty)
            {
                output.AddStyleAttribute(HtmlTextWriterStyle.Color, Utils.Color2Hex(ddl.ForeColor));
            }
            Utils.AddStyleFontAttribute(output, ddl.Font);
            output.RenderBeginTag(HtmlTextWriterTag.Td);

            string text = string.Empty;

            if (ddl.SelectedIndex == -1)
            {
                text = ddl.Text.TrimEnd();
            }
            else if (ddl.ChangeToSelectedText == SelectedText.Text)
            {
                text = ddl.Items[ddl.SelectedIndex].Text;
            }
            else if (ddl.ChangeToSelectedText == SelectedText.Value)
            {
                text = ddl.Items[ddl.SelectedIndex].Value;
            }

            if (text.IndexOf("$IMAGESDIRECTORY$") >= 0)
            {
                string imagesDirectory = string.Empty;
                if (ddl.Parent != null && ddl.Parent is ActiveUp.WebControls.Toolbar)
                {
                    imagesDirectory = Utils.GetCorrectImageDir(((Toolbar)ddl.Parent).ImagesDirectory);
                }

                text = text.Replace("$IMAGESDIRECTORY$", imagesDirectory);
            }
            //text = ddl.Text;
            output.Write(text);

            output.RenderEndTag();
            output.AddAttribute(HtmlTextWriterAttribute.Height, "100%");
            output.RenderBeginTag(HtmlTextWriterTag.Td);

            // drop down image
            output.AddAttribute(HtmlTextWriterAttribute.Width, "100%");
            output.AddAttribute(HtmlTextWriterAttribute.Height, "100%");

            // Added by PMENGAL
            output.AddAttribute(HtmlTextWriterAttribute.Width, "100%");
            output.AddAttribute(HtmlTextWriterAttribute.Height, "100%");
            output.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0");
            output.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0");
            output.RenderBeginTag(HtmlTextWriterTag.Table);
            output.RenderBeginTag(HtmlTextWriterTag.Tr);
            output.AddAttribute(HtmlTextWriterAttribute.Height, "100%");
            output.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0");
            output.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0");
            output.RenderBeginTag(HtmlTextWriterTag.Td);
            output.AddAttribute(HtmlTextWriterAttribute.Border, "0");
            if (ddl.DropDownImage != string.Empty)
            {
                if (ddl.Parent != null && ddl.Parent is ActiveUp.WebControls.Toolbar)
                {
                    output.AddAttribute(HtmlTextWriterAttribute.Src, Utils.ConvertToImageDir(((Toolbar)ddl.Parent).ImagesDirectory, ddl.DropDownImage, "down.gif", ddl.Page, ddl.GetType()));
                }
                else
                {
                    output.AddAttribute(HtmlTextWriterAttribute.Src, ddl.DropDownImage);
                }
            }
            else
            {
                if (ddl.Parent != null && ddl.Parent is ActiveUp.WebControls.Toolbar)
                {
#if (FX1_1)
                    ddl.DropDownImage = "down.gif";
#endif
                    output.AddAttribute(HtmlTextWriterAttribute.Src, Utils.ConvertToImageDir(((Toolbar)ddl.Parent).ImagesDirectory, ddl.DropDownImage, "down.gif", ddl.Page, ddl.GetType()));
                }
                else
                {
                    output.AddAttribute(HtmlTextWriterAttribute.Src, "down.gif");
                }
            }

            output.RenderBeginTag(HtmlTextWriterTag.Img);
            output.RenderEndTag();

            output.RenderEndTag();
            output.RenderEndTag();
            output.RenderEndTag();
            output.RenderEndTag();
            output.RenderEndTag();
            output.RenderEndTag();
            output.RenderEndTag();
            output.RenderEndTag();

            output.Write("</table>");
        }