Example #1
0
        public void T05_ListXmlNodesTest()
        {
            var catalog1 = XmlSlurper.ParseText(getFile("BookCatalog.xml"));
            var catalog2 = XmlSlurper.ParseFile(getFileFullPath("BookCatalog.xml"));

            foreach (var catalog in new[] { catalog1, catalog2 })
            {
                var bookList = catalog.bookList;

                Assert.Equal(12, bookList.Count);

                var book1 = bookList[0];
                Assert.Equal("bk101", book1.id);
                Assert.Equal("Gambardella, Matthew", book1.author);
                Assert.Equal("XML Developer's Guide", book1.title);
                Assert.Equal("Computer", book1.genre);
                Assert.Equal("44.95", book1.price);

                var book4 = bookList[3];
                Assert.Equal("bk104", book4.id);
                Assert.Equal("Corets, Eva", book4.author);
                Assert.Equal("Oberon's Legacy", book4.title);
                Assert.Equal("Fantasy", book4.genre);
                Assert.Equal("5.95", book4.price);

                var book12 = bookList[11];
                Assert.Equal("bk112", book12.id);
                Assert.Equal("Galos, Mike", book12.author);
                Assert.Equal("Visual Studio 7: A Comprehensive Guide", book12.title);
                Assert.Equal("Computer", book12.genre);
                Assert.Equal("49.95", book12.price);
            }
        }
Example #2
0
        public void T11_ConversionExceptionTest()
        {
            var settings1 = XmlSlurper.ParseText(getFile("HardwareSettings.xml"));
            var settings2 = XmlSlurper.ParseFile(getFileFullPath("HardwareSettings.xml"));

            foreach (var settings in new[] { settings1, settings2 })
            {
                Assert.Throws <ValueConversionException>(() =>
                {
                    int t = settings.view.displayIcons;
                });
                Assert.Throws <ValueConversionException>(() =>
                {
                    decimal t = settings.view.displayIcons;
                });
                Assert.Throws <ValueConversionException>(() =>
                {
                    double t = settings.view.displayIcons;
                });
                Assert.Throws <ValueConversionException>(() =>
                {
                    bool t = settings.performance.additionalChecks.disk.minFreeSpace;
                });
            }
        }
Example #3
0
        public void T10_BoolIntDecimalDoubleTest()
        {
            var settings1 = XmlSlurper.ParseText(getFile("HardwareSettings.xml"));
            var settings2 = XmlSlurper.ParseFile(getFileFullPath("HardwareSettings.xml"));

            foreach (var settings in new[] { settings1, settings2 })
            {
                Assert.Equal <bool?>(true, settings.view.displayIcons);
                Assert.Equal <bool?>(false, settings.view.showFiles);
                Assert.Equal <int?>(2, settings.performance.additionalChecks.disk.minFreeSpace);
                Assert.Equal <double?>(5.5, settings.performance.additionalChecks.disk.warnFreeSpace);
                Assert.Equal <decimal?>(5.5m, settings.performance.additionalChecks.disk.warnFreeSpace);

                Assert.True(settings.view.displayIcons);
                Assert.False(settings.view.showFiles);
                Assert.Equal <int>(2, settings.performance.additionalChecks.disk.minFreeSpace);
                Assert.Equal <double>(5.5, settings.performance.additionalChecks.disk.warnFreeSpace);
                Assert.Equal <decimal>(5.5m, settings.performance.additionalChecks.disk.warnFreeSpace);

                // usage showcase
                if (!settings.view.displayIcons)
                {
                    Assert.True(false);
                }
                int?minFreeSpace = settings.performance.additionalChecks.disk.minFreeSpace;
                if (minFreeSpace != 2)
                {
                    Assert.True(false);
                }
            }
        }
Example #4
0
        public void T04_XmlMultipleLevelsNodesTest()
        {
            var settings1 = XmlSlurper.ParseText(getFile("HardwareSettings.xml"));
            var settings2 = XmlSlurper.ParseFile(getFileFullPath("HardwareSettings.xml"));

            foreach (var settings in new[] { settings1, settings2 })
            {
                Assert.Equal("true", settings.view.displayIcons);
                Assert.Equal("false", settings.performance.additionalChecks.disk.brandOptions.toshiba.useBetaFunc);
            }
        }
