public void ShouldSerializeProduct() { var marketplace = new Marketplace { Product = new List <CdonMarketplace.Availability.Product> { new CdonMarketplace.Availability.Product { Status = Status.Offline, Id = "your_sku", Stock = 0, Se = new MarketSE { DeliveryTime = new DeliveryTime { Min = 2, Max = 3, }, Status = Status.Offline, } } } }; var xml = XmlUtils.SerializeXml(marketplace); var expected = $"<?xml version=\"1.0\" encoding=\"utf-8\"?><marketplace xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"https://schemas.cdon.com/product/4.0/{ApiVersion.Product()}/availability\"><product><id>your_sku</id><status>Offline</status><stock>0</stock><se><status>Offline</status><deliveryTime><min>2</min><max>3</max></deliveryTime></se></product></marketplace>"; Assert.Equal(expected, xml); }
public void ShouldUseCdata() { var marketplace = new Marketplace { Product = new List <CdonMarketplace.Product.Product> { new CdonMarketplace.Product.Product { Title = new Title { Default = "I am a title" }, Description = new Description { Default = "<strong>I contain HTML</strong>" } } } }; var xml = XmlUtils.SerializeXml(marketplace); var expected = $"<?xml version=\"1.0\" encoding=\"utf-8\"?><marketplace xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"https://schemas.cdon.com/product/4.0/{ApiVersion.Product()}/product\"><product><title><default>I am a title</default></title><description><default><![CDATA[<strong>I contain HTML</strong>]]></default></description></product></marketplace>"; Assert.Equal(expected, xml); }
public void ShouldUseLists() { var marketplace = new Marketplace { Product = new List <CdonMarketplace.Product.Product> { new CdonMarketplace.Product.Product { Category = new Category() { Attributes = new Attributes { Any = new[] { CreateAttribute("name", "value") }.ToList() } } } } }; var xml = XmlUtils.SerializeXml(marketplace); var expected = $"<?xml version=\"1.0\" encoding=\"utf-8\"?><marketplace xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"https://schemas.cdon.com/product/4.0/{ApiVersion.Product()}/product\"><product><category><attributes><name>value</name></attributes></category></product></marketplace>"; Assert.Equal(expected, xml); }
public void ShouldSerializeProduct() { var marketplace = new Marketplace { Product = new List <CdonMarketplace.Price.Product> { new CdonMarketplace.Price.Product { Id = "your_sku", Se = new MarketSE { OriginalPrice = 1337, SalePrice = 999, IsShippedFromEU = true, ShippingCost = MarketSEShippingCost.Item0, Vat = 25, }, Dk = new MarketDK { OriginalPrice = 1337, SalePrice = 999, ShippingCost = MarketDKShippingCost.Item0, Vat = 25, } } } }; var xml = XmlUtils.SerializeXml(marketplace); var expected = $"<?xml version=\"1.0\" encoding=\"utf-8\"?><marketplace xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"https://schemas.cdon.com/product/4.0/{ApiVersion.Product()}/price\"><product><id>your_sku</id><se><salePrice>999</salePrice><originalPrice>1337</originalPrice><isShippedFromEU>true</isShippedFromEU><shippingCost>0</shippingCost><vat>25</vat></se><dk><salePrice>999</salePrice><originalPrice>1337</originalPrice><shippingCost>0</shippingCost><vat>25</vat></dk></product></marketplace>"; Assert.Equal(expected, xml); }
public void ShouldHandleNullAndEmpty() { var empty = new Marketplace { Product = new List <CdonMarketplace.Media.Product>() { new CdonMarketplace.Media.Product { Id = "your_id", Images = new Images { Main = "url_to_main_image", } } } }; var nullSet = new Marketplace { Product = new List <CdonMarketplace.Media.Product>() { new CdonMarketplace.Media.Product { Id = "your_id", Images = new Images { Main = "url_to_main_image", Extra = null, } } } }; var emptyXml = XmlUtils.SerializeXml(empty); var nullXml = XmlUtils.SerializeXml(nullSet); var expected = $"<?xml version=\"1.0\" encoding=\"utf-8\"?><marketplace xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"https://schemas.cdon.com/product/4.0/{ApiVersion.Product()}/media\"><product><id>your_id</id><images><main>url_to_main_image</main></images></product></marketplace>"; Assert.Equal(expected, emptyXml); Assert.Equal(expected, nullXml); }
public void ShouldSerializeProduct() { var marketplace = new Marketplace { Product = new List <CdonMarketplace.Media.Product>() { new CdonMarketplace.Media.Product { Id = "your_id", Images = new Images { Main = "url_to_main_image", Extra = new List <string> { "url_to_extra_image1", "url_to_extra_image2", } } } } }; var xml = XmlUtils.SerializeXml(marketplace); string expected = $"<?xml version=\"1.0\" encoding=\"utf-8\"?><marketplace xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"https://schemas.cdon.com/product/4.0/{ApiVersion.Product()}/media\"><product><id>your_id</id><images><main>url_to_main_image</main><extra>url_to_extra_image1</extra><extra>url_to_extra_image2</extra></images></product></marketplace>"; Assert.Equal(expected, xml); }
public void ShouldNotUseNamespacesOnElements() { var marketplace = new Marketplace { Product = new List <CdonMarketplace.Product.Product> { new CdonMarketplace.Product.Product { Identity = new Identity { Id = "Test" } } } }; var xml = XmlUtils.SerializeXml(marketplace); var expected = $"<?xml version=\"1.0\" encoding=\"utf-8\"?><marketplace xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"https://schemas.cdon.com/product/4.0/{ApiVersion.Product()}/product\"><product><identity><id>Test</id></identity></product></marketplace>"; Assert.Equal(expected, xml); }