Esempio n. 1
0
        public void SelectEnumerableValuesAsRelatedUsingEnumerablePathFromJson_Where_PathsContainASinglePathWhichIsScalar_Expected_FlattenedDataWithValueFromScalarPath()
        {
            IPath path  = new JsonPath("Name", "Name");
            var   paths = new List <IPath> {
                path
            };

            var JsonNavigator = new JsonNavigator(testData);

            var data = JsonNavigator.SelectEnumerablesAsRelated(paths);

            const string expected = "Dev2";
            var          actual   = string.Join("|", data[path].Select(s => s.ToString().Trim()));

            Assert.AreEqual(expected, actual);
        }
Esempio n. 2
0
        public void SelectEnumerableValuesAsRelatedUsingEnumerablePathFromJson_Where_PathsContainASinglePathWhichIsEnumerable_Expected_FlattenedDataWithValuesFromEnumerablePath()
        {
            IPath path  = new JsonPath("Departments().Employees().Name", "Departments.Employees.Name");
            var   paths = new List <IPath> {
                path
            };

            var JsonNavigator = new JsonNavigator(testData);

            var data = JsonNavigator.SelectEnumerablesAsRelated(paths);

            const string expected = "Brendon|Jayd|Bob|Joe";
            var          actual   = string.Join("|", data[path].Select(s => s.ToString().Trim()));

            Assert.AreEqual(expected, actual);
        }
Esempio n. 3
0
        public void SelectEnumerableValuesAsRelatedUsingEnumerablePathFromJson_Where_PathsContainUnrelatedEnumerablePaths_Expected_FlattenedDataWithValuesFromUnrelatedEnumerablePathsAtMatchingIndexes()
        {
            IPath path  = new JsonPath("Departments().Name", "Departments.Name");
            IPath path1 = new JsonPath("Contractors().Name", "Contractors.Name");
            var   paths = new List <IPath> {
                path, path1
            };

            var JsonNavigator = new JsonNavigator(testData);

            var data = JsonNavigator.SelectEnumerablesAsRelated(paths);

            const string expected = "Dev|Accounts||^Roofs Inc.|Glass Inc.|Doors Inc.|Cakes Inc.";
            var          actual   = string.Join("|", data[path].Select(s => s.ToString().Trim())) + "^" + string.Join("|", data[path1].Select(s => s.ToString().Trim()));

            Assert.AreEqual(expected, actual);
        }
Esempio n. 4
0
        public void SelectEnumerableValuesAsRelatedUsingEnumerablePathFromJson_Where_PathsContainAScalarPath_Expected_FlattenedDataWithValueFromScalarPathRepeatingForEachEnumeration()
        {
            IPath path  = new JsonPath("Name", "Name");
            IPath path1 = new JsonPath("Departments().Name", "Departments.Name");
            var   paths = new List <IPath> {
                path, path1
            };

            var JsonNavigator = new JsonNavigator(testData);

            var data = JsonNavigator.SelectEnumerablesAsRelated(paths);

            const string expected = "Dev2|Dev2^Dev|Accounts";
            var          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_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);

            string expected = "Dev2";
            string actual   = string.Join("|", data[path].Select(s => s.ToString().Trim()));

            Assert.AreEqual(expected, actual);
        }
Esempio n. 6
0
        public void SelectEnumerableValuesAsRelatedUsingEnumerablePathFromJson_Where_PathsContainNestedEnumerablePaths_Expected_FlattenedDataWithValuesFromOuterEnumerablePathRepeatingForEveryValueFromNestedEnumerablePath()
        {
            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");
            var   paths = new List <IPath> {
                path3, path, path1, path2
            };

            var JsonNavigator = new JsonNavigator(testData);

            var data = JsonNavigator.SelectEnumerablesAsRelated(paths);

            var expected = "Dev2|Dev2|Dev2|Dev2^Dev|Dev|Accounts|Accounts^Brendon|Jayd|Bob|Joe^RandomData\r\n    ,\r\n        RandomData1|||";
            var 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()));

            FixBreaks(ref expected, ref actual);
            Assert.AreEqual(expected, actual);
        }
Esempio n. 7
0
        public void SelectEnumerablesAsRelated_WithSeperatorSymbol_Expected_UnchangedPath()
        {
            List <IPath> namePath = new List <IPath>()
            {
                new JsonPath(".", ".")
            };

            var JsonNavigator = new JsonNavigator(testData);

            var actual = string.Join("|", JsonNavigator.SelectEnumerablesAsRelated(namePath).Values.FirstOrDefault());

            var expected = @"{
  ""Name"": ""Dev2"",
  ""Motto"": ""Eat lots of cake"",
  ""Departments"": [
    {
      ""Name"": ""Dev"",
      ""Employees"": [
        {
          ""Name"": ""Brendon"",
          ""Surename"": ""Page""
        },
        {
          ""Name"": ""Jayd"",
          ""Surename"": ""Page""
        }
      ]
    },
    {
      ""Name"": ""Accounts"",
      ""Employees"": [
        {
          ""Name"": ""Bob"",
          ""Surename"": ""Soap""
        },
        {
          ""Name"": ""Joe"",
          ""Surename"": ""Pants""
        }
      ]
    }
  ],
  ""Contractors"": [
    {
      ""Name"": ""Roofs Inc."",
      ""PhoneNumber"": ""123""
    },
    {
      ""Name"": ""Glass Inc."",
      ""PhoneNumber"": ""1234""
    },
    {
      ""Name"": ""Doors Inc."",
      ""PhoneNumber"": ""1235""
    },
    {
      ""Name"": ""Cakes Inc."",
      ""PhoneNumber"": ""1236""
    }
  ],
  ""PrimitiveRecordset"": [
    ""\r\n        RandomData\r\n    "",
    ""\r\n        RandomData1\r\n    ""
  ]
}";

            Assert.AreEqual(expected, actual);
        }