Inheritance: BasePath
        public void GetSegments_Expected_CorrectSegmentCount()
        {
            XmlPath path = new XmlPath("Company.Departments().Department:Name", "Company.Departments.Department:Name");

            const int expected = 4;
            int actual = path.GetSegements().Count();

            Assert.AreEqual(expected, actual);
        }
        public void GetSegments_Expected_LastSegmentIsCorrect()
        {
            XmlPath path = new XmlPath("Company.Departments().Department:Name", "Company.Departments.Department:Name");

            const string expected = "Name";
            string actual = path.GetSegements().Last().ToString();

            Assert.AreEqual(expected, actual);
        }
        public void ToStringOnScalarSegmentt_WhereEnumerablesArentConsidered__Expected_ScalarFormat()
        {
            XmlPath path = new XmlPath();
            IPathSegment segment = path.CreatePathSegment("Name");

            string expected = "Name";
            string actual = segment.ToString(false);

            Assert.AreEqual(expected, actual);
        }
        public void CreateEnumerablePathSegmentFromSegmentText_Expected_EnumerableXmlPathSegment()
        {
            XmlPath path = new XmlPath();
            IPathSegment segment = path.CreatePathSegment("Departments()");

            bool expected = true;
            bool actual = segment.IsEnumarable;

            Assert.AreEqual(expected, actual);
        }
        public void ToStringOnScalarSegment_Expected_ScalarFormat()
        {
            XmlPath path = new XmlPath();
            IPathSegment segment = path.CreatePathSegment("Name");

            string expected = "Name";
            string actual = segment.ToString();

            Assert.AreEqual(expected, actual);
        }
        public void ToStringOnEnumerableSegment_Expected_EnumerableFormat()
        {
            XmlPath path = new XmlPath();
            IPathSegment segment = path.CreatePathSegment("Departments()");

            const string expected = "Departments()";
            string actual = segment.ToString();

            Assert.AreEqual(expected, actual);
        }
        public void ToStringOnEnumerableSegment_WhereEnumerablesAreConsidered_Expected_ScalarFormat()
        {
            XmlPath path = new XmlPath();
            IPathSegment segment = path.CreatePathSegment("Departments()");

            string expected = "Departments()";
            string actual = segment.ToString(true);

            Assert.AreEqual(expected, actual);
        }
        public void CreateScalarPathSegmentFromXElement_Expected_ScalarXmlPathSegment()
        {
            XElement element = new XElement("Departments");
            XmlPath path = new XmlPath();
            IPathSegment segment = path.CreatePathSegment(element);

            const bool expected = false;
            bool actual = segment.IsEnumarable;

            Assert.AreEqual(expected, actual);
        }
        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);
        }
        public void CreateEnumerablePathSegmentFromXElement_Expected_EnumerableXmlPathSegment()
        {
            XElement element = new XElement("Departments",
                new XElement("Department"),
                new XElement("Department"));

            XmlPath path = new XmlPath();
            IPathSegment segment = path.CreatePathSegment(element);

            const bool expected = true;
            bool actual = segment.IsEnumarable;

            Assert.AreEqual(expected, actual);
        }
示例#11
0
        private IPath BuildPath(Stack <Tuple <XElement, bool> > elementStack, XAttribute attribute, XElement root)
        {
            XmlPath path = new XmlPath();

            path.ActualPath = string.Join(XmlPath.NodeSeperatorSymbol, elementStack.Reverse().Select(e => path.CreatePathSegment(e.Item1).ToString(e.Item2)));

            List <Tuple <IPathSegment, bool> > displayPathSegments = elementStack.Reverse().Select(p => new Tuple <IPathSegment, bool>(path.CreatePathSegment(p.Item1), p.Item2)).ToList();
            bool recordsetEncountered = false;

            for (int i = displayPathSegments.Count - 1; i >= 0; i--)
            {
                Tuple <IPathSegment, bool> pathSegment = displayPathSegments[i];
                if (recordsetEncountered)
                {
                    pathSegment.Item1.IsEnumarable = false;
                }

                if (pathSegment.Item1.IsEnumarable && pathSegment.Item2)
                {
                    recordsetEncountered = true;
                }
            }

            path.DisplayPath = string.Join(XmlPath.NodeSeperatorSymbol, displayPathSegments.Select(p => p.Item1.ToString(p.Item2)));

            if (path.ActualPath != string.Empty)
            {
                path.ActualPath += XmlPath.AttributeSeperatorSymbol;
            }

            if (path.DisplayPath != string.Empty)
            {
                path.DisplayPath += XmlPath.AttributeSeperatorSymbol;
            }

            path.ActualPath  += path.CreatePathSegment(attribute).ToString();
            path.DisplayPath += path.CreatePathSegment(attribute).ToString();
            path.SampleData  += GetSampleData(root, path);

            return(path);
        }
