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; }
string GetSampleData(JToken root, IPath path) { var navigator = new JsonNavigator(root.ToString()); return(string.Join(GlobalConstants.AnythingToXmlPathSeperator, navigator.SelectEnumerable(path) .Select( o => o.ToString() .Replace(GlobalConstants.AnythingToXmlPathSeperator, GlobalConstants.AnytingToXmlCommaToken)) .Take(10))); }
public void SelectScalarValueUsingScalarPathFromJson_Expected_ScalarValue() { string testData = Given(); IPath namePath = new JsonPath("Name", "Name"); JsonNavigator JsonNavigator = new JsonNavigator(testData); string actual = JsonNavigator.SelectScalar(namePath).ToString(); const string expected = "Dev2"; Assert.AreEqual(expected, actual); }
public void SelectEnumerableValuesAsRelatedUsingEnumerablePathFromJson_Where_PathsContainASinglePathWhichIsScalar_Expected_FlattenedDataWithValueFromScalarPath() { string testData = Given(); IPath path = new JsonPath("Name", "Name"); List<IPath> paths = new List<IPath> { path }; JsonNavigator JsonNavigator = new JsonNavigator(testData); Dictionary<IPath, IList<object>> data = JsonNavigator.SelectEnumerablesAsRelated(paths); const string expected = "Dev2"; string actual = string.Join("|", data[path].Select(s => s.ToString().Trim())); Assert.AreEqual(expected, actual); }
public void SelectEnumerableValuesAsRelatedUsingEnumerablePathFromJson_Where_PathsContainASinglePathWhichIsEnumerable_Expected_FlattenedDataWithValuesFromEnumerablePath() { string testData = Given(); IPath path = new JsonPath("Departments().Employees().Name", "Departments.Employees.Name"); List<IPath> paths = new List<IPath> { path }; JsonNavigator JsonNavigator = new JsonNavigator(testData); Dictionary<IPath, IList<object>> data = JsonNavigator.SelectEnumerablesAsRelated(paths); const string expected = "Brendon|Jayd|Bob|Joe"; string actual = string.Join("|", data[path].Select(s => s.ToString().Trim())); Assert.AreEqual(expected, actual); }
public void SelectEnumerableValuesAsRelatedUsingEnumerablePathFromJson_Where_PathsContainNestedEnumerablePaths_Expected_FlattenedDataWithValuesFromOuterEnumerablePathRepeatingForEveryValueFromNestedEnumerablePath() { string testData = Given(); IPath path3 = new JsonPath("Name", "Name"); IPath path = new JsonPath("Departments().Name", "Departments.Name"); IPath path1 = new JsonPath("Departments().Employees().Name", "Departments.Employees.Name"); IPath path2 = new JsonPath("PrimitiveRecordset()", "PrimitiveRecordset"); List<IPath> paths = new List<IPath> { path3, path, path1, path2 }; JsonNavigator JsonNavigator = new JsonNavigator(testData); Dictionary<IPath, IList<object>> data = JsonNavigator.SelectEnumerablesAsRelated(paths); const string expected = "Dev2|Dev2|Dev2|Dev2^Dev|Dev|Accounts|Accounts^Brendon|Jayd|Bob|Joe^RandomData\r\n ,\r\n RandomData1|||"; string actual = string.Join("|", data[path3].Select(s => s.ToString().Trim())) + "^" + string.Join("|", data[path].Select(s => s.ToString().Trim())) + "^" + string.Join("|", data[path1].Select(s => s.ToString().Trim())) + "^" + string.Join("|", data[path2].Select(s => s.ToString().Trim())); Assert.AreEqual(expected, actual); }
public void SelectEnumerableValuesAsRelatedUsingEnumerablePathFromJson_Where_PathsContainUnrelatedEnumerablePaths_Expected_FlattenedDataWithValuesFromUnrelatedEnumerablePathsAtMatchingIndexes() { string testData = Given(); IPath path = new JsonPath("Departments().Name", "Departments.Name"); IPath path1 = new JsonPath("Contractors().Name", "Contractors.Name"); List<IPath> paths = new List<IPath> { path, path1 }; JsonNavigator JsonNavigator = new JsonNavigator(testData); Dictionary<IPath, IList<object>> data = JsonNavigator.SelectEnumerablesAsRelated(paths); const string expected = "Dev|Accounts||^Roofs Inc.|Glass Inc.|Doors Inc.|Cakes Inc."; 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 SelectEnumerableValuesAsRelatedUsingEnumerablePathFromJson_Where_PathsContainAScalarPath_Expected_FlattenedDataWithValueFromScalarPathRepeatingForEachEnumeration() { string testData = Given(); IPath path = new JsonPath("Name", "Name"); IPath path1 = new JsonPath("Departments().Name", "Departments.Name"); List<IPath> paths = new List<IPath> { path, path1 }; JsonNavigator JsonNavigator = new JsonNavigator(testData); Dictionary<IPath, IList<object>> data = JsonNavigator.SelectEnumerablesAsRelated(paths); const string expected = "Dev2|Dev2^Dev|Accounts"; 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 SelectEnumerableValuesUsingEnumerablePathFromJson_WherePathMapsThroughNestedEnumerables_Expected_EnumerableValue() { string testData = Given(); IPath path = new JsonPath("Departments().Employees().Name", "Departments.Employees.Name"); JsonNavigator JsonNavigator = new JsonNavigator(testData); string actual = string.Join("|", JsonNavigator.SelectEnumerable(path).Select(o => o.ToString().Trim())); const string expected = "Brendon|Jayd|Bob|Joe"; Assert.AreEqual(expected, actual); }
public void SelectEnumerableValuesUsingScalarPathFromJson_Expected_EnumerableValue() { string testData = Given(); IPath path = new JsonPath("Motto", "Motto"); JsonNavigator JsonNavigator = new JsonNavigator(testData); string actual = string.Join("|", JsonNavigator.SelectEnumerable(path).Select(o => o.ToString().Trim())); const string expected = "Eat lots of cake"; Assert.AreEqual(expected, actual); }
public void SelectEnumerableValuesUsingEnumerablePathFromJson_Expected_EnumerableValue() { string testData = Given(); IPath path = new JsonPath("Departments().Name", "Departments.Name"); JsonNavigator JsonNavigator = new JsonNavigator(testData); string actual = string.Join("|", JsonNavigator.SelectEnumerable(path).Select(o => o.ToString().Trim())); const string expected = "Dev|Accounts"; Assert.AreEqual(expected, actual); }
public void SelectEnumerableValuesUsingEnumerablePathFromJson_WherePathMapsToPrimitiveEnumerable_Expected_EnumerableValue() { string testData = Given(); IPath path = new JsonPath("PrimitiveRecordset()", "PrimitiveRecordset"); JsonNavigator JsonNavigator = new JsonNavigator(testData); string actual = string.Join("|", JsonNavigator.SelectEnumerable(path).Select(o => o.ToString().Trim())); const string expected = "RandomData|RandomData1"; Assert.AreEqual(expected, actual); }
public void SelectScalarValueUsingEnumerablePathFromJson_WherePathMapsToPrimitiveEnumerable_Expected_ScalarValue() { string testData = Given(); IPath namePath = new JsonPath("PrimitiveRecordset()", "PrimitiveRecordset"); JsonNavigator JsonNavigator = new JsonNavigator(testData); string actual = JsonNavigator.SelectScalar(namePath).ToString().Trim(); const string expected = "RandomData1"; Assert.AreEqual(expected, actual); }
public void SelectScalarValueUsingEnumerablePathFromJson_Expected_ScalarValue() { string testData = Given(); IPath namePath = new JsonPath("Departments().Employees().Name", "Departments.Employees.Name"); JsonNavigator JsonNavigator = new JsonNavigator(testData); string actual = JsonNavigator.SelectScalar(namePath).ToString(); const string expected = "Joe"; Assert.AreEqual(expected, actual); }
private string GetSampleData(JToken root, IPath path) { var navigator = new JsonNavigator(root.ToString()); return string.Join(GlobalConstants.AnythingToXmlPathSeperator, navigator.SelectEnumerable(path) .Select( o => o.ToString() .Replace(GlobalConstants.AnythingToXmlPathSeperator, GlobalConstants.AnytingToXmlCommaToken)) .Take(10)); }