Example #5
0
        public void T02_SimpleXmlAttributesTest()
        {
            var book1 = XmlSlurper.ParseText(getFile("Book.xml"));
            var book2 = XmlSlurper.ParseFile(getFileFullPath("Book.xml"));

            foreach (var book in new[] { book1, book2 })
            {
                Assert.Equal("bk101", book.id);
                Assert.Equal("123456789", book.isbn);
            }
        }
Example #6
0
        public void T01_ObjectNotNullTest()
        {
            var city1 = XmlSlurper.ParseText(getFile("City.xml"));
            var city2 = XmlSlurper.ParseFile(getFileFullPath("City.xml"));

            foreach (var city in new[] { city1, city2 })
            {
                Assert.NotNull(city);
                Assert.NotNull(city.Name);
            }
        }
Example #7
0
        public void T03_SimpleXmlNodesTest()
        {
            var book1 = XmlSlurper.ParseText(getFile("Book.xml"));
            var book2 = XmlSlurper.ParseFile(getFileFullPath("Book.xml"));

            foreach (var book in new[] { book1, book2 })
            {
                Assert.Equal("Gambardella, Matthew", book.author);
                Assert.Equal("XML Developer's Guide", book.title);
                Assert.Equal("Computer", book.genre);
                Assert.Equal("44.95", book.price);
            }
        }
Example #8
0
        public void T07_BothPropertiesAndListRecursiveXmlTest()
        {
            var city1 = XmlSlurper.ParseText(getFile("CityInfo.xml"));
            var city2 = XmlSlurper.ParseFile(getFileFullPath("CityInfo.xml"));

            foreach (var city in new[] { city1, city2 })
            {
                Assert.True(city.Mayor == "Roni Mueller");
                Assert.True(city.CityHall == "Schulstrasse 12");
                Assert.True(city.Name == "Wilen bei Wollerau");
                Assert.True(city.Gemeinde == "Freienbach");

                Assert.Equal(3, city.StreetList.Count);

                Assert.Equal("8832", city.StreetList[2].PostCode);
                Assert.Equal(3, city.StreetList[2].HouseNumberList.Count);
            }
        }
Example #9
0
        public void T06_BothPropertiesAndListRootXmlTest()
        {
            var nutrition1 = XmlSlurper.ParseText(getFile("Nutrition.xml"));
            var nutrition2 = XmlSlurper.ParseFile(getFileFullPath("Nutrition.xml"));

            foreach (var nutrition in new[] { nutrition1, nutrition2 })
            {
                var foodList = nutrition.foodList;

                Assert.Equal(10, foodList.Count);

                var food1 = foodList[0];
                Assert.Equal("Avocado Dip", food1.name);
                Assert.Equal("Sunnydale", food1.mfr);
                Assert.Equal("11", food1.totalfat);

                Assert.Equal("1", food1.vitamins.a);
                Assert.Equal("0", food1.vitamins.c);
            }
        }
Example #10
0
        public void T12_CDataTest()
        {
            var cdata1 = XmlSlurper.ParseText(getFile("CData.xml"));
            var cdata2 = XmlSlurper.ParseFile(getFileFullPath("CData.xml"));

            foreach (var cdata in new[] { cdata1, cdata2 })
            {
                // test cdata for single nodes
                Assert.Equal("DOCUMENTO N. 1234-9876", cdata.Title);

                // test cdata for list nodes
                dynamic attr = cdata.AttributeList[0];
                Assert.Equal("document.id", attr.Name);
                Assert.Equal("<string>DOCUMENTO N. 1234-9876</string>", attr);

                attr = cdata.AttributeList[4];
                Assert.Equal("receipt.date", attr.Name);
                Assert.Equal("<string>2020-12-28</string>", attr);

                attr = cdata.AttributeList[5];
                Assert.Equal("fcurrency", attr.Name);
                Assert.Equal("EUR", attr);
            }
        }