public INavigator CreateNavigator(object data, Type pathType) { if (!pathType.GetInterfaces().Contains(typeof (IPath))) { throw new Exception("'" + pathType + "' doesn't implement '" + typeof (IPath) + "'"); } INavigator navigator; if (pathType == typeof (XmlPath)) { navigator = new XmlNavigator(data); } else if (pathType == typeof (JsonPath)) { navigator = new JsonNavigator(data); } else if (pathType == typeof (PocoPath)) { navigator = new PocoNavigator(data); } else if( pathType == typeof(StringPath)) { navigator = new StringNavigator(data); } else { navigator = null; } return navigator; }
public void SelectScalarValueUsingScalarPathFromXml_WherePathMapsToAnAttribute_Expected_ScalarValue() { string testData = Given(); IPath namePath = new XmlPath("Company:Name", "Company:Name"); XmlNavigator xmlNavigator = new XmlNavigator(testData); string actual = xmlNavigator.SelectScalar(namePath).ToString(); string expected = "Dev2"; Assert.AreEqual(expected, actual); }
string GetSampleData(XElement root, IPath path) { var navigator = new XmlNavigator(root.ToString()); return(string.Join(GlobalConstants.AnythingToXmlPathSeperator, navigator.SelectEnumerable(path) .Select( o => o.ToString() .Replace(GlobalConstants.AnythingToXmlPathSeperator, GlobalConstants.AnytingToXmlCommaToken)) .Take(10))); }
public void SelectEnumerableValuesAsRelatedUsingEnumerablePathFromXml_Where_PathsContainNestedEnumerablePaths_Expected_FlattenedDataWithValuesFromOuterEnumerablePathRepeatingForEveryValueFromNestedEnumerablePath() { string testData = Given(); IPath path = new XmlPath("Company.Departments().Department:Name", "Company.Departments.Department:Name"); IPath path1 = new XmlPath("Company.Departments().Department.Employees().Person:Name", "Company.Departments.Department.Employees.Person:Name"); List<IPath> paths = new List<IPath> { path, path1 }; XmlNavigator xmlNavigator = new XmlNavigator(testData); Dictionary<IPath, IList<object>> data = xmlNavigator.SelectEnumerablesAsRelated(paths); string expected = "Dev|Dev|Accounts|Accounts^Brendon|Jayd|Bob|Joe"; string actual = string.Join("|", data[path].Select(s => s.ToString().Trim())) + "^" + string.Join("|", data[path1].Select(s => s.ToString().Trim())); Assert.AreEqual(expected, actual); }
public void SelectEnumerableValuesAsRelatedUsingEnumerablePathFromXml_Where_PathsContainUnrelatedEnumerablePaths_Expected_FlattenedDataWithValuesFromUnrelatedEnumerablePathsAtMatchingIndexes() { string testData = Given(); IPath path = new XmlPath("Company().OuterNestedRecordSet().InnerNestedRecordSet:ItemValue", "Company.OuterNestedRecordSet.InnerNestedRecordSet:ItemValue"); IPath path1 = new XmlPath("Company().InlineRecordSet", "Company.InlineRecordSet"); List<IPath> paths = new List<IPath> { path, path1 }; XmlNavigator xmlNavigator = new XmlNavigator(testData); Dictionary<IPath, IList<object>> data = xmlNavigator.SelectEnumerablesAsRelated(paths); string expected = "val1|val2|val3|val4^RandomData|RandomData1||"; string actual = string.Join("|", data[path].Select(s => s.ToString().Trim())) + "^" + string.Join("|", data[path1].Select(s => s.ToString().Trim())); Assert.AreEqual(expected, actual); }
public void SelectEnumerableValuesAsRelatedUsingEnumerablePathFromXml_Where_PathsContainAScalarPath_Expected_FlattenedDataWithValueFromScalarPathRepeatingForEachEnumeration() { string testData = Given(); IPath path = new XmlPath("Company:Name", "Company:Name"); IPath path1 = new XmlPath("Company().InlineRecordSet", "Company.InlineRecordSet"); List<IPath> paths = new List<IPath> { path, path1 }; XmlNavigator xmlNavigator = new XmlNavigator(testData); Dictionary<IPath, IList<object>> data = xmlNavigator.SelectEnumerablesAsRelated(paths); string expected = "Dev2|Dev2^RandomData|RandomData1"; string actual = string.Join("|", data[path].Select(s => s.ToString().Trim())) + "^" + string.Join("|", data[path1].Select(s => s.ToString().Trim())); Assert.AreEqual(expected, actual); }
public void SelectEnumerableValuesAsRelatedUsingScalarPathFromXmlWithASingleNode_WherePathMapsToANode_Expected_ScalarValue() { string testData = GivenSingleNode(); IPath namePath = new XmlPath("Message", "Message"); IList<IPath> paths = new List<IPath>(); paths.Add(namePath); XmlNavigator xmlNavigator = new XmlNavigator(testData); var actual = xmlNavigator.SelectEnumerablesAsRelated(paths); string expected = "Dummy Data"; Assert.IsTrue(actual[namePath].Contains(expected)); }
public void SelectEnumerableValuesUsingEnumerablePathFromXml_WherePathMapsThroughNestedEnumerablesScenario2_Expected_EnumerableValue() { string testData = Given(); IPath path = new XmlPath("Company().OuterNestedRecordSet().InnerNestedRecordSet:ItemValue", "Company.OuterNestedRecordSet.InnerNestedRecordSet:ItemValue"); XmlNavigator xmlNavigator = new XmlNavigator(testData); string actual = string.Join("|", xmlNavigator.SelectEnumerable(path).Select(o => o.ToString().Trim())); string expected = "val1|val2|val3|val4"; Assert.AreEqual(expected, actual); }
public void SelectEnumerableValuesUsingScalarPathFromXml_WherePathMapsToANode_Expected_EnumerableValue() { string testData = Given(); IPath path = new XmlPath("Company.Motto", "Company.Motto"); XmlNavigator xmlNavigator = new XmlNavigator(testData); string actual = string.Join("|", xmlNavigator.SelectEnumerable(path).Select(o => o.ToString().Trim())); const string expected = "Eat lots of cake"; Assert.AreEqual(expected, actual); }
public void SelectEnumerableValuesUsingEnumerablePathFromXml_WherePathMapsToANode_Expected_EnumerableValue() { string testData = Given(); IPath path = new XmlPath("Company().InlineRecordSet", "Company.InlineRecordSet"); XmlNavigator xmlNavigator = new XmlNavigator(testData); string actual = string.Join("|", xmlNavigator.SelectEnumerable(path).Select(o => o.ToString().Trim())); string expected = "RandomData|RandomData1"; Assert.AreEqual(expected, actual); }
public void SelectEnumerableValueUsingScalarPathFromXmlWithASingleNode_WherePathMapsToANode_Expected_ScalarValue() { string testData = GivenSingleNode(); IPath namePath = new XmlPath("Message", "Message"); XmlNavigator xmlNavigator = new XmlNavigator(testData); IEnumerable<object> actual = xmlNavigator.SelectEnumerable(namePath); string expected = "Dummy Data"; Assert.IsTrue(actual.Contains(expected)); }
public void SelectScalarValueUsingEnumerablePathFromXml_WherePathMapsToANode_Expected_ScalarValue() { string testData = Given(); IPath namePath = new XmlPath("Company().InlineRecordSet", "Company.InlineRecordSet"); XmlNavigator xmlNavigator = new XmlNavigator(testData); string actual = xmlNavigator.SelectScalar(namePath).ToString().Trim(); string expected = "RandomData1"; Assert.AreEqual(expected, actual); }
public void SelectScalarValueUsingEnumerablePathFromXml_WherePathMapsToAnAttribute_Expected_ScalarValue() { string testData = Given(); IPath namePath = new XmlPath("Company.Departments().Department.Employees().Person:Name", "Company.Departments.Department.Employees.Person:Name"); XmlNavigator xmlNavigator = new XmlNavigator(testData); string actual = xmlNavigator.SelectScalar(namePath).ToString(); string expected = "Joe"; Assert.AreEqual(expected, actual); }
public void SelectScalarValueUsingScalarPathFromXmlWithASingleNode_WherePathMapsToANode_Expected_ScalarValue() { string testData = GivenSingleNode(); IPath namePath = new XmlPath("Message", "Message"); XmlNavigator xmlNavigator = new XmlNavigator(testData); string actual = xmlNavigator.SelectScalar(namePath).ToString(); string expected = "Dummy Data"; Assert.AreEqual(expected, actual); }
private string GetSampleData(XElement root, IPath path) { var navigator = new XmlNavigator(root.ToString()); return string.Join(GlobalConstants.AnythingToXmlPathSeperator, navigator.SelectEnumerable(path) .Select( o => o.ToString() .Replace(GlobalConstants.AnythingToXmlPathSeperator, GlobalConstants.AnytingToXmlCommaToken)) .Take(10)); }
public void SelectEnumerableValuesAsRelatedUsingEnumerablePathFromXml_Where_PathsContainASinglePathWhichIsEnumerable_Expected_FlattenedDataWithValuesFromEnumerablePath() { string testData = Given(); IPath path = new XmlPath("Company.Departments().Department.Employees().Person:Name", "Company.Departments.Department.Employees.Person:Name"); List<IPath> paths = new List<IPath> { path }; XmlNavigator xmlNavigator = new XmlNavigator(testData); Dictionary<IPath, IList<object>> data = xmlNavigator.SelectEnumerablesAsRelated(paths); string expected = "Brendon|Jayd|Bob|Joe"; string actual = string.Join("|", data[path].Select(s => s.ToString().Trim())); Assert.AreEqual(expected, actual); }
public void SelectEnumerableValuesAsRelatedUsingEnumerablePathFromXml_Where_PathsContainASinglePathWhichIsScalar_Expected_FlattenedDataWithValueFromScalarPath() { string testData = Given(); IPath path = new XmlPath("Company:Name", "Company:Name"); List<IPath> paths = new List<IPath> { path }; XmlNavigator xmlNavigator = new XmlNavigator(testData); Dictionary<IPath, IList<object>> data = xmlNavigator.SelectEnumerablesAsRelated(paths); string expected = "Dev2"; string actual = string.Join("|", data[path].Select(s => s.ToString().Trim())); Assert.AreEqual(expected, actual); }
public void SelectEnumerableValuesUsingScalarPathFromXml_WherePathMapsToAnAttribute_Expected_EnumerableValue() { string testData = Given(); IPath path = new XmlPath("Company:Name", "Company:Name"); XmlNavigator xmlNavigator = new XmlNavigator(testData); string actual = string.Join("|", xmlNavigator.SelectEnumerable(path).Select(o => o.ToString().Trim())); string expected = "Dev2"; Assert.AreEqual(expected, actual); }
public void SelectScalarValueUsingScalarPathFromXml_WherePathMapsToANode_Expected_ScalarValue() { string testData = Given(); IPath namePath = new XmlPath("Company.Motto", "Company.Motto"); XmlNavigator xmlNavigator = new XmlNavigator(testData); string actual = xmlNavigator.SelectScalar(namePath).ToString(); string expected = "Eat lots of cake"; Assert.AreEqual(expected, actual); }
public void SelectEnumerableValuesUsingEnumerablePathFromXml_WherePathMapsThroughNestedEnumerablesScenario1_Expected_EnumerableValue() { string testData = Given(); IPath path = new XmlPath("Company.Departments().Department.Employees().Person:Name", "Company.Departments.Department.Employees.Person:Name"); XmlNavigator xmlNavigator = new XmlNavigator(testData); string actual = string.Join("|", xmlNavigator.SelectEnumerable(path).Select(o => o.ToString().Trim())); string expected = "Brendon|Jayd|Bob|Joe"; Assert.AreEqual(expected, actual); }