public static IOutputFormatter CreateOutputFormatter(IOutputDescription outputDescription, string rootNodeName) { IOutputFormatter outputFormatter; if (outputDescription.Format == OutputFormats.ShapedXML) { outputFormatter = new ShapedXmlOutputFormatter(outputDescription, rootNodeName); } else { outputFormatter = null; } return outputFormatter; }
public void FormatWithNestedEnumerablesInOutputDescriptionFromReferenceType_Expected_XmlWithRecordsetValues() { PocoTestData testData = GivenPocoWithParallelAndNestedEnumerables(); IDataSourceShape dataSourceShape = DataSourceShapeFactory.CreateDataSourceShape(); dataSourceShape.Paths.Add(new PocoPath("Name", "Name", "[[Names().RootName]]")); dataSourceShape.Paths.Add(new PocoPath("EnumerableData().Name", "EnumerableData.Name", "[[Names().NameAtLevel1]]")); dataSourceShape.Paths.Add(new PocoPath("EnumerableData().EnumerableData().Name", "EnumerableData.EnumerableData.Name", "[[Names().NameAtLevel2]]")); IOutputDescription outputDescription = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML); outputDescription.DataSourceShapes.Add(dataSourceShape); ShapedXmlOutputFormatter outputFormatter = new ShapedXmlOutputFormatter(outputDescription) { RootNodeName = "ADL" }; const string expected = @"<ADL> <Names> <RootName>Brendon</RootName> <NameAtLevel1>Mo</NameAtLevel1> <NameAtLevel2>Jayd</NameAtLevel2> </Names> <Names> <RootName>Brendon</RootName> <NameAtLevel1>Mo</NameAtLevel1> <NameAtLevel2>Dan</NameAtLevel2> </Names> <Names> <RootName>Brendon</RootName> <NameAtLevel1>Mo</NameAtLevel1> <NameAtLevel2>Warren</NameAtLevel2> </Names> <Names> <RootName>Brendon</RootName> <NameAtLevel1>Trav</NameAtLevel1> <NameAtLevel2>Mark</NameAtLevel2> </Names> </ADL>"; string actual = outputFormatter.Format(testData).ToString(); Assert.AreEqual(expected, actual); }
public void FormatWithNonExistantEnumerableInOutputDescriptionFromReferenceType_Expected_XmlWithEmptyRecordsetValues() { PocoTestData testData = GivenPocoWithParallelAndNestedEnumerables(); IDataSourceShape dataSourceShape = DataSourceShapeFactory.CreateDataSourceShape(); dataSourceShape.Paths.Add(new PocoPath("EnumerableData().CakeName", "EnumerableData.CakeName", "[[Names().CakeName]]")); IOutputDescription outputDescription = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML); outputDescription.DataSourceShapes.Add(dataSourceShape); ShapedXmlOutputFormatter outputFormatter = new ShapedXmlOutputFormatter(outputDescription) { RootNodeName = "ADL" }; const string expected = @"<ADL> <Names> <CakeName /> </Names> <Names> <CakeName /> </Names> </ADL>"; string actual = outputFormatter.Format(testData).ToString(); Assert.AreEqual(expected, actual); }
public void FormatWithUnrelatedAndNestedEnumerablesInOutputDescriptionFromXml_Expected_XmlWithRecordsetValues() { string testData = GivenXml(); IDataSourceShape dataSourceShape = DataSourceShapeFactory.CreateDataSourceShape(); dataSourceShape.Paths.Add(new XmlPath("Company:Name", "Company:Name", "[[Names().CompanyName]]")); dataSourceShape.Paths.Add(new XmlPath("Company.Departments().Department:Name", "Company.Departments.Department:Name", "[[Names().DepartmentName]]")); dataSourceShape.Paths.Add(new XmlPath("Company.Departments().Department.Employees().Person:Name", "Company.Departments.Department.Employees.Person:Name", "[[Names().EmployeeName]]")); dataSourceShape.Paths.Add(new XmlPath("Company().InlineRecordSet", "Company().InlineRecordSet", "[[Names().InnerName]]")); IOutputDescription outputDescription = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML); outputDescription.DataSourceShapes.Add(dataSourceShape); ShapedXmlOutputFormatter outputFormatter = new ShapedXmlOutputFormatter(outputDescription) { RootNodeName = "ADL" }; const string expected = @"<ADL> <Names> <CompanyName>Dev2</CompanyName> <DepartmentName>Dev</DepartmentName> <EmployeeName>Brendon</EmployeeName> <InnerName> RandomData </InnerName> </Names> <Names> <CompanyName>Dev2</CompanyName> <DepartmentName>Dev</DepartmentName> <EmployeeName>Jayd</EmployeeName> <InnerName> RandomData1 </InnerName> </Names> <Names> <CompanyName>Dev2</CompanyName> <DepartmentName>Accounts</DepartmentName> <EmployeeName>Bob</EmployeeName> <InnerName></InnerName> </Names> <Names> <CompanyName>Dev2</CompanyName> <DepartmentName>Accounts</DepartmentName> <EmployeeName>Joe</EmployeeName> <InnerName></InnerName> </Names> </ADL>"; string actual = outputFormatter.Format(testData).ToString(); Assert.AreEqual(expected, actual); }
public void FormatWithNonExistantEnumerableInOutputDescriptionFromXml_Expected_XmlWithEmptyRecordsetValues() { string testData = GivenXml(); IDataSourceShape dataSourceShape = DataSourceShapeFactory.CreateDataSourceShape(); dataSourceShape.Paths.Add(new XmlPath("Company.Departments().Department:CakeName", "Company.Departments.Department:CakeName", "[[Departments().CakeName]]")); IOutputDescription outputDescription = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML); outputDescription.DataSourceShapes.Add(dataSourceShape); ShapedXmlOutputFormatter outputFormatter = new ShapedXmlOutputFormatter(outputDescription) { RootNodeName = "ADL" }; const string expected = @"<ADL> <Departments> <CakeName></CakeName> </Departments> </ADL>"; string actual = outputFormatter.Format(testData).ToString(); Assert.AreEqual(expected, actual); }
public void FormatWithUnrelatedEnumerablesInOutputDescriptionFromJson_Expected_XmlWithRecordsetValues() { string testData = GivenJson(); IDataSourceShape dataSourceShape = DataSourceShapeFactory.CreateDataSourceShape(); dataSourceShape.Paths.Add(new JsonPath("Name", "Name", "[[Names().CompanyName]]")); dataSourceShape.Paths.Add(new JsonPath("Departments().Employees().Name", "Departments.Employees.Name", "[[Names().EmployeeName]]")); dataSourceShape.Paths.Add(new JsonPath("PrimitiveRecordset()", "PrimitiveRecordset", "[[Names().InnerName]]")); IOutputDescription outputDescription = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML); outputDescription.DataSourceShapes.Add(dataSourceShape); ShapedXmlOutputFormatter outputFormatter = new ShapedXmlOutputFormatter(outputDescription) { RootNodeName = "ADL" }; const string expected = @"<ADL> <Names> <CompanyName>Dev2</CompanyName> <EmployeeName>Brendon</EmployeeName> <InnerName> RandomData , RandomData1 </InnerName> </Names> <Names> <CompanyName>Dev2</CompanyName> <EmployeeName>Jayd</EmployeeName> <InnerName></InnerName> </Names> <Names> <CompanyName>Dev2</CompanyName> <EmployeeName>Bob</EmployeeName> <InnerName></InnerName> </Names> <Names> <CompanyName>Dev2</CompanyName> <EmployeeName>Joe</EmployeeName> <InnerName></InnerName> </Names> </ADL>"; string actual = outputFormatter.Format(testData).ToString(); Assert.AreEqual(expected, actual); }
public void FormatWithNonExistantNestedEnumerablesInOutputDescriptionFromJson_Expected_XmlWithEmptyRecordsetValues() { string testData = GivenJson(); IDataSourceShape dataSourceShape = DataSourceShapeFactory.CreateDataSourceShape(); dataSourceShape.Paths.Add(new JsonPath("Name", "Name", "[[Names().CompanyName]]")); dataSourceShape.Paths.Add(new JsonPath("Departments().Name", "Departments.Name", "[[Names().DepartmentName]]")); dataSourceShape.Paths.Add(new JsonPath("Departments().Employees().CakeName", "Departments.Employees.CakeName", "[[Names().EmployeeCakeName]]")); IOutputDescription outputDescription = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML); outputDescription.DataSourceShapes.Add(dataSourceShape); ShapedXmlOutputFormatter outputFormatter = new ShapedXmlOutputFormatter(outputDescription) { RootNodeName = "ADL" }; const string expected = @"<ADL> <Names> <CompanyName>Dev2</CompanyName> <DepartmentName>Dev</DepartmentName> <EmployeeCakeName></EmployeeCakeName> </Names> <Names> <CompanyName>Dev2</CompanyName> <DepartmentName>Dev</DepartmentName> <EmployeeCakeName></EmployeeCakeName> </Names> <Names> <CompanyName>Dev2</CompanyName> <DepartmentName>Accounts</DepartmentName> <EmployeeCakeName></EmployeeCakeName> </Names> <Names> <CompanyName>Dev2</CompanyName> <DepartmentName>Accounts</DepartmentName> <EmployeeCakeName></EmployeeCakeName> </Names> </ADL>"; string actual = outputFormatter.Format(testData).ToString(); Assert.AreEqual(expected, actual); }
public void FormatWithScalarInOutputDescriptionFromXml_Expected_XmlWithScalarValue() { string testData = GivenXml(); IDataSourceShape dataSourceShape = DataSourceShapeFactory.CreateDataSourceShape(); dataSourceShape.Paths.Add(new XmlPath("Company:Name", "Company:Name", "[[Name]]")); IOutputDescription outputDescription = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML); outputDescription.DataSourceShapes.Add(dataSourceShape); ShapedXmlOutputFormatter outputFormatter = new ShapedXmlOutputFormatter(outputDescription) { RootNodeName = "ADL" }; const string expected = @"<ADL> <Name>Dev2</Name> </ADL>"; string actual = outputFormatter.Format(testData).ToString(); Assert.AreEqual(expected, actual); }
public void FormatWithNonExistantScalarInOutputDescriptionFromJson_Expected_XmlWithEmptycalarValue() { string testData = GivenJson(); IDataSourceShape dataSourceShape = DataSourceShapeFactory.CreateDataSourceShape(); dataSourceShape.Paths.Add(new JsonPath("CakeName", "CakeName", "[[CakeName]]")); IOutputDescription outputDescription = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML); outputDescription.DataSourceShapes.Add(dataSourceShape); ShapedXmlOutputFormatter outputFormatter = new ShapedXmlOutputFormatter(outputDescription) { RootNodeName = "ADL" }; const string expected = @"<ADL> <CakeName></CakeName> </ADL>"; string actual = outputFormatter.Format(testData).ToString(); Assert.AreEqual(expected, actual); }
public void FormatWithMultipleOutputExpressionsInOutputDescriptionFromReferenceType_Expected_XmlWithRecordsetValuesAndAScalarValue() { PocoTestData testData = GivenPocoWithParallelAndNestedEnumerables(); IDataSourceShape dataSourceShape = DataSourceShapeFactory.CreateDataSourceShape(); dataSourceShape.Paths.Add(new PocoPath("Name", "Name", "[[ScalarName]]")); dataSourceShape.Paths.Add(new PocoPath("EnumerableData().Name", "EnumerableData.Name", "[[Names().NameAtLevel1a]]")); dataSourceShape.Paths.Add(new PocoPath("EnumerableData().EnumerableData().Name", "EnumerableData.EnumerableData.Name", "[[Names().NameAtLevel2a]]")); dataSourceShape.Paths.Add(new PocoPath("EnumerableData1().Name", "EnumerableData1.Name", "[[OtherNames().Name]]")); IOutputDescription outputDescription = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML); outputDescription.DataSourceShapes.Add(dataSourceShape); ShapedXmlOutputFormatter outputFormatter = new ShapedXmlOutputFormatter(outputDescription) { RootNodeName = "ADL" }; const string expected = @"<ADL> <ScalarName>Brendon</ScalarName> <Names> <NameAtLevel1a>Mo</NameAtLevel1a> <NameAtLevel2a>Jayd</NameAtLevel2a> </Names> <Names> <NameAtLevel1a>Mo</NameAtLevel1a> <NameAtLevel2a>Dan</NameAtLevel2a> </Names> <Names> <NameAtLevel1a>Mo</NameAtLevel1a> <NameAtLevel2a>Warren</NameAtLevel2a> </Names> <Names> <NameAtLevel1a>Trav</NameAtLevel1a> <NameAtLevel2a>Mark</NameAtLevel2a> </Names> <OtherNames> <Name>Franco</Name> </OtherNames> <OtherNames> <Name>Taryn</Name> </OtherNames> <OtherNames> <Name>Melissa</Name> </OtherNames> <OtherNames> <Name>Melanie</Name> </OtherNames> <OtherNames> <Name>Justin</Name> </OtherNames> </ADL>"; string actual = outputFormatter.Format(testData).ToString(); Assert.AreEqual(expected, actual); }
public void FormatWithMultipleOutputExpressionsInOutputDescriptionFromJson_Expected_XmlWithRecordsetValuesAndAScalarValue() { string testData = GivenJson(); IDataSourceShape dataSourceShape = DataSourceShapeFactory.CreateDataSourceShape(); dataSourceShape.Paths.Add(new JsonPath("Name", "Name", "[[ScalarName]]")); dataSourceShape.Paths.Add(new JsonPath("Departments().Name", "Departments.Name", "[[Names().DepartmentName]]")); dataSourceShape.Paths.Add(new JsonPath("Departments().Employees().Name", "Departments.Employees.Name", "[[Names().EmployeeName]]")); dataSourceShape.Paths.Add(new JsonPath("PrimitiveRecordset()", "PrimitiveRecordset", "[[OtherNames().Name]]")); IOutputDescription outputDescription = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML); outputDescription.DataSourceShapes.Add(dataSourceShape); ShapedXmlOutputFormatter outputFormatter = new ShapedXmlOutputFormatter(outputDescription) { RootNodeName = "ADL" }; const string expected = @"<ADL> <ScalarName>Dev2</ScalarName> <Names> <DepartmentName>Dev</DepartmentName> <EmployeeName>Brendon</EmployeeName> </Names> <Names> <DepartmentName>Dev</DepartmentName> <EmployeeName>Jayd</EmployeeName> </Names> <Names> <DepartmentName>Accounts</DepartmentName> <EmployeeName>Bob</EmployeeName> </Names> <Names> <DepartmentName>Accounts</DepartmentName> <EmployeeName>Joe</EmployeeName> </Names> <OtherNames> <Name> RandomData </Name> </OtherNames> <OtherNames> <Name> RandomData1 </Name> </OtherNames> </ADL>"; string actual = outputFormatter.Format(testData).ToString(); Assert.AreEqual(expected, actual); }
public void FormatWithEnumerableInOutputDescriptionFromJson_Expected_XmlWithRecordsetValues() { string testData = GivenJson(); IDataSourceShape dataSourceShape = DataSourceShapeFactory.CreateDataSourceShape(); dataSourceShape.Paths.Add(new JsonPath("Departments().Name", "Departments.Name", "[[Departments().Name]]")); IOutputDescription outputDescription = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML); outputDescription.DataSourceShapes.Add(dataSourceShape); ShapedXmlOutputFormatter outputFormatter = new ShapedXmlOutputFormatter(outputDescription); outputFormatter.RootNodeName = "ADL"; string expected = @"<ADL> <Departments> <Name>Dev</Name> </Departments> <Departments> <Name>Accounts</Name> </Departments> </ADL>"; string actual = outputFormatter.Format(testData).ToString(); Assert.AreEqual(expected, actual); }
public void FormatWithScalarInOutputDescriptionFromReferenceType_Expected_XmlWithScalarValue() { PocoTestData testData = GivenPocoWithParallelAndNestedEnumerables(); IDataSourceShape dataSourceShape = DataSourceShapeFactory.CreateDataSourceShape(); dataSourceShape.Paths.Add(new PocoPath("Name", "Name", "[[Name]]")); IOutputDescription outputDescription = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML); outputDescription.DataSourceShapes.Add(dataSourceShape); ShapedXmlOutputFormatter outputFormatter = new ShapedXmlOutputFormatter(outputDescription); outputFormatter.RootNodeName = "ADL"; string expected = @"<ADL> <Name>Brendon</Name> </ADL>"; string actual = outputFormatter.Format(testData).ToString(); Assert.AreEqual(expected, actual); }
public void FormatWithUnrelatedEnumerablesInOutputDescriptionFromReferenceType_Expected_XmlWithRecordsetValues() { PocoTestData testData = GivenPocoWithParallelAndNestedEnumerables(); IDataSourceShape dataSourceShape = DataSourceShapeFactory.CreateDataSourceShape(); dataSourceShape.Paths.Add(new PocoPath("Name", "Name", "[[Names().RootName]]")); dataSourceShape.Paths.Add(new PocoPath("EnumerableData().Name", "EnumerableData.Name", "[[Names().NameAtLevel1a]]")); dataSourceShape.Paths.Add(new PocoPath("EnumerableData1().Name", "EnumerableData1.Name", "[[Names().NameAtLevel1b]]")); IOutputDescription outputDescription = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML); outputDescription.DataSourceShapes.Add(dataSourceShape); ShapedXmlOutputFormatter outputFormatter = new ShapedXmlOutputFormatter(outputDescription); outputFormatter.RootNodeName = "ADL"; string expected = @"<ADL> <Names> <RootName>Brendon</RootName> <NameAtLevel1a>Mo</NameAtLevel1a> <NameAtLevel1b>Franco</NameAtLevel1b> </Names> <Names> <RootName>Brendon</RootName> <NameAtLevel1a>Trav</NameAtLevel1a> <NameAtLevel1b>Taryn</NameAtLevel1b> </Names> <Names> <RootName>Brendon</RootName> <NameAtLevel1a></NameAtLevel1a> <NameAtLevel1b>Melissa</NameAtLevel1b> </Names> <Names> <RootName>Brendon</RootName> <NameAtLevel1a></NameAtLevel1a> <NameAtLevel1b>Melanie</NameAtLevel1b> </Names> <Names> <RootName>Brendon</RootName> <NameAtLevel1a></NameAtLevel1a> <NameAtLevel1b>Justin</NameAtLevel1b> </Names> </ADL>"; string actual = outputFormatter.Format(testData).ToString(); Assert.AreEqual(expected, actual); }