示例#1
0
        public void TestShopDeliveryOptions()
        {
            var shop = new shop("BestShop", "Best online seller Inc.", "http://best.seller.ru/", new currency[0], new category[0],
                                new[]
            {
                new delivery_option(300, 1),
                new delivery_option(0, 5, 7, 14),
            },
                                new offer[0]);

            var xShop = new YmlSerializer().ToXDocument(shop).Root;

            xShop.Should().NotBeNull();

            xShop.Should().HaveElement("delivery-options").Which.Should().HaveElement("option");
            var deliveryOptions = xShop.Element("delivery-options").Elements("option").ToList();

            deliveryOptions.Count().Should().Be(2);

            foreach (var deliveryOption in deliveryOptions)
            {
                deliveryOption.Attribute("cost").Should().NotBeNull();
            }

            deliveryOptions.SingleOrDefault(x => x.Attribute("cost").Value == 300.ToString()).Should().NotBeNull();
            deliveryOptions.SingleOrDefault(x => x.Attribute("cost").Value == 0.ToString()).Should().NotBeNull();
        }
示例#2
0
        public void TestShopCategories()
        {
            var shop = new shop("BestShop", "Best online seller Inc.", "http://best.seller.ru/", new currency[0],
                                new[]
            {
                new category(1, "Книги"),
                new category(2, "Детективы", 1),
            },
                                new delivery_option[0], new offer[0]);

            var xShop = new YmlSerializer().ToXDocument(shop).Root;

            xShop.Should().NotBeNull();

            xShop.Should().HaveElement("categories").Which.Should().HaveElement("category");
            // ReSharper disable once PossibleNullReferenceException
            var categories = xShop.Element("categories").Elements("category").ToList();

            categories.Count().Should().Be(2);

            foreach (var category in categories)
            {
                category.Attribute("id").Should().NotBeNull();
            }

            categories.SingleOrDefault(x => x.Attribute("id").Value == 1.ToString()).Should().NotBeNull();
            categories.SingleOrDefault(x => x.Attribute("id").Value == 2.ToString()).Should().NotBeNull();
        }
示例#3
0
        public void TestShopCurrencies()
        {
            var shop = new shop("BestShop", "Best online seller Inc.", "http://best.seller.ru/",
                                new[]
            {
                new currency(CurrencyEnum.RUR, 1),
                new currency(CurrencyEnum.EUR, RateEnum.CBRF),
            },
                                new category[0], new delivery_option[0], new offer[0]);

            var xShop = new YmlSerializer().ToXDocument(shop).Root;

            xShop.Should().NotBeNull();

            xShop.Should().HaveElement("currencies").Which.Should().HaveElement("currency");

            // ReSharper disable once PossibleNullReferenceException
            var currencies = xShop.Element("currencies").Elements("currency").ToList();

            currencies.Count().Should().Be(2);

            foreach (var currency in currencies)
            {
                currency.Attribute("id").Should().NotBeNull();
            }

            currencies.SingleOrDefault(x => x.Attribute("id").Value == CurrencyEnum.RUR.ToString()).Should().NotBeNull();
            currencies.SingleOrDefault(x => x.Attribute("id").Value == CurrencyEnum.EUR.ToString()).Should().NotBeNull();
        }
示例#4
0
        public void YmlSerializer_FromXmlString_Test()
        {
            var xmlStringStandart = ReadXmlFromAssembly();

            var ymlCatalog = new YmlSerializer().FromXmlString <yml_catalog>(xmlStringStandart);

            ymlCatalog.ShouldBeEquivalentTo(_ymlCatalog);
        }
示例#5
0
        public void Age_GivenUnit_HaveValuesInXml()
        {
            var age = new age(AgeUnit.month);

            var xAge = new YmlSerializer().ToXDocument(age).Root;

            xAge.Should().NotBeNull();
            xAge.Should().HaveAttribute("unit", AgeUnit.month.ToString());
        }
        public void Currency_GivenValuesWithEnumRateAndConvertedToXDocument_PersistsValues()
        {
            var currency = new currency(CurrencyEnum.EUR, RateEnum.CBRF);

            var xCurrency = new YmlSerializer().ToXDocument(currency).Root;

            xCurrency.Should().NotBeNull();
            xCurrency.Should().HaveAttribute("id", CurrencyEnum.EUR.ToString());
            xCurrency.Should().HaveAttribute("rate", RateEnum.CBRF.ToString());
        }