示例#12
0
        public IEnumerable <object> SelectEnumerable(IPath path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            XmlPath xmlPath = path as XmlPath;

            if (xmlPath == null)
            {
                throw new Exception(string.Format("Path of type '{0}' expected, path of type '{1}' received.", typeof(XmlPath), path.GetType()));
            }

            XDocument document = Data as XDocument;

            if (document == null)
            {
                throw new Exception(string.Format("Type of {0} was expected for data, type of {1} was found instead.", typeof(XDocument), Data.GetType()));
            }

            List <object> returnData     = null;
            XElement      currentElement = document.Root;

            if (path.ActualPath == XmlPath.NodeSeperatorSymbol)
            {
                if (currentElement != null)
                {
                    returnData = new List <object> {
                        currentElement.ToString()
                    };
                }
            }
            else
            {
                List <IPathSegment> pathSegments = new List <IPathSegment>(xmlPath.GetSegements());
                returnData = new List <object>(SelectEnumberable(pathSegments.Skip(1).ToList(), pathSegments.FirstOrDefault(), currentElement));
            }

            return(returnData);
        }
        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 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);
        }
        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 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);
        }
示例#21
0
        public void SelectScalarValueUsingPocoScalarPathFromXml_Expected_ScalarValue()
        {
            string testData = GivenXml();

            IPath namePath = new XmlPath("Company:Name", "Company:Name");
            IDataBrowser dataBrowser = DataBrowserFactory.CreateDataBrowser();

            object data = dataBrowser.SelectScalar(namePath, testData);

            Assert.AreEqual(data, "Dev2");
        }
        public void CreateScalarPathSegmentFromSegmentText_Expected_ScalarXmlPathSegment()
        {
            XmlPath path = new XmlPath();
            IPathSegment segment = path.CreatePathSegment("Name");

            const bool expected = false;
            bool actual = segment.IsEnumarable;

            Assert.AreEqual(expected, actual);
        }
        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_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);
        }
示例#25
0
        public object SelectScalar(IPath path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            XmlPath xmlPath = path as XmlPath;

            if (xmlPath == null)
            {
                throw new Exception(string.Format("Path of type '{0}' expected, path of type '{1}' received.", typeof(XmlPath), path.GetType()));
            }

            XDocument document = Data as XDocument;

            if (document == null)
            {
                throw new Exception(string.Format("Type of {0} was expected for data, type of {1} was found instead.", typeof(XDocument), Data.GetType()));
            }

            string   returnData     = string.Empty;
            XElement currentElement = document.Root;

            if (path.ActualPath == XmlPath.NodeSeperatorSymbol)
            {
                if (currentElement != null)
                {
                    returnData = currentElement.ToString();
                }
            }
            else
            {
                List <XmlPathSegment> pathSegments = new List <XmlPathSegment>(xmlPath.GetSegements().OfType <XmlPathSegment>());
                int segmentIndex = 0;

                while (currentElement != null && segmentIndex < pathSegments.Count)
                {
                    if (segmentIndex == 0 && currentElement.Name != pathSegments[segmentIndex].ActualSegment)
                    {
                        currentElement = null;
                        returnData     = null;
                    }
                    else if (segmentIndex == 0 && pathSegments.Count == 1 && currentElement.Name == pathSegments[segmentIndex].ActualSegment)
                    {
                        returnData = currentElement.Value;
                    }
                    else if (segmentIndex > 0)
                    {
                        if (pathSegments[segmentIndex].IsAttribute)
                        {
                            XAttribute attribute = currentElement.Attribute(pathSegments[segmentIndex].ActualSegment);

                            if (attribute != null)
                            {
                                currentElement = null;
                                returnData     = attribute.Value;
                            }
                        }
                        else
                        {
                            currentElement = currentElement.Elements(pathSegments[segmentIndex].ActualSegment).LastOrDefault();
                            // Travis.Frisinger : 09/10/2012 - Fix for null element, naughty Brendan ;)
                            if (currentElement != null)
                            {
                                returnData = currentElement.Value;
                            }
                            else
                            {
                                returnData = string.Empty;
                            }
                        }
                    }

                    segmentIndex++;
                }
            }

            return(returnData);
        }
        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 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 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);
        }
