コード例 #1
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);
        }
コード例 #2
0
        public void SelectEnumerableValuesAsRelatedUsingJsonEnumerablePathsFromJson_Where_PathsContainNestedEnumerablePaths_Expected_FlattenedDataWithValuesFromOuterEnumerablePathRepeatingForEveryValueFromNestedEnumerablePath()
        {
            string testData = GivenJson();

            IPath        enumerableNamePath       = new JsonPath("Departments().Name", "Departments.Name");
            IPath        nestedEnumerableNamePath = new JsonPath("Departments().Employees().Name", "Departments.Employees.Name");
            List <IPath> paths = new List <IPath> {
                enumerableNamePath, nestedEnumerableNamePath
            };

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

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