示例#7
0
        public void Age_GivenYearUnitAndValidValue_HaveValuesInXml()
        {
            var age = new age(AgeUnit.year, 12);

            var xAge = new YmlSerializer().ToXDocument(age).Root;

            xAge.Should().NotBeNull();
            xAge.Should().HaveAttribute("unit", AgeUnit.year.ToString());
            xAge.Should().HaveValue(12.ToString());
        }
        public void DeliveryOption_GivenCostAndDays_HaveValuesInXml()
        {
            var deliveryOption = new delivery_option(300, 1);

            var xDeliveryOption = new YmlSerializer().ToXDocument(deliveryOption).Root;

            xDeliveryOption.Should().NotBeNull();
            xDeliveryOption.Should().HaveAttribute("cost", "300");
            xDeliveryOption.Should().HaveAttribute("days", "1");
        }
        public void Param_GivenNameAndValue_HaveValuesInXml()
        {
            var param = new param("Тип", "моноблок");

            var xParam = new YmlSerializer().ToXDocument(param).Root;

            xParam.Should().NotBeNull();
            xParam.Should().HaveAttribute("name", "Тип");
            xParam.Should().HaveValue("моноблок");
        }
示例#10
0
        public void Category_GivenAttributesAndConvertedToXDocument_PersistValues()
        {
            var category = new category(1, "Книги");

            var xCategory = new YmlSerializer().ToXDocument(category).Root;

            xCategory.Should().NotBeNull();
            xCategory.Should().HaveAttribute("id", "1");
            xCategory.Should().HaveValue("Книги");
        }
        public void Param_GivenNameValueAndUnit_HaveValuesInXml()
        {
            var param = new param("Размер экрана", 27.ToString(), "дюйм");

            var xParam = new YmlSerializer().ToXDocument(param).Root;

            xParam.Should().NotBeNull();
            xParam.Should().HaveAttribute("name", "Размер экрана");
            xParam.Should().HaveAttribute("unit", "дюйм");
            xParam.Should().HaveValue(27.ToString());
        }
示例#12
0
        public void Category_GivenAttributesWithParentCategoryAndConvertedToXDocument_PersistValues()
        {
            var category = new category(2, "Детективы", 1);

            var xCategory = new YmlSerializer().ToXDocument(category).Root;

            xCategory.Should().NotBeNull();
            xCategory.Should().HaveAttribute("id", "2");
            xCategory.Should().HaveAttribute("parentId", "1");
            xCategory.Should().HaveValue("Детективы");
        }
        public void DeliveryOption_GivenCostAndDaysPeriodAndOrderBefore_HaveValuesInXml()
        {
            var deliveryOption = new delivery_option(cost: 0, workDaysFrom: 5, workDaysTo: 7, orderBefore: 14);

            var xDeliveryOption = new YmlSerializer().ToXDocument(deliveryOption).Root;

            xDeliveryOption.Should().NotBeNull();
            xDeliveryOption.Should().HaveAttribute("cost", "0");
            xDeliveryOption.Should().HaveAttribute("days", "5-7");
            xDeliveryOption.Should().HaveAttribute("order-before", "14");
        }
示例#14
0
        public void YmlSerializer_ToXmlString_Test()
        {
            var xmlStringFromObject = new YmlSerializer().ToXmlString(_ymlCatalog);

            xmlStringFromObject.Should().NotBeNullOrWhiteSpace();

            var xmlStringStandart = ReadXmlFromAssembly();

            xmlStringStandart.Should().NotBeNullOrWhiteSpace();

            xmlStringFromObject.ShouldBeEquivalentTo(xmlStringStandart);
        }
示例#15
0
        public void OfferSimple_GivenRequiredParameters_ShouldHaveRightProperties()
        {
            var offer = new offer(id: "12346", price: 600, currencyId: CurrencyEnum.EUR, categoryId: 1, name: "Наручные часы Casio A1234567B");

            var xOffer = new YmlSerializer().ToXDocument(offer).Root;

            xOffer.Should().NotBeNull();
            xOffer.Should().HaveAttribute("id", "12346");
            xOffer.Should().HaveElement("price").Which.Should().HaveValue("600");
            xOffer.Should().HaveElement("currencyId").Which.Should().HaveValue(CurrencyEnum.EUR.ToString());
            xOffer.Should().HaveElement("categoryId").Which.Should().HaveValue(1.ToString());
            xOffer.Should().HaveElement("name").Which.Should().HaveValue("Наручные часы Casio A1234567B");
        }
示例#16
0
        public void OfferSimple_GivenBarcodes_ShouldHaveRightBarcodes()
        {
            var offer = new offer(id: "12346", price: 600, currencyId: CurrencyEnum.EUR, categoryId: 1, name: "Наручные часы Casio A1234567B")
            {
                barcode = new[] { "423424", "43423423", "5353523" },
            };

            var xOffer = new YmlSerializer().ToXDocument(offer).Root;

            xOffer.Should().HaveElement("barcode");
            // ReSharper disable once PossibleNullReferenceException
            xOffer.Descendants("barcode").Count().Should().Be(3);
        }
