Ejemplo n.º 1
0
 public void CanAddAttributeWithFormat()
 {
     Element div = new Element("div");
     div.AddAttribute("id", "name_{0}", "chris");
     Assert.AreEqual("<div id=\"name_chris\"></div>", div.ToString());
     Assert.IsTrue(div.HasAttribute("id"));
 }
Ejemplo n.º 2
0
 public void NullElementsAreNotAddedToList()
 {
     Element nullel = null;
     Element el = new Element("b").Update("Anja");
     ElementList list = new ElementList(nullel, el);
     Assert.AreEqual(1, list.Count);
     Assert.AreEqual("<b>Anja</b>", list.ToString());
 }
Ejemplo n.º 3
0
 public void XmlWriterWrapperCanBeUsedInUsingWithTextWriter()
 {
     var el = new Element("img", "src=myimage.gif");
     var expected = "<img src=\"myimage.gif\" />";
     var actual = String.Empty;
     using (var textWriter = new StringWriter())
     using (var xml = new XmlWriterWrapper(textWriter))
     {
         el.Render(xml);
         actual = textWriter.ToString();
     }
     Assert.AreEqual(expected, actual);
 }
Ejemplo n.º 4
0
        public void can_get_key_values()
        {
            var contentsOfConfigFile = new Element("hyperactive",
                new Element("config",
                    new Element("add", "key=abstractbasename;value=LarsBase"),
                    new Element("add", @"key=outputpath;value=Data\Generated")));

            var configParser = new DefaultConfigParser();
            var configs = configParser.ParseXml(contentsOfConfigFile);
            Assert.AreEqual(1, configs.Count());
            var options = configs.ElementAt(0);
            Assert.AreEqual("LarsBase", options.AbstractBaseName);
            Assert.AreEqual(@"Data\Generated", options.OutputPath);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates the appropriate li and anchor tags for use inside of the skeleton tabs.
        /// </summary>
        /// <param name="this">Instance of HtmlHelper being extended.</param>
        /// <param name="tabText">The text displayed on the tab.</param>
        /// <param name="activeControllerName">Name of the active controller.  This is used to determine which anchor tag in
        /// the tabs gets the 'active' css class.</param>
        /// <returns></returns>
        public static MvcHtmlString Tab(this HtmlHelper @this, string tabText, string activeControllerName)
        {
            var text = String.IsNullOrEmpty(tabText) ? "My Tasks" : tabText;
            var controllerName = String.IsNullOrEmpty(activeControllerName) ? "Tasks" : activeControllerName;

            var url = new UrlHelper(@this.ViewContext.RequestContext);
            var link = new Element("a").AddAttribute("href", url.Action("Index", controllerName)).Update(tabText);

            var currentController = @this.ViewContext.RequestContext.RouteData.Values["controller"].ToString();
            if (controllerName.Equals(currentController, StringComparison.OrdinalIgnoreCase))
                link.CssClasses.Add("active");

            return MvcHtmlString.Create(new Element("li", link));
        }
Ejemplo n.º 6
0
        public void can_get_enums()
        {
            var contentsOfConfigFile = new Element("hyperactive",
                new Element("config",
                    new Element("enums",
                        new Element("add", "table=TransactionLineType;nameField=Label;valueField=ID;"))));

            var configParser = new DefaultConfigParser();
            var options = configParser.ParseXml(contentsOfConfigFile).ElementAt(0);
            Assert.AreEqual(1, options.Enums.Count());
            var @enum = options.Enums.ElementAt(0);
            Assert.AreEqual("TransactionLineType", @enum.TableName);
            Assert.AreEqual("Label", @enum.NameField);
            Assert.AreEqual("ID", @enum.ValueField);
        }
Ejemplo n.º 7
0
 public void CanCreateHtmlSelectWithOptions()
 {
     string expected =
         "<select id=\"select1\" name=\"select1\">" +
         "<option value=\"1\">Chris</option>" +
         "<option value=\"2\">Anja</option>" +
         "<option value=\"3\">Riley</option>" +
         "<option value=\"4\">Emmitt</option>" +
         "</select>";
     string actual = new Element("select", "id=select1;name=select1;")
         .Append(new Element("option", "value=1").Update("Chris"))
         .Append(new Element("option", "value=2").Update("Anja"))
         .Append(new Element("option", "value=3").Update("Riley"))
         .Append(new Element("option", "value=4").Update("Emmitt"))
         .ToString();
     Assert.AreEqual(expected, actual);
 }
Ejemplo n.º 8
0
        public void can_get_components()
        {
            var contentsOfConfigFile = new Element("hyperactive",
                new Element("config",
                    new Element("components",
                        new Element("component", "service=TheService;serviceimpl=TheImpl;",
                            new Element("param", "name=myParam;type=string;value=$IRock;")))));

            var configParser = new DefaultConfigParser();
            var options = configParser.ParseXml(contentsOfConfigFile).ElementAt(0);
            Assert.AreEqual(1, options.Components.Count());
            var comp = options.Components.ElementAt(0);
            Assert.AreEqual("TheService", comp.ServiceTypeName);
            Assert.AreEqual("TheImpl", comp.ServiceImplementationTypeName);
            Assert.AreEqual(1, comp.Parameters.Count);
            var p = comp.Parameters.ElementAt(0);
            Assert.AreEqual("myParam", p.Name);
            Assert.AreEqual("string", p.Type);
            Assert.AreEqual("$IRock", p.Value);
        }
Ejemplo n.º 9
0
 public void VerifyToString()
 {
     string expected = @"<span>Hello World</span>";
     string actual = new Element("span").Update("Hello World").ToString();
     Assert.AreEqual(expected, actual);
 }
Ejemplo n.º 10
0
 public void VerifyTagName()
 {
     Element para = new Element("p");
     Assert.AreEqual("p", para.TagName);
     Assert.AreEqual("<p></p>", para.ToString());
 }
Ejemplo n.º 11
0
 public void VerifyNullElementsAreSkippedDuringInsert()
 {
     Element nullelement = null;
     Element select = new Element("select");
     select.Insert(new Element("option").Update("Item 1"), nullelement);
     Assert.AreEqual(1, select.Children.Count);
     Assert.AreEqual("<select><option>Item 1</option></select>", select.ToString());
 }
Ejemplo n.º 12
0
 public void VerifyInsertDefaultsToIndexZero()
 {
     Element select = new Element("select");
     select.Insert(new Element("option").Update("Item 1"));
     select.Insert(new Element("option").Update("Item 2"));
     Assert.AreEqual("<select><option>Item 2</option><option>Item 1</option></select>", select.ToString());
 }
Ejemplo n.º 13
0
 public void VerifyInsert()
 {
     Element table = new Element("table");
     Element thead = new Element("thead");
     Element tr = new Element("tr");
     for (int i = 0; i < 3; i++)
     {
         tr.Insert(new Element("th").Update("Blah"));
     }
     table.Append(thead.Append(tr));
     string actual = table.ToString();
     string expected = "<table><thead><tr><th>Blah</th><th>Blah</th><th>Blah</th></tr></thead></table>";
     Assert.AreEqual(expected, actual);
 }
Ejemplo n.º 14
0
 public void VerifyCanInsertByIndex()
 {
     Element select = new Element("select")
         .Append(new Element("option", "value=0").Update("Create New"))
         .Insert(0, new Element("option", "value=").Update(":: Select ::"));
     string expected = "<select><option value=\"\">:: Select ::</option><option value=\"0\">Create New</option></select>";
     Assert.AreEqual(expected, select.ToString());
     Assert.AreEqual("<option value=\"\">:: Select ::</option>", select.Children[0].ToString());
 }
Ejemplo n.º 15
0
 public void CanReturnStringImplicitlyFromElement()
 {
     string expected = "<p></p>";
     string actual = new Element("p");
     Assert.AreEqual(expected, actual);
 }
Ejemplo n.º 16
0
 public void NullOrEmptyChildElementsAsArgsToAppendMethodAreNotAppended()
 {
     Element body = new Element("body");
     Element[] nullarray = null;
     Assert.AreEqual("<body></body>", body.Append(nullarray).ToString());
     Assert.AreEqual(0, body.Children.Count);
     Element[] emptyarray = new Element[0] { };
     Assert.AreEqual(0, body.Children.Count);
 }
Ejemplo n.º 17
0
 public void NullElementsAreNotAppendedAndDoNotThrowExceptions()
 {
     Element body = new Element("body");
     Element iamnull = null;
     Element form = new Element("form");
     body.Append(iamnull, form);
     Assert.AreEqual(1, body.Children.Count);
     Assert.AreEqual("<body><form></form></body>", body.ToString());
 }
Ejemplo n.º 18
0
 private void MixWithStrings()
 {
     string s = new Element("b").Update("hello") + "<i>bye bye</i>";
     Console.WriteLine(s);
 }
Ejemplo n.º 19
0
 public void CanRemoveAttributes()
 {
     Element table = new Element("table", "border=0;width=100%;");
     table.RemoveAttribute("border");
     string expected = "<table width=\"100%\"></table>";
     string actual = table;
     Assert.AreEqual(expected, actual);
 }
Ejemplo n.º 20
0
        public void NullChildElementsAreIgnoredDuringRendering()
        {
            Element iAmNull = null;

            Element myelement = new Element("p");
            myelement.Children.Add(iAmNull);
            Assert.AreEqual("<p></p>", myelement.ToString());
        }
Ejemplo n.º 21
0
 public void IndexerTests()
 {
     Element span = new Element("p");
     span["id"] = "blah";
     Assert.AreEqual("blah", span["id"], "can get an attribute previously set");
     span["id"] = "poop";
     Assert.AreEqual("poop", span["id"], "you can update attribute values without creating duplicates");
     Assert.AreEqual(null, span["nonexistent"], "non existent attributes return a null value");
     Assert.AreEqual(null, span[null], "null attributename returns null value");
     Assert.AreEqual(null, span[String.Empty], "empty attributename returns null value");
 }
Ejemplo n.º 22
0
 public void CanUpdateContentsOfElementsWithInnerHtml()
 {
     Element div = new Element("div");
     div.InnerHtml = "chris";
     Assert.AreEqual("<div>chris</div>", div.ToString());
     div.InnerHtml = "anja";
     Assert.AreEqual("<div>anja</div>", div.ToString());
 }
Ejemplo n.º 23
0
 public void StylesAreLastAttributeValueWins()
 {
     string expected = "<span style=\"width:100px;\"></span>";
     string actual = new Element("span").AddAttribute("style=width:50px;").AddAttribute("style=width:100px;");
     Assert.AreEqual(expected, actual);
     Assert.AreEqual("<span width=\"100px\"></span>", new Element("span", "width=100px;").ToString());
 }
Ejemplo n.º 24
0
 public void NullChildElementsDuringInsertReturnsTheInstanceUnchanged()
 {
     Element[] nullElements = null;
     Assert.AreEqual("<select></select>", new Element("select").Insert(nullElements).ToString());
     Element nullElement = null;
     nullElements = new Element[] { nullElement };
     Assert.AreEqual("<select></select>", new Element("select").Insert(nullElements).ToString());
 }
Ejemplo n.º 25
0
 public void CanRenderToStream()
 {
     string expected = "<p>Hello World</p>";
     byte[] buffer = new byte[expected.Length];
     using (MemoryStream stream = new MemoryStream(buffer))
     {
         Element para = new Element("p").Update("Hello World");
         para.Render(stream);
         string actual = System.Text.ASCIIEncoding.ASCII.GetString(buffer);
         Assert.AreEqual(expected, actual);
     }
 }
Ejemplo n.º 26
0
 public void NullChildElementsSkippedInCtor()
 {
     Element nullElement = null;
     Element select = new Element("select", nullElement, new Element("option").Update("chris"));
     Assert.AreEqual("<select><option>chris</option></select>", select.ToString());
 }
Ejemplo n.º 27
0
 private void HelloWorld()
 {
     Element element = new Element("p").Update("Hello World");
     Console.WriteLine(element.ToString());
 }