Esempio n. 1
0
        public void ElementComposition()
        {
            var sb       = new StringBuilder();
            var elements = new DialogElement();

            elements.Add(new DialogButton("Foobar1"));
            elements.Render(ref sb);
            Assert.Equal("<button title='Foobar1' keyword='@foobar1' />", sb.ToString());
            sb.Clear();

            elements.Add(new DialogButton("Foobar2"));
            elements.Render(ref sb);
            Assert.Equal("<button title='Foobar1' keyword='@foobar1' /><button title='Foobar2' keyword='@foobar2' />", sb.ToString());
            sb.Clear();

            elements.Insert(1, new DialogButton("Foobar3"));
            elements.Render(ref sb);
            Assert.Equal("<button title='Foobar1' keyword='@foobar1' /><button title='Foobar3' keyword='@foobar3' /><button title='Foobar2' keyword='@foobar2' />", sb.ToString());
            sb.Clear();

            elements.Replace(0, new DialogButton("Foobar4"));
            elements.Render(ref sb);
            Assert.Equal("<button title='Foobar4' keyword='@foobar4' /><button title='Foobar3' keyword='@foobar3' /><button title='Foobar2' keyword='@foobar2' />", sb.ToString());
            sb.Clear();

            elements.Insert(0, new DialogButton("Foobar5"));
            elements.Render(ref sb);
            Assert.Equal("<button title='Foobar5' keyword='@foobar5' /><button title='Foobar4' keyword='@foobar4' /><button title='Foobar3' keyword='@foobar3' /><button title='Foobar2' keyword='@foobar2' />", sb.ToString());
            sb.Clear();

            elements.Insert(99, new DialogButton("Foobar6"));
            elements.Render(ref sb);
            Assert.Equal("<button title='Foobar5' keyword='@foobar5' /><button title='Foobar4' keyword='@foobar4' /><button title='Foobar3' keyword='@foobar3' /><button title='Foobar2' keyword='@foobar2' /><button title='Foobar6' keyword='@foobar6' />", sb.ToString());
            sb.Clear();

            elements = new DialogElement();

            elements.Insert(1, new DialogButton("Foobar7"));
            elements.Render(ref sb);
            Assert.Equal("<button title='Foobar7' keyword='@foobar7' />", sb.ToString());
            sb.Clear();

            elements = new DialogElement();

            elements.Replace(0, new DialogButton("Foobar8"));
            elements.Render(ref sb);
            Assert.Equal("<button title='Foobar8' keyword='@foobar8' />", sb.ToString());
            sb.Clear();

            elements = new DialogElement("foobar, <username/>!", new DialogButton("Foobar9"), new DialogButton("Foobar10"));

            elements.Render(ref sb);
            Assert.Equal("foobar, <username/>!<button title='Foobar9' keyword='@foobar9' /><button title='Foobar10' keyword='@foobar10' />", sb.ToString());
            sb.Clear();

            elements.Replace(0, "barfoo?");
            elements.Insert(1, new DialogButton("Foobar11"));
            elements.Render(ref sb);
            Assert.Equal("barfoo?<button title='Foobar11' keyword='@foobar11' /><button title='Foobar9' keyword='@foobar9' /><button title='Foobar10' keyword='@foobar10' />", sb.ToString());
            sb.Clear();
        }