예제 #1
0
        public void SelectEnumerableValuesAsRelatedUsingScalarPathFromXmlWithASingleNode_WherePathMapsToANode_Expected_ScalarValue()
        {
            IPath         namePath = new XmlPath("Message", "Message");
            IList <IPath> paths    = new List <IPath>();

            paths.Add(namePath);


            var          xmlNavigator = new XmlNavigator(GivenSingleNode);
            var          actual       = xmlNavigator.SelectEnumerablesAsRelated(paths);
            const string expected     = "Dummy Data";

            Assert.IsTrue(actual[namePath].Contains(expected));
        }
예제 #2
0
        public void XmlNavigator_SelectEnumerableValuesAsRelated_UsingScalarPathFrom_Valid_SOAPXml_WherePathMapsToANode_Expected_ScalarValue1()
        {
            IPath         namePath = new XmlPath("Envelope.Body.LoginResponse.LoginResult.CookieName", "Envelope.Body.LoginResponse.LoginResult.CookieName");
            IList <IPath> paths    = new List <IPath>
            {
                namePath
            };

            using (var xmlNavigator = new XmlNavigator(GivenSoapWithManyNamespaces))
            {
                var actual = xmlNavigator.SelectEnumerablesAsRelated(paths);

                Assert.IsTrue(actual[namePath].Contains("FedAuth"));
            }
        }
예제 #3
0
        public void XmlNavigator_SelectEnumerableValuesAsRelated_UsingScalarPathFrom_Valid_SOAPXml_WherePathMapsToANode_Expected_ScalarValue()
        {
            IPath         namePath = new XmlPath("Envelope.Body.process().asCode", "Envelope.Body.process.asCode");
            IList <IPath> paths    = new List <IPath>
            {
                namePath
            };

            using (var xmlNavigator = new XmlNavigator(GivenComplexedSoapTestData))
            {
                var actual = xmlNavigator.SelectEnumerablesAsRelated(paths);

                Assert.IsTrue(actual[namePath].Contains("VN101"));
            }
        }
예제 #4
0
        public void SelectEnumerableValuesAsRelatedUsingEnumerablePathFromXml_Where_PathsContainASinglePathWhichIsScalar_Expected_FlattenedDataWithValueFromScalarPath()
        {
            IPath path  = new XmlPath("Company:Name", "Company:Name");
            var   paths = new List <IPath> {
                path
            };

            var xmlNavigator = new XmlNavigator(testData);

            var data = xmlNavigator.SelectEnumerablesAsRelated(paths);

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

            Assert.AreEqual(expected, actual);
        }
예제 #5
0
        public void SelectEnumerableValuesAsRelatedUsingEnumerablePathFromXml_Where_PathsContainASinglePathWhichIsEnumerable_Expected_FlattenedDataWithValuesFromEnumerablePath()
        {
            IPath path  = new XmlPath("Company.Departments().Department.Employees().Person:Name", "Company.Departments.Department.Employees.Person:Name");
            var   paths = new List <IPath> {
                path
            };

            var xmlNavigator = new XmlNavigator(testData);

            var data = xmlNavigator.SelectEnumerablesAsRelated(paths);

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

            Assert.AreEqual(expected, actual);
        }
예제 #6
0
        public void XmlNavigator_SelectEnumerablesAsRelated_WithSeperatorSymbol_Expected_UnchangedPath()
        {
            var namePath = new List <IPath> {
                new XmlPath(".", ".")
            };

            using (var XmlNavigator = new XmlNavigator(TestData))
            {
                var actual = string.Join("|", XmlNavigator.SelectEnumerablesAsRelated(namePath).Values.FirstOrDefault());

                const string expected =
                    "<Company Name=\"Dev2\">\r\n" +
                    "  <Motto>Eat lots of cake</Motto>\r\n" +
                    "  <PreviousMotto />\r\n" +
                    "  <Departments TestAttrib=\"testing\">\r\n" +
                    "    <Department Name=\"Dev\">\r\n" +
                    "      <Employees>\r\n" +
                    "        <Person Name=\"Brendon\" Surename=\"Page\" />\r\n" +
                    "        <Person Name=\"Jayd\" Surename=\"Page\" />\r\n" +
                    "      </Employees>\r\n" +
                    "    </Department>\r\n" +
                    "    <Department Name=\"Accounts\">\r\n" +
                    "      <Employees>\r\n" +
                    "        <Person Name=\"Bob\" Surename=\"Soap\" />\r\n" +
                    "        <Person Name=\"Joe\" Surename=\"Pants\" />\r\n" +
                    "      </Employees>\r\n" +
                    "    </Department>\r\n" +
                    "  </Departments>\r\n" +
                    "  <InlineRecordSet>\r\n" +
                    "                RandomData\r\n" +
                    "            </InlineRecordSet>\r\n" +
                    "  <InlineRecordSet>\r\n" +
                    "                RandomData1\r\n" +
                    "            </InlineRecordSet>\r\n" +
                    "  <OuterNestedRecordSet>\r\n" +
                    "    <InnerNestedRecordSet ItemValue=\"val1\" />\r\n" +
                    "    <InnerNestedRecordSet ItemValue=\"val2\" />\r\n" +
                    "  </OuterNestedRecordSet>\r\n" +
                    "  <OuterNestedRecordSet>\r\n" +
                    "    <InnerNestedRecordSet ItemValue=\"val3\" />\r\n" +
                    "    <InnerNestedRecordSet ItemValue=\"val4\" />\r\n" +
                    "  </OuterNestedRecordSet>\r\n" +
                    "</Company>";

                Assert.AreEqual(expected, actual);
            }
        }
