Inheritance: BasePath
Exemplo n.º 1
0
        public void GetSegments_Expected_LastSegmentIsCorrect()
        {
            PocoPath path = new PocoPath("EnumerableData().NestedData.NestedData.Name", "EnumerableData.NestedData.NestedData.Name");

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

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 2
0
        public void GetSegments_Expected_CorrectSegmentCount()
        {
            PocoPath path = new PocoPath("EnumerableData().NestedData.Name", "EnumerableData.NestedData.Name");

            int expected = 3;
            int actual = path.GetSegements().Count();

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

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

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

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

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 5
0
        public void CreateScalarPathSegmentFromPropertyInfo_Expected_ScalarPocoPathSegment()
        {
            PropertyInfo propertyInfo = typeof(PocoTestData).GetProperty("Name");
            PocoPath path = new PocoPath();
            IPathSegment segment = path.CreatePathSegment(propertyInfo);

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

            Assert.AreEqual(expected, actual);
        }
        public void CreateEnumerablePathSegmentFromPropertyInfo_Expected_EnumerablePocoPathSegment()
        {
            PropertyInfo propertyInfo = typeof(PocoTestData).GetProperty("EnumerableData");
            PocoPath path = new PocoPath();
            IPathSegment segment = path.CreatePathSegment(propertyInfo);

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

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 7
0
        private IPath BuildPath(Stack <Tuple <PropertyInfo, bool, object> > propertyStack, PropertyInfo property,
                                object root)
        {
            var path = new PocoPath();

            path.ActualPath = string.Join(PocoPath.SeperatorSymbol,
                                          propertyStack.Reverse().Select(p => path.CreatePathSegment(p.Item1).ToString(p.Item2)));

            List <Tuple <IPathSegment, bool> > displayPathSegments =
                propertyStack.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(PocoPath.SeperatorSymbol,
                                           displayPathSegments.Select(p => p.Item1.ToString(p.Item2)));

            if (path.ActualPath != string.Empty)
            {
                path.ActualPath += PocoPath.SeperatorSymbol;
            }

            if (path.DisplayPath != string.Empty)
            {
                path.DisplayPath += PocoPath.SeperatorSymbol;
            }

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

            return(path);
        }
Exemplo n.º 8
0
        IPath BuildPath(Stack <Tuple <string, bool, bool, object> > propertyStack, string name, bool isEnumerable)
        {
            var path = new PocoPath();

            path.ActualPath = string.Join(PocoPath.SeperatorSymbol,
                                          propertyStack.Reverse().Select(p => path.CreatePathSegment(p.Item1, p.Item2).ToString(p.Item3)));

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

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

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

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

            if (path.ActualPath != string.Empty)
            {
                path.ActualPath += PocoPath.SeperatorSymbol;
            }

            if (path.DisplayPath != string.Empty)
            {
                path.DisplayPath += PocoPath.SeperatorSymbol;
            }

            path.ActualPath  += path.CreatePathSegment(name, isEnumerable);
            path.DisplayPath += path.CreatePathSegment(name, isEnumerable);

            return(path);
        }
Exemplo n.º 9
0
        public IEnumerable <object> SelectEnumerable(IPath path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            PocoPath pocoPath = path as PocoPath;

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

            List <object> returnData;

            if (path.ActualPath == PocoPath.SeperatorSymbol)
            {
                returnData = new List <object> {
                    Data
                };
            }
            else if (path.ActualPath == PocoPath.EnumerableSymbol + PocoPath.SeperatorSymbol)
            {
                IEnumerable enumerableData = Data as IEnumerable;
                returnData = new List <object>();

                if (enumerableData != null)
                {
                    IEnumerator enumerator = enumerableData.GetEnumerator();
                    enumerator.Reset();
                    while (enumerator.MoveNext())
                    {
                        returnData.Add(enumerator.Current);
                    }
                }
            }
            else
            {
                returnData = SelectEnumberable(pocoPath.GetSegements().ToList(), Data).ToList();
            }

            return(returnData);
        }
Exemplo n.º 10
0
        private IPath BuildPath(Stack<Tuple<PropertyInfo, bool, object>> propertyStack, PropertyInfo property,
            object root)
        {
            var path = new PocoPath();

            path.ActualPath = string.Join(PocoPath.SeperatorSymbol,
                propertyStack.Reverse().Select(p => path.CreatePathSegment(p.Item1).ToString(p.Item2)));

            List<Tuple<IPathSegment, bool>> displayPathSegments =
                propertyStack.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(PocoPath.SeperatorSymbol,
                displayPathSegments.Select(p => p.Item1.ToString(p.Item2)));

            if (path.ActualPath != string.Empty)
            {
                path.ActualPath += PocoPath.SeperatorSymbol;
            }

            if (path.DisplayPath != string.Empty)
            {
                path.DisplayPath += PocoPath.SeperatorSymbol;
            }

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

            return path;
        }
Exemplo n.º 11
0
        public void SelectEnumerableValueUsingPocoEnumerablePathFromReferenceType_Expected_ValuesFromEachItemInEnumeration()
        {
            PocoTestData testData = GivenPoco();

            IPath namePath = new PocoPath("EnumerableData().Name", "EnumerableData.Name");
            IDataBrowser dataBrowser = DataBrowserFactory.CreateDataBrowser();

            IEnumerable<object> data = dataBrowser.SelectEnumerable(namePath, testData);

            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.º 12
0
        public void SelectEnumerableValuesAsRelatedFromReferenceType_Where_PathsContainUnrelatedEnumerablePaths_Expected_FlattenedDataWithValuesFromUnrelatedEnumerablePathsAtMatchingIndexes()
        {
            PocoTestData testData = GivenWithParallelAndNestedEnumerables();

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

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

            int maxCount = Math.Max(testData.EnumerableData.Count, testData.EnumerableData1.Count);

            #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 i = 0; i < maxCount; i++)
            {
                if (i == maxCount - 1) separator = "";

                if (i < testData.EnumerableData.Count)
                {
                    tmpExpected += testData.EnumerableData[i].Name + separator;
                }
                else
                {
                    tmpExpected += separator;
                }

                if (i < testData.EnumerableData1.Count)
                {
                    tmpExpected1 += testData.EnumerableData1[i].Name + separator;
                }
                else
                {
                    tmpExpected1 += separator;
                }
            }

            #endregion Complex Setup for Expected

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

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 13
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.º 14
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.º 15
0
        public void CreateScalarPathSegmentFromSegmentText_Expected_ScalarPocoPathSegment()
        {
            PocoPath path = new PocoPath();
            IPathSegment segment = path.CreatePathSegment("Name");

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

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 16
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.º 17
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.º 18
0
        public void CreateEnumerablePathSegmentFromSegmentText_Expected_EnumerablePocoPathSegment()
        {
            PocoPath path = new PocoPath();
            IPathSegment segment = path.CreatePathSegment("EnumerableData()");

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

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 19
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.º 20
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.º 21
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.º 22
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.º 23
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.º 24
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.º 25
0
        public object SelectScalar(IPath path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            PocoPath pocoPath = path as PocoPath;

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

            object currentData = Data;

            if (path.ActualPath == PocoPath.SeperatorSymbol)
            {
                currentData = Data.ToString();
            }
            else if (path.ActualPath == PocoPath.EnumerableSymbol + PocoPath.SeperatorSymbol)
            {
                IEnumerable enumerableData = currentData as IEnumerable;

                if (enumerableData == null)
                {
                    currentData = null;
                }
                else
                {
                    IEnumerator enumerator = enumerableData.GetEnumerator();
                    enumerator.Reset();
                    while (enumerator.MoveNext())
                    {
                        currentData = enumerator.Current;
                    }
                }
            }
            else
            {
                List <IPathSegment> pathSegments = pocoPath.GetSegements().ToList();
                int segmentIndex = 0;

                while (currentData != null && segmentIndex < pathSegments.Count)
                {
                    if (pathSegments[segmentIndex].IsEnumarable)
                    {
                        IEnumerable enumerableData = GetEnumerableValueForPathSegment(pathSegments[segmentIndex], currentData);

                        if (enumerableData == null)
                        {
                            currentData = null;
                        }
                        else
                        {
                            IEnumerator enumerator = enumerableData.GetEnumerator();
                            enumerator.Reset();
                            while (enumerator.MoveNext())
                            {
                                currentData = enumerator.Current;
                            }
                        }
                    }
                    else
                    {
                        currentData = GetScalarValueForPathSegement(pathSegments[segmentIndex], currentData);
                    }

                    segmentIndex++;
                }
            }

            return(currentData);
        }
Exemplo n.º 26
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.º 27
0
        public void SelectScalarValueUsingPocoScalarPathFromReferenceType_Expected_ScalarValue()
        {
            PocoTestData testData = GivenPoco();

            IPath namePath = new PocoPath("Name", "Name");
            IDataBrowser dataBrowser = DataBrowserFactory.CreateDataBrowser();

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

            Assert.AreEqual(data, testData.Name);
        }
Exemplo n.º 28
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.º 29
0
        public void SelectEnumerableValuesAsRelatedUsingPocoEnumerablePathsFromReferenceType_Where_PathsContainNestedEnumerablePaths_Expected_FlattenedDataWithValuesFromOuterEnumerablePathRepeatingForEveryValueFromNestedEnumerablePath()
        {
            PocoTestData testData = GivenPocoWithParallelAndNestedEnumerables();

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

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

            #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.º 30
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);
        }