示例#29
0
        private IPath BuildPath(Stack<Tuple<XElement, bool>> elementStack, XAttribute attribute, XElement root)
        {
            var path = new XmlPath();

            path.ActualPath = string.Join(XmlPath.NodeSeperatorSymbol,
                elementStack.Reverse().Select(e => path.CreatePathSegment(e.Item1).ToString(e.Item2)));

            List<Tuple<IPathSegment, bool>> displayPathSegments =
                elementStack.Reverse()
                    .Select(p => new Tuple<IPathSegment, bool>(path.CreatePathSegment(p.Item1), p.Item2))
                    .ToList();
            bool recordsetEncountered = false;

            for (int i = displayPathSegments.Count - 1; i >= 0; i--)
            {
                Tuple<IPathSegment, bool> pathSegment = displayPathSegments[i];
                if (recordsetEncountered)
                {
                    pathSegment.Item1.IsEnumarable = false;
                }

                if (pathSegment.Item1.IsEnumarable && pathSegment.Item2) recordsetEncountered = true;
            }

            path.DisplayPath = string.Join(XmlPath.NodeSeperatorSymbol,
                displayPathSegments.Select(p => p.Item1.ToString(p.Item2)));

            if (path.ActualPath != string.Empty)
            {
                path.ActualPath += XmlPath.AttributeSeperatorSymbol;
            }

            if (path.DisplayPath != string.Empty)
            {
                path.DisplayPath += XmlPath.AttributeSeperatorSymbol;
            }

            path.ActualPath += path.CreatePathSegment(attribute).ToString();
            path.DisplayPath += path.CreatePathSegment(attribute).ToString();
            path.SampleData += GetSampleData(root, path);

            return path;
        }
        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 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);
        }
示例#32
0
        public void SelectEnumerableValuesAsRelatedUsingPocoEnumerablePathsFromXml_Where_PathsContainNestedEnumerablePaths_Expected_FlattenedDataWithValuesFromOuterEnumerablePathRepeatingForEveryValueFromNestedEnumerablePath()
        {
            string testData = GivenXml();

            XmlPath enumerableNamePath = new XmlPath("Company.Departments().Department:Name", "Company.Departments.Department:Name");
            XmlPath nestedEnumerableNamePath = new XmlPath("Company.Departments().Department.Employees().Person:Name", "Company.Departments.Department.Employees.Person:Name");
            List<IPath> paths = new List<IPath> { enumerableNamePath, nestedEnumerableNamePath };

            IDataBrowser dataBrowser = DataBrowserFactory.CreateDataBrowser();
            Dictionary<IPath, IList<object>> data = dataBrowser.SelectEnumerablesAsRelated(paths, testData);

            const string expected = "Dev|Dev|Accounts|Accounts^Brendon|Jayd|Bob|Joe";
            string actual = string.Join("|", data[enumerableNamePath]);
            actual += "^" + string.Join("|", data[nestedEnumerableNamePath]);

            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);
        }