예제 #7
0
        public void XmlNavigator_SelectEnumerablesAsRelated_WithSeperatorSymbol_Expected_UnchangedPath()
        {
            var namePath = new List <IPath> {
                new XmlPath(".", ".")
            };

            using (var XmlNavigator = new XmlNavigator(TestData))
            {
                var actual = string.Join("|", XmlNavigator.SelectEnumerablesAsRelated(namePath).Values.FirstOrDefault());

                const string expected = @"<Company Name=""Dev2"">
  <Motto>Eat lots of cake</Motto>
  <PreviousMotto />
  <Departments TestAttrib=""testing"">
    <Department Name=""Dev"">
      <Employees>
        <Person Name=""Brendon"" Surename=""Page"" />
        <Person Name=""Jayd"" Surename=""Page"" />
      </Employees>
    </Department>
    <Department Name=""Accounts"">
      <Employees>
        <Person Name=""Bob"" Surename=""Soap"" />
        <Person Name=""Joe"" Surename=""Pants"" />
      </Employees>
    </Department>
  </Departments>
  <InlineRecordSet>
        RandomData
    </InlineRecordSet>
  <InlineRecordSet>
        RandomData1
    </InlineRecordSet>
  <OuterNestedRecordSet>
    <InnerNestedRecordSet ItemValue=""val1"" />
    <InnerNestedRecordSet ItemValue=""val2"" />
  </OuterNestedRecordSet>
  <OuterNestedRecordSet>
    <InnerNestedRecordSet ItemValue=""val3"" />
    <InnerNestedRecordSet ItemValue=""val4"" />
  </OuterNestedRecordSet>
</Company>";

                Assert.AreEqual(expected, actual);
            }
        }
예제 #8
0
        public void SelectEnumerableValuesAsRelatedUsingEnumerablePathFromXml_Where_PathsContainNestedEnumerablePaths_Expected_FlattenedDataWithValuesFromOuterEnumerablePathRepeatingForEveryValueFromNestedEnumerablePath()
        {
            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");
            var   paths = new List <IPath> {
                path, path1
            };

            var xmlNavigator = new XmlNavigator(testData);

            var data = xmlNavigator.SelectEnumerablesAsRelated(paths);

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

            Assert.AreEqual(expected, actual);
        }
예제 #9
0
        public void SelectEnumerableValuesAsRelatedUsingEnumerablePathFromXml_Where_PathsContainUnrelatedEnumerablePaths_Expected_FlattenedDataWithValuesFromUnrelatedEnumerablePathsAtMatchingIndexes()
        {
            IPath path  = new XmlPath("Company().OuterNestedRecordSet().InnerNestedRecordSet:ItemValue", "Company.OuterNestedRecordSet.InnerNestedRecordSet:ItemValue");
            IPath path1 = new XmlPath("Company().InlineRecordSet", "Company.InlineRecordSet");
            var   paths = new List <IPath> {
                path, path1
            };

            var xmlNavigator = new XmlNavigator(testData);

            var data = xmlNavigator.SelectEnumerablesAsRelated(paths);

            const string expected = "val1|val2|val3|val4^RandomData|RandomData1||";
            var          actual   = string.Join("|", data[path].Select(s => s.ToString().Trim())) + "^" + string.Join("|", data[path1].Select(s => s.ToString().Trim()));

            Assert.AreEqual(expected, actual);
        }
예제 #10
0
        public void SelectEnumerableValuesAsRelatedUsingEnumerablePathFromXml_Where_PathsContainAScalarPath_Expected_FlattenedDataWithValueFromScalarPathRepeatingForEachEnumeration()
        {
            IPath path  = new XmlPath("Company:Name", "Company:Name");
            IPath path1 = new XmlPath("Company().InlineRecordSet", "Company.InlineRecordSet");
            var   paths = new List <IPath> {
                path, path1
            };

            var xmlNavigator = new XmlNavigator(testData);

            var data = xmlNavigator.SelectEnumerablesAsRelated(paths);

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

            Assert.AreEqual(expected, actual);
        }
예제 #11
0
        public void SelectEnumerableValuesAsRelatedUsingEnumerablePathFromXmlFromFailingTest()
        {
            var xmlDocument = new XmlDocument();

            xmlDocument.LoadXml("<ArrayOfProduct xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.datacontract.org/2004/07/WebApplication1.Controllers\"><Product><Category>Electronic</Category><Id>1</Id><Name>Television</Name><Price>82000</Price></Product><Product><Category>Electronic</Category><Id>2</Id><Name>Refrigerator</Name><Price>23000</Price></Product><Product><Category>Electronic</Category><Id>3</Id><Name>Mobiles</Name><Price>20000</Price></Product><Product><Category>Electronic</Category><Id>4</Id><Name>Laptops</Name><Price>45000</Price></Product><Product><Category>Electronic</Category><Id>5</Id><Name>iPads</Name><Price>67000</Price></Product><Product><Category>Gift Items</Category><Id>6</Id><Name>Toys</Name><Price>15000</Price></Product></ArrayOfProduct>");

            var testData  = Scrubber.Scrub(xmlDocument.InnerXml);
            var xmlMapper = new XmlMapper();
            var paths     = xmlMapper.Map(testData).ToList();
            var path      = paths.FirstOrDefault();

            var xmlNavigator = new XmlNavigator(testData);

            var          data2    = xmlNavigator.SelectEnumerablesAsRelated(paths);
            const string expected = "Electronic|Electronic|Electronic|Electronic|Electronic|Gift Items";
            var          actual   = string.Join("|", data2[path].Select(s => s.ToString().Trim()));

            Assert.AreEqual(expected, actual);
        }