示例#17
0
        public void OfferVendor_GivenRequiredParameters_ShouldHaveRightProperties()
        {
            var offer = new offer(id: "12341", price: 16800, currencyId: CurrencyEnum.RUR, categoryId: 2, typePrefix: "Принтер", vendor: "HP", model: "Deskjet D2663");

            var xOffer = new YmlSerializer().ToXDocument(offer).Root;

            xOffer.Should().NotBeNull();
            xOffer.Should().HaveAttribute("id", "12341");
            xOffer.Should().HaveAttribute("type", "vendor.model");
            xOffer.Should().HaveElement("price").Which.Should().HaveValue("16800");
            xOffer.Should().HaveElement("currencyId").Which.Should().HaveValue(CurrencyEnum.RUR.ToString());
            xOffer.Should().HaveElement("categoryId").Which.Should().HaveValue(2.ToString());
            xOffer.Should().HaveElement("typePrefix").Which.Should().HaveValue("Принтер");
            xOffer.Should().HaveElement("vendor").Which.Should().HaveValue("HP");
            xOffer.Should().HaveElement("model").Which.Should().HaveValue("Deskjet D2663");
        }
        public void TestYmlCatalog()
        {
            var ymlCatalog = new yml_catalog(
                new DateTime(2010, 04, 01, 17, 05, 00),
                new shop("BestShop",
                         "Best online seller Inc.",
                         "http://best.seller.ru/",
                         new currency[0],
                         new category[0],
                         new delivery_option[0],
                         new offer[0]));

            var serializer = new YmlSerializer();

            var xYmlCatalog = serializer.ToXDocument(ymlCatalog);

            xYmlCatalog.Should().NotBeNull();

            xYmlCatalog.Should().HaveRoot("yml_catalog");
            xYmlCatalog.Root.Should().HaveAttribute("date", "2010-04-01 17:05");
            xYmlCatalog.Root.Should().HaveElement("shop");
        }
示例#19
0
        public void TestShopOffers()
        {
            var shop = new shop("BestShop", "Best online seller Inc.", "http://best.seller.ru/", new currency[0], new category[0], new delivery_option[0],
                                new[]
            {
                new offer(id: "12346", price: 600, currencyId: CurrencyEnum.EUR, categoryId: 1, name: "Наручные часы Casio A1234567B"),
                new offer(id: "12341", price: 16800, currencyId: CurrencyEnum.RUR, categoryId: 2, typePrefix: "Принтер", vendor: "HP", model: "Deskjet D2663"),
            });

            var xShop = new YmlSerializer().ToXDocument(shop).Root;

            xShop.Should().HaveElement("offers").Which.Should().HaveElement("offer");
            var offers = xShop.Element("offers").Elements("offer").ToList();

            offers.Count().Should().Be(2);
            foreach (var offer in offers)
            {
                Assert.NotNull(offer.Attribute("id"), "offer.Attribute('id') != null");
            }

            offers.SingleOrDefault(x => x.Attribute("id").Value == 12346.ToString()).Should().NotBeNull();
            offers.SingleOrDefault(x => x.Attribute("id").Value == 12341.ToString()).Should().NotBeNull();
        }
示例#20
0
        public void TestShopSimpleAttributes()
        {
            var shop = new shop("BestShop",
                                "Best online seller Inc.",
                                "http://best.seller.ru/",
                                new currency[0],
                                new category[0],
                                new delivery_option[0],
                                new offer[0])
            {
                platform = "CMS",
                version  = "2.3",
                agency   = "Agency",
                email    = "*****@*****.**",
                cpa      = "0",
            };

            var xShop = new YmlSerializer().ToXDocument(shop).Root;

            xShop.Should().NotBeNull();

            xShop.Should().HaveElement("name").Which.Should().HaveValue("BestShop");
            xShop.Should().HaveElement("company").Which.Should().HaveValue("Best online seller Inc.");
            xShop.Should().HaveElement("url").Which.Should().HaveValue("http://best.seller.ru/");

            xShop.Should().HaveElement("platform").Which.Should().HaveValue("CMS");
            xShop.Should().HaveElement("version").Which.Should().HaveValue("2.3");
            xShop.Should().HaveElement("agency").Which.Should().HaveValue("Agency");
            xShop.Should().HaveElement("email").Which.Should().HaveValue("*****@*****.**");
            xShop.Should().HaveElement("cpa").Which.Should().HaveValue("0");

            xShop.Should().HaveElement("currencies");
            xShop.Should().HaveElement("categories");
            xShop.Should().HaveElement("delivery-options");
            xShop.Should().HaveElement("offers");
        }