Beispiel #1
0
        public void ToStringOnEnumerableSegment_WhereEnumerablesArentConsidered_Expected_ScalarFormat()
        {
            PocoPath     path    = new PocoPath();
            IPathSegment segment = path.CreatePathSegment("Collection()");

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

            Assert.AreEqual(expected, actual);
        }
Beispiel #2
0
        public void ToStringOnScalarSegmentt_WhereEnumerablesAreConsidered__Expected_ScalarFormat()
        {
            PocoPath     path    = new PocoPath();
            IPathSegment segment = path.CreatePathSegment("Name");

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

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

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

            Assert.AreEqual(expected, actual);
        }
Beispiel #4
0
        public void ToStringOnEnumerableSegment_Expected_EnumerableFormat()
        {
            PocoPath     path    = new PocoPath();
            IPathSegment segment = path.CreatePathSegment("Collection()");

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

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

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

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

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

            Assert.AreEqual(expected, actual);
        }
Beispiel #7
0
        public void CreateScalarPathSegmentFromPropertyInfo_Expected_ScalarPocoPathSegment()
        {
            var propertyInfo = typeof(PocoTestData).GetProperty("Name");
            var path         = new PocoPath();
            var segment      = path.CreatePathSegment(propertyInfo.Name, propertyInfo.PropertyType.IsEnumerable());

            const bool expected = false;
            var        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.Name, propertyInfo.PropertyType.IsEnumerable());

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

            Assert.AreEqual(expected, actual);
        }
        public void SelectScalarValueUsingRootPathFromPrimitive_Expected_ScalarValue()
        {
            PocoTestData testData = Given();

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

            PocoNavigator pocoNavigator = new PocoNavigator(1);

            object data = pocoNavigator.SelectScalar(path);

            Assert.AreEqual(data, "1");
        }
Beispiel #10
0
        public void SelectEnumerableValuesAsRelatedFromReferenceType_Where_PathsContainNestedEnumerablePaths_Expected_FlattenedDataWithValuesFromOuterEnumerablePathRepeatingForEveryValueFromNestedEnumerablePath()
        {
            var testData = GivenWithParallelAndNestedEnumerables();

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

            var pocoNavigator = new PocoNavigator(testData);
            var data          = pocoNavigator.SelectEnumerablesAsRelated(paths);

            var tmpExpected  = "";
            var tmpExpected1 = "";
            var 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;
                    }
                }
            }

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

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

            Assert.AreEqual(expected, actual);
        }
Beispiel #11
0
        public void SelectEnumerableValuesAsRelatedFromReferenceType_Where_PathsContainUnrelatedEnumerablePaths_Expected_FlattenedDataWithValuesFromUnrelatedEnumerablePathsAtMatchingIndexes()
        {
            var testData = GivenWithParallelAndNestedEnumerables();

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

            var pocoNavigator = new PocoNavigator(testData);
            var data          = pocoNavigator.SelectEnumerablesAsRelated(paths);

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

            var tmpExpected  = "";
            var tmpExpected1 = "";
            var 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;
                }
            }

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

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

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

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

            PocoNavigator pocoNavigator = new PocoNavigator(testData);

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

            Assert.AreEqual(expected, actual);
        }
        public void SelectEnumerableValuesUsingRootPathFromPrimitive_Expected_SingleValueInEnumeration()
        {
            PocoTestData testData = Given();

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

            PocoNavigator pocoNavigator = new PocoNavigator(1);

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

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

            Assert.AreEqual(expected, actual);
        }
Beispiel #14
0
        public void SelectEnumerableValuesUsingScalarPathFromEnumerable_Expected_SingleValueInEnumeration()
        {
            var testData = Given();

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

            var pocoNavigator = new PocoNavigator(testData);

            var data = pocoNavigator.SelectEnumerable(namePath);

            var expected = testData.EnumerableData.Count.ToString();
            var actual   = string.Join("", data.Select(o => o.ToString()));

            Assert.AreEqual(expected, actual);
        }
Beispiel #15
0
        public void SelectEnumerableValuesUsingEnumerableReferenceType_Expected_ValuesFromEachItemInEnumeration()
        {
            var testData = Given();

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

            var pocoNavigator = new PocoNavigator(testData.EnumerableData);

            var data = pocoNavigator.SelectEnumerable(namePath);

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

            Assert.AreEqual(expected, actual);
        }