Inheritance: Dev2.Converters.Graph.NavigatorBase, INavigator
        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;
        }
Exemplo n.º 2
0
        public void SelectEnumerableValuesUsingScalarPathFromReferenceType_Expected_SingleValueInEnumeration()
        {
            PocoTestData testData = Given();

            IPath namePath = new PocoPath("NestedData.Name", "NestedData.Name");

            PocoNavigator pocoNavigator = new PocoNavigator(testData);

            IEnumerable<object> data = pocoNavigator.SelectEnumerable(namePath);

            string expected = testData.NestedData.Name;
            string actual = string.Join("", data.Select(o => o.ToString()));

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 3
0
        public void SelectEnumerableValuesUsingEnumerablePathFromReferenceType_Where_EnumerableDataIsNull_Expected_Null()
        {
            PocoTestData testData = GivenWithNoEnumerableData();

            IPath namePath = new PocoPath("EnumerableData().Name", "EnumerableData.Name");

            PocoNavigator pocoNavigator = new PocoNavigator(testData);

            object data = pocoNavigator.SelectScalar(namePath);

            Assert.AreEqual(data, null);
        }
Exemplo n.º 4
0
        public void SelectEnumerableValuesUsingEnumerablePathFromReferenceType_Expected_ValuesFromEachItemInEnumeration()
        {
            PocoTestData testData = Given();

            IPath namePath = new PocoPath("EnumerableData().Name", "EnumerableData.Name");

            PocoNavigator pocoNavigator = new PocoNavigator(testData);

            IEnumerable<object> data = pocoNavigator.SelectEnumerable(namePath);

            string expected = string.Join("|", testData.EnumerableData.Select(e => e.Name));
            string actual = string.Join("|", data.Select(o => o.ToString()));

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 5
0
        public void SelectScalarValueUsingEnumerablePathFromReferenceType_Expected_ScalarValueFromLastItemInEnumerableCollection()
        {
            PocoTestData testData = Given();

            IPath namePath = new PocoPath("EnumerableData().NestedData.Name", "EnumerableData.NestedData.Name");

            PocoNavigator pocoNavigator = new PocoNavigator(testData);

            object data = pocoNavigator.SelectScalar(namePath);

            Assert.AreEqual(data, testData.EnumerableData.ElementAt(testData.EnumerableData.Count - 1).NestedData.Name);
        }
Exemplo n.º 6
0
        public void SelectScalarValueUsingScalarPathFromReferenceType_Expected_ScalarValue()
        {
            PocoTestData testData = Given();

            IPath namePath = new PocoPath("Name", "Name");

            PocoNavigator pocoNavigator = new PocoNavigator(testData);

            object data = pocoNavigator.SelectScalar(namePath);

            Assert.AreEqual(data, testData.Name);
        }
Exemplo n.º 7
0
        public void SelectScalarValueUsingScalarPathFromEnumerable_Expected_ScalarValue()
        {
            PocoTestData testData = Given();

            IPath path = new PocoPath("EnumerableData.Count", "EnumerableData.Count");

            PocoNavigator pocoNavigator = new PocoNavigator(testData);

            object data = pocoNavigator.SelectScalar(path);

            Assert.AreEqual(data, testData.EnumerableData.Count);
        }
Exemplo n.º 8
0
 private string GetSampleData(object root, IPath path)
 {
     var navigator = new PocoNavigator(root);
     return string.Join(GlobalConstants.AnythingToXmlPathSeperator,
         navigator.SelectEnumerable(path)
             .Select(
                 o =>
                     o.ToString()
                         .Replace(GlobalConstants.AnythingToXmlPathSeperator,
                             GlobalConstants.AnytingToXmlCommaToken))
             .Take(10));
 }
Exemplo n.º 9
0
        public void SelectEnumerableValuesUsingRootPathFromEnumerableContainingOnlyPrimitives_Expected_ValuesForEachValueInEnumeration()
        {
            List<int> testData = new List<int> { 1, 2, 3 };

            IPath path = new PocoPath("().", "().");
            List<IPath> paths = new List<IPath> { path };

            PocoNavigator pocoNavigator = new PocoNavigator(testData);

            Dictionary<IPath, IList<object>> data = pocoNavigator.SelectEnumerablesAsRelated(paths);

            string expected = string.Join("|", testData.Select(e => e));
            string actual = string.Join("|", data[path]);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 10
0
        public void SelectScalarValueUsingRootPathFromEnumerableContainingOnlyPrimitives_Expected_LastScalarValueInEnumeration()
        {
            List<int> testData = new List<int> { 1, 2, 3 };

            IPath namePath = new PocoPath("().", "().");

            PocoNavigator pocoNavigator = new PocoNavigator(testData);

            const string expected = "3";
            string actual = pocoNavigator.SelectScalar(namePath).ToString();

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 11
0
        public void SelectEnumerableValuesAsRelatedUsingRootPathFromPrimitive_Expected_SingleValueInEnumeration()
        {
            Given();

            IPath path = new PocoPath(PocoPath.SeperatorSymbol, PocoPath.SeperatorSymbol);
            List<IPath> paths = new List<IPath> { path };

            PocoNavigator pocoNavigator = new PocoNavigator(1);

            Dictionary<IPath, IList<object>> data = pocoNavigator.SelectEnumerablesAsRelated(paths);

            const string expected = "1";
            string actual = string.Join("|", data[path]);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 12
0
        public void SelectEnumerableValuesUsingRootPathFromPrimitive_Expected_SingleValueInEnumeration()
        {
            Given();

            IPath path = new PocoPath(PocoPath.SeperatorSymbol, PocoPath.SeperatorSymbol);

            PocoNavigator pocoNavigator = new PocoNavigator(1);

            IEnumerable<object> data = pocoNavigator.SelectEnumerable(path);

            const string expected = "1";
            string actual = string.Join("", data.Select(o => o.ToString()));

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 13
0
        public void SelectScalarValueUsingRootPathFromPrimitive_Expected_ScalarValue()
        {
            Given();

            IPath path = new PocoPath(PocoPath.SeperatorSymbol, PocoPath.SeperatorSymbol);

            PocoNavigator pocoNavigator = new PocoNavigator(1);

            object data = pocoNavigator.SelectScalar(path);

            Assert.AreEqual(data, "1");
        }
Exemplo n.º 14
0
        public void SelectEnumerableValuesAsRelatedFromReferenceType_Where_PathsContainNestedEnumerablePaths_Expected_FlattenedDataWithValuesFromOuterEnumerablePathRepeatingForEveryValueFromNestedEnumerablePath()
        {
            PocoTestData testData = GivenWithParallelAndNestedEnumerables();

            PocoPath enumerableNamePath = new PocoPath("EnumerableData().Name", "EnumerableData.Name");
            PocoPath nestedEnumerableNamePath = new PocoPath("EnumerableData().EnumerableData().Name", "EnumerableData.EnumerableData.Name");
            List<IPath> paths = new List<IPath> { enumerableNamePath, nestedEnumerableNamePath };

            PocoNavigator pocoNavigator = new PocoNavigator(testData);
            Dictionary<IPath, IList<object>> data = pocoNavigator.SelectEnumerablesAsRelated(paths);

            #region Complex Setup for Expected

            //
            // The code in this region is used to setup the exprected value.
            // It can't be reused for other tests and can't be made generic
            // without replicating the funcationality being tested.
            //
            string tmpExpected = "";
            string tmpExpected1 = "";
            string separator = "|";

            for (int outerCount = 0; outerCount < testData.EnumerableData.Count; outerCount++)
            {
                for (int innerCount = 0; innerCount < testData.EnumerableData[outerCount].EnumerableData.Count; innerCount++)
                {
                    if (outerCount == testData.EnumerableData.Count - 1 && innerCount == testData.EnumerableData[outerCount].EnumerableData.Count - 1) separator = "";
                    if (outerCount < testData.EnumerableData.Count)
                    {
                        tmpExpected += testData.EnumerableData[outerCount].Name + separator;
                    }
                    else
                    {
                        tmpExpected += separator;
                    }

                    if (innerCount < testData.EnumerableData[outerCount].EnumerableData.Count)
                    {
                        tmpExpected1 += testData.EnumerableData[outerCount].EnumerableData[innerCount].Name + separator;
                    }
                    else
                    {
                        tmpExpected1 += separator;
                    }
                }
            }

            #endregion Complex Setup for Expected

            string expected = tmpExpected + "^" + tmpExpected1;
            string actual = string.Join("|", data[enumerableNamePath]);
            actual += "^" + string.Join("|", data[nestedEnumerableNamePath]);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 15
0
        public void SelectEnumerableValuesAsRelatedUsingRootPathFromEnumerableContainingOnlyPrimitives_Expected_ValuesForEachValueInEnumeration()
        {
            List<int> testData = new List<int> { 1, 2, 3 };

            IPath path = new PocoPath("().", "().");

            PocoNavigator pocoNavigator = new PocoNavigator(testData);

            IEnumerable<object> data = pocoNavigator.SelectEnumerable(path);

            string expected = string.Join("|", testData.Select(e => e));
            string actual = string.Join("|", data.Select(o => o.ToString()));

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 16
0
        public void SelectEnumerableValuesAsRelatedFromReferenceType_Where_PathsContainASinglePathWhichIsScalar_Expected_FlattenedDataWithValueFromScalarPath()
        {
            PocoTestData testData = GivenWithParallelAndNestedEnumerables();

            PocoPath namePath = new PocoPath("Name", "Name");
            List<IPath> paths = new List<IPath> { namePath };

            PocoNavigator pocoNavigator = new PocoNavigator(testData);
            Dictionary<IPath, IList<object>> data = pocoNavigator.SelectEnumerablesAsRelated(paths);

            string expected = testData.Name;
            string actual = string.Join("|", data[namePath]);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 17
0
        private string GetSampleData(object root, IPath path)
        {
            PocoNavigator navigator = new PocoNavigator(root);

            return(string.Join(GlobalConstants.AnythingToXmlPathSeperator, navigator.SelectEnumerable(path).Select(o => o.ToString().Replace(GlobalConstants.AnythingToXmlPathSeperator, GlobalConstants.AnytingToXmlCommaToken)).Take(10)));
        }