public void DateTimeFormattingWithCulture() { Customer customer = Repository.SampleCustomer; Collapse collapse = new Collapse() .SetDateTimeFormat(CultureInfo.CurrentCulture); XDocument doc = collapse.ExportToXml(customer, Res.FileContent("FormattingDates")); List<XElement> orders = doc.Root.Elements("order").ToList(); List<XElement> valOrders = doc.Root.Elements("valOrder").ToList(); for (int i = 0; i < orders.Count; i++) { XElement orderElement = orders[i]; XElement valOrderElement = valOrders[i]; Order order = customer.Orders[i]; String expectedDateTimeString = order.Timestamp.ToString(CultureInfo.CurrentCulture); Assert.AreEqual(expectedDateTimeString, orderElement.Value); Assert.AreEqual(expectedDateTimeString, orderElement.Attribute("time").Value); Assert.AreEqual(expectedDateTimeString, valOrderElement.Value.Trim()); } }
public void FilterAttribute() { Collapse collapse = new Collapse() .SetFilter("isValidName", args => args[0].Value<Customer>().Name.Contains("Mark")); XDocument doc = collapse.ExportToXml( new Repository(), Res.FileContent("FilterAttribute")); List<XElement> elements = doc.Root.Elements("customer").ToList(); Assert.AreEqual(1, elements[0].Attributes("name").Count()); Assert.AreEqual(0, elements[1].Attributes("name").Count()); }
public void InitializationWithValidXmlDisableInlineTextTransform() { Collapse collapse = new Collapse(transformInlineText: false); Assert.IsFalse(collapse.IsInlineTextTransformEnabled); XDocument doc = collapse.ExportToXml( new Repository(), Res.FileContent("ValidInlineText")); List<XElement> customers = doc.Root.Elements("customer").ToList(); foreach (XElement item in customers) Assert.AreEqual("(cx|c.Name)", item.Value); }
public void NumberFormattingWithFormatProvider() { NumberFormatInfo nfi = new NumberFormatInfo() { NumberDecimalSeparator = "@" }; Repository rep = new Repository(); Collapse collapse = new Collapse() .SetNumberFormat(nfi); XDocument doc = collapse.ExportToXml(rep, Res.FileContent("FormattingNumbers")); List<XElement> customerElements = doc.Root.Elements("customer").ToList(); List<XElement> valCustomers = doc.Root.Elements("valCustomer").ToList(); for (int i = 0; i < customerElements.Count; i++) { XElement customerElement = customerElements[i]; XElement valCustomerElement = customerElements[i]; Customer customer = rep.Customers[i]; String expectedNumberString = customer.Coefficient.ToString(nfi); Assert.AreEqual(expectedNumberString, customerElement.Value); Assert.AreEqual(expectedNumberString, customerElement.Attribute("coefficient").Value); Assert.AreEqual(expectedNumberString, valCustomerElement.Value.Trim()); } }
public void NumberFormattingWithCulture() { Repository rep = new Repository(); Collapse collapse = new Collapse(); XDocument doc = collapse.ExportToXml(rep, Res.FileContent("FormattingNumbers")); List<XElement> customerElements = doc.Root.Elements("customer").ToList(); List<XElement> valCustomers = doc.Root.Elements("valCustomer").ToList(); for (int i = 0; i < customerElements.Count; i++) { XElement customerElement = customerElements[i]; XElement valCustomerElement = customerElements[i]; Customer customer = rep.Customers[i]; String expectedNumberString = customer.Coefficient.ToString(CultureInfo.CurrentCulture); Assert.AreEqual(expectedNumberString, customerElement.Value); Assert.AreEqual(expectedNumberString, customerElement.Attribute("coefficient").Value); Assert.AreEqual(expectedNumberString, valCustomerElement.Value.Trim()); } }
public void ValidFilterMissingFilterBehaviorSomeFound() { Collapse collapse = new Collapse(MissingFilterBehavior.OmitItem) .SetFilter("hasCustomers", args => args[0].Value<List<Customer>>().Any()); XDocument doc = collapse.ExportToXml( new Repository(), Res.FileContent("ValidXmlWithFilter")); Assert.AreEqual(1, doc.Root.Elements("description").Count()); Assert.AreEqual(0, doc.Root.Elements("customer").Count()); }
public void ValidFilterMissingFilterBehaviorOmit() { Collapse collapse = new Collapse(MissingFilterBehavior.OmitItem); XDocument doc = collapse.ExportToXml( new Repository(), Res.FileContent("ValidXmlWithFilter")); Assert.AreEqual(0, doc.Root.Elements("description").Count()); Assert.AreEqual(0, doc.Root.Elements("customer").Count()); }
public void ValidFilter() { String template = Res.FileContent("ValidXmlWithFilter"); Repository repository = new Repository(); // Normally, repository contains 2 customers which should be in results // Set filter which should leave only 1 customer in results Collapse collapse = new Collapse() .SetFilter("isCustomerValid", args => args[0].Value<String>().Contains("Mark")) .SetFilter("hasCustomers", args => args[0].Value<List<Customer>>().Any()); XDocument xDocument = collapse.ExportToXml(repository, template); List<XElement> customers = xDocument.Root.Elements("customer").ToList(); Assert.AreEqual(1, customers.Count); // Set filter which should filter out all customers from results collapse = new Collapse() .SetFilter("isCustomerValid", args => args[1].Value<int>() > 20) .SetFilter("hasCustomers", args => args[0].Value<List<Customer>>().Any()); xDocument = collapse.ExportToXml(repository, template); customers = xDocument.Root.Elements("customer").ToList(); Assert.AreEqual(0, customers.Count); Assert.IsTrue(xDocument.Root.Elements("description").Count() == 1); // Set filter which should filter out all customers from results collapse = new Collapse() .SetFilter("isCustomerValid", args => args[1].Value<int>() > 20) .SetFilter("hasCustomers", args => false); xDocument = collapse.ExportToXml(repository, template); customers = xDocument.Root.Elements("customer").ToList(); Assert.AreEqual(0, customers.Count); Assert.IsTrue(xDocument.Root.Elements("description").Count() == 0); }
public void FilterOnValue() { // Only Mark should have his name shown Collapse collapse = new Collapse() .SetFilter("isCustomerValid", args => args[0].Value<Customer>().Name.ToLower().Contains("mark")); Repository rep = new Repository(); XDocument doc = collapse.ExportToXml( rep, Res.FileContent("FilterOnValue")); Debug.WriteLine(doc.ToString()); List<XElement> customers = doc.Root.Elements("customer").ToList(); Assert.AreEqual(rep.Customers[0].Name, customers[0].Value.Trim()); Assert.AreEqual(string.Empty, customers[1].Value.Trim()); }