public void ForeachFromIEnumerableOfValueTypeCovariance() { Repository repository = new Repository(); XDocument doc = new Collapse() .ExportToXml(repository, Res.FileContent("ValidXmlCovarianceInValueTypes")); }
public void ForeachCollectionIdentifierContainsWordIn() { Repository repository = new Repository(); XDocument doc = new Collapse() .ExportToXml(repository, Res.FileContent("ForeachCollectionIdentifierContainsIn")); }
public void RootValidAndContainsCorrectNumberOfChildren() { Repository repository = new Repository(); XDocument doc = new Collapse() .ExportToXml(repository, Res.FileContent("ForeachCustomer")); Assert.AreEqual("customers", doc.Root.Name); Assert.AreEqual(repository.Customers.Count, doc.Root.Elements("customer").Count()); Assert.AreEqual(doc.Root.Elements().Count(), doc.Root.Elements("customer").Count()); }
public void NamedFilters() { String template = Res.FileContent("FilterNamedArguments"); Repository rep = new Repository(); new Collapse() .SetFilter("Filter", args => { Assert.IsNotNull(args["c"].Value<Customer>()); Assert.IsNotNull(args["count"].Value<int>() >= 0); return true; }) .ExportToXml(rep, template); }
public void ForeachElementCorrectlyTransformed() { Repository repository = new Repository(); XDocument doc = new Collapse() .ExportToXml(repository, Res.FileContent("ForeachCustomer")); List<XElement> customersXml = doc.Root.Elements().ToList(); for (int i = 0; i < repository.Customers.Count; i++) { Customer customer = repository.Customers[i]; XElement customerXml = customersXml[i]; Assert.AreEqual(customer.Name, customerXml.Attribute("name").Value); } }
public void TextNodeIsValid() { Repository rep = new Repository(); XDocument xDocument = new Collapse() .ExportToXml(rep, Res.FileContent("TextNode")); Assert.AreEqual("customers", xDocument.Root.Name); List<XElement> customers = xDocument.Root.Elements("customer").ToList(); for (int i = 0; i < customers.Count; i++) { Assert.AreEqual( String.Format("Customer's name is {0}.", rep.Customers[i].Name), customers[i].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 ValidFilterMissingFilterBehaviorInclude() { Repository rep = new Repository(); XDocument doc = new Collapse(MissingFilterBehavior.IncludeItem) .ExportToXml(rep, Res.FileContent("ValidXmlWithFilter")); Assert.AreEqual(1, doc.Root.Elements("description").Count()); Assert.AreEqual(rep.Customers.Count, 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()); }