Beispiel #1
0
        public void FilterScreen()
        {
            // Creamos un level y screen.
            String screenName = "screen1";
            String levelName  = "level1";

            World world = Singleton <World> .Instance;
            Level level = new Level(levelName, world);

            world.Add(level);

            Dictionary <string, Attribute> attributeList = new Dictionary <string, Attribute>();

            Attribute attributeName  = new Attribute("Name", screenName);
            Attribute attributeLevel = new Attribute("Level", levelName);

            attributeList.Add(attributeName.Key, attributeName);
            attributeList.Add(attributeLevel.Key, attributeLevel);

            // Visitamos el mundo con la tag de Screen, este agrega la screen al ultimo level del world.
            Tag tag = new Tag("Screen", attributeList);

            VisitorScreen visitor = new VisitorScreen(tag);

            visitor.Visit(world);

            Screen expectedScreen = new Screen(screenName, world.ListLevel[1]);

            Assert.Equal(world.ListLevel[1].ScreenList.Count, 1);
            Assert.True(world.ListLevel[1].ScreenList[0] is Screen);
            Assert.Equal(world.ListLevel[1].ScreenList[0].Name, screenName);
        }
Beispiel #2
0
        public void FilterElement()
        {
            IPipe pipeNull = new PipeNull();

            //Creamos una tag de Image
            Dictionary <string, Attribute> attributeList = new Dictionary <string, Attribute>();
            Attribute attribute  = new Attribute("Name", "image1");
            Attribute attribute2 = new Attribute("PositionY", "100");
            Attribute attribute3 = new Attribute("PositionX", "100");
            Attribute attribute4 = new Attribute("Length", "100");
            Attribute attribute5 = new Attribute("Width", "100");
            Attribute attribute6 = new Attribute("ImagePath", "Oceano.jpg");

            attributeList.Add(attribute.Key, attribute);
            attributeList.Add(attribute2.Key, attribute2);
            attributeList.Add(attribute3.Key, attribute3);
            attributeList.Add(attribute4.Key, attribute4);
            attributeList.Add(attribute5.Key, attribute5);
            attributeList.Add(attribute6.Key, attribute6);
            Tag tag = new Tag("Image", attributeList);

            //Creamos un filterImage
            IFilterConditional filterImage = new FilterImage();
            IPipe pipe0 = new PipeConditional(filterImage, pipeNull, pipeNull);

            //Testeamos que el resultado de la pipe sea el correcto.
            Assert.True(pipe0.Send(tag) is VisitorImage);
        }
Beispiel #3
0
        public void PositiveTest()
        {
            //Finder.Find:
            //Input = string -> html
            //Output = List<Tag> tags

            string input = @"<html>
	                            <body>
		                            <font color=""blue"" size=""3"">
			                            Ingrese su nombre 
		                            </font>
		                            <input type=""text"" name=""nombre"" maxlength=""8""/>
		                            <br/>
		                            <font size=""2"">
			                            Máximo 8caracteres
		                            </font>
	                            </body>
                            </html>";

            List <Tag> expectedTags = new List <Tag>();

            expectedTags.Add(new Tag("html"));
            expectedTags.Add(new Tag("body"));

            Dictionary <string, Attribute> fontAttributes1 = new Dictionary <string, Attribute>();
            Attribute attribute1 = new Attribute("color", "blue");
            Attribute attribute2 = new Attribute("size", "3");

            fontAttributes1.Add(attribute1.Key, attribute1);
            fontAttributes1.Add(attribute2.Key, attribute2);
            expectedTags.Add(new Tag("font", fontAttributes1));

            Dictionary <string, Attribute> inputAttributes = new Dictionary <string, Attribute>();
            Attribute attribute3 = new Attribute("type", "text");
            Attribute attribute4 = new Attribute("name", "nombre");
            Attribute attribute5 = new Attribute("maxlength", "8");

            inputAttributes.Add(attribute3.Key, attribute3);
            inputAttributes.Add(attribute4.Key, attribute4);
            inputAttributes.Add(attribute5.Key, attribute5);
            expectedTags.Add(new Tag("input", inputAttributes));

            expectedTags.Add(new Tag("br"));

            Dictionary <string, Attribute> fontAttributes2 = new Dictionary <string, Attribute>();
            Attribute attribute6 = new Attribute("size", "2");

            fontAttributes2.Add(attribute6.Key, attribute6);
            expectedTags.Add(new Tag("font", fontAttributes2));
            FinderTests.ComparatorMethod(input, expectedTags);
        }
Beispiel #4
0
        public void FilterElement()
        {
            // Creamos un elemento, screen y elemento.
            String screenName = "screen1";
            String levelName  = "level1";

            World  world  = Singleton <World> .Instance;
            Level  level  = new Level(levelName, world);
            Screen screen = new Screen(screenName, level);

            world.Add(level);
            level.Add(screen);

            Dictionary <string, Attribute> attributeList = new Dictionary <string, Attribute>();

            string name      = "image1";
            string length    = "100";
            string width     = "100";
            string positionY = "100";
            string positionX = "100";
            string imagePath = "Oceano.jpg";

            Attribute attributeName      = new Attribute("Name", name);
            Attribute attributeScreen    = new Attribute("Screen", screenName);
            Attribute attributeLenght    = new Attribute("Length", length);
            Attribute attributeWidth     = new Attribute("Width", width);
            Attribute attributePositionY = new Attribute("PositionY", positionY);
            Attribute attributePositionX = new Attribute("PositionX", positionX);
            Attribute attributeImagePath = new Attribute("ImagePath", imagePath);

            attributeList.Add(attributeName.Key, attributeName);
            attributeList.Add(attributeScreen.Key, attributeScreen);
            attributeList.Add(attributeLenght.Key, attributeLenght);
            attributeList.Add(attributeWidth.Key, attributeWidth);
            attributeList.Add(attributePositionY.Key, attributePositionY);
            attributeList.Add(attributePositionX.Key, attributePositionX);
            attributeList.Add(attributeImagePath.Key, attributeImagePath);

            // Visitamos el mundo con la tag de Image, este agrega la image a la ultima screen del world.
            Tag tag = new Tag("Image", attributeList);

            VisitorImage visitor = new VisitorImage(tag);

            visitor.Visit(world);

            Image expectedImage = new Image(name, Int32.Parse(positionY), Int32.Parse(positionX), Int32.Parse(length), Int32.Parse(width), screen, imagePath);

            Assert.True(world.ListLevel[2].ScreenList[0].ElementList[0] is Image);
            Assert.Equal(world.ListLevel[2].ScreenList[0].ElementList[0].Name, name);
        }
Beispiel #5
0
        public void TagWithName_And_ListAttributes()
        {
            Dictionary <string, Attribute> attributeList = new Dictionary <string, Attribute>();
            Attribute attribute  = new Attribute("pedro", "15");
            Attribute attribute2 = new Attribute("marcos", "13");

            attributeList.Add(attribute.Key, attribute);
            attributeList.Add(attribute2.Key, attribute2);
            Tag    tag          = new Tag("personas", attributeList);
            string nameExpected = "personas";
            Dictionary <string, Attribute> ListaAtributosExpected = attributeList;

            Assert.Equal(nameExpected, tag.Name);
            Assert.Equal(ListaAtributosExpected, tag.AttributeList);
        }
Beispiel #6
0
        public void FilterScreen()
        {
            IPipe pipeNull = new PipeNull();

            //Creamos una tag de Screen falsa
            Dictionary <string, Attribute> attributeList = new Dictionary <string, Attribute>();
            Attribute attribute = new Attribute("Name", "screen1");

            attributeList.Add(attribute.Key, attribute);
            Tag tag = new Tag("Screen", attributeList);

            //Creamos un filterScreen
            IFilterConditional filterScreen = new FilterScreen();
            IPipe pipe0 = new PipeConditional(filterScreen, pipeNull, pipeNull);

            //Nos fijamos que devuelva el Visitor correcto
            Assert.True(pipe0.Send(tag) is VisitorScreen);
        }
Beispiel #7
0
        public void FilterLevelTest()
        {
            IPipe pipeNull = new PipeNull();

            //Creamos una tag falsa de Level
            Dictionary <string, Attribute> attributeList = new Dictionary <string, Attribute>();
            Attribute attribute = new Attribute("Name", "level1");

            attributeList.Add(attribute.Key, attribute);
            Tag tag = new Tag("Level", attributeList);

            //Creamos un filter Level
            IFilterConditional filterLevel = new FilterLevel();
            IPipe pipe0 = new PipeConditional(filterLevel, pipeNull, pipeNull);

            //Nos fijamos que el resultado de la pipe sea un VisitorLevel
            Assert.True(pipe0.Send(tag) is VisitorLevel);
        }
Beispiel #8
0
        // metodo utilizado por todos los tests, compara los elementos de la List<> expectedTags con los elementos
        // de la lista que resulta de aplicar el metodo Finder
        public static void ComparatorMethod(string input, List <Tag> expectedTags)
        {
            Finder     finder     = new Finder();
            List <Tag> resultTags = finder.Find(input);

            Assert.Equal(expectedTags.Count, resultTags.Count);

            if (expectedTags.Count == resultTags.Count)
            {
                for (int i = 0; i < resultTags.Count; i++)
                {
                    Assert.Equal(resultTags[i].Name, expectedTags[i].Name);

                    if (resultTags[i].AttributeList != null & expectedTags[i].AttributeList != null)
                    {
                        Assert.Equal(resultTags[i].AttributeList.Count, expectedTags[i].AttributeList.Count);

                        if (resultTags[i].AttributeList.Count > 0 & expectedTags[i].AttributeList.Count > 0 &
                            resultTags[i].AttributeList.Count == expectedTags[i].AttributeList.Count)
                        {
                            foreach (KeyValuePair <string, Attribute> entry in resultTags[i].AttributeList)
                            {
                                //entry.key
                                //resultTags[i].AttributeList[entry.key]
                                bool encontro;
                                try
                                {
                                    Attribute attribute = expectedTags[i].AttributeList[entry.Key];
                                    encontro = true;
                                }
                                catch (System.Exception)
                                {
                                    encontro = false;
                                }
                                Assert.True(encontro);
                            }
                        }
                    }
                }
            }
        }
Beispiel #9
0
        public void FilterLevelTest()
        {
            // Creamos tag de Level.
            World world = Singleton <World> .Instance;
            Dictionary <string, Attribute> attributeList = new Dictionary <string, Attribute>();
            String    levelName = "level1";
            Attribute attribute = new Attribute("Name", levelName);

            attributeList.Add(attribute.Key, attribute);
            Tag tag = new Tag("Level", attributeList);

            // Visitamos el mundo con la tag de level, este agrega el level al world.
            VisitorLevel visitor = new VisitorLevel(tag);

            visitor.Visit(world);

            Level expectedLevel = new Level(levelName, world);

            Assert.Equal(world.ListLevel.Count, 1);
            Assert.True(world.ListLevel[0] is Level);
            Assert.Equal(world.ListLevel[0].Name, levelName);
        }
Beispiel #10
0
        public void ListFormatedCorrectly()
        {
            Formater format = new Formater();
            Dictionary <string, Attribute> attributeList = new Dictionary <string, Attribute>();
            Attribute  attribute  = new Attribute("pedro", "15");
            Attribute  attribute2 = new Attribute("marcos", "13");
            List <Tag> ListaTags  = new List <Tag>();

            attributeList.Add(attribute.Key, attribute);
            attributeList.Add(attribute2.Key, attribute2);
            ListaTags.Add(new Tag("personas", attributeList));
            List <string> listaFormated = format.Format(ListaTags);
            List <string> ListaExpected = new List <string> {
                "personas", "pedro=15", "marcos=13"
            };

            for (int i = 0; i < ListaExpected.Count; i++)
            {
                string elemento         = listaFormated[i];
                string elementoExpected = ListaExpected[i];
                Assert.Equal(elemento, elementoExpected);
            }
        }