public void AddDimensionLevelTest1()
 {
     Dimension target = new Dimension();
     List<Dimension> l = new List<Dimension>() { new Dimension() };
     target.AddDimensionLevel(l);
     Assert.AreEqual(l[0], target.GetCoarserDimensionLevel()[0]);
 }
 public void AddDimensionLevelTest()
 {
     Dimension target = new Dimension();
     Dimension d = new Dimension();
     target.AddDimensionLevel(d);
     Assert.AreEqual(d, target.GetCoarserDimensionLevel()[0]);
 }
        public void GetLevelTest()
        {
            Dimension target = new Dimension();
            Dimension d1 = new Dimension();
            Dimension d2 = new Dimension();
            d1.AddDimensionLevel(d2);
            target.AddDimensionLevel(d1);

            List<Dimension> actual = target.GetLevel();
            Assert.AreEqual(actual.Count, 3);
        }
        /// <summary>
        /// This takes a tablename (most likely "FACT") and loads all foreign keys, which should point to a dimension (Table + column).
        /// It creates a List of Dimensions and adds a dimension for each row the Database returns. It then goes on recursively 
        /// and grabs the Table + Column of the "next" Table, meaning the one you end up at, if you roll up the cube.
        /// Note that in this piece of code a dimension may have MULTIPLE sub-ListOfDimensions, which should not exist in the model, 
        /// but IF they do, it's not a problem at this point (but rather a GUI-problem)
        /// </summary>
        /// <param name="tablename">The Name of the Table whose ListOfDimensions are to be found.</param>
        /// <returns>A list of ListOfDimensions which, most likely, contain even more ListOfDimensions themselves.</returns>
        /// <author>Jannik Arndt, Bernd Nottbeck</author>
        public List<Dimension> GetDimensionsOf(String tablename)
        {
            DataTable referencedTables;
            DataTable dimensionContentDataTable;
            List<Dimension> resultingListOfDimensions = new List<Dimension>();

            try
            {
                Open();

                // every table row is a dimension
                referencedTables = GetReferencingDataTable(tablename);

                foreach (DataRow referencedTableRow in referencedTables.Rows)
                {
                    // create a dimension-object (see MetaWorker.Dimension)
                    Dimension newDimension = new Dimension(referencedTableRow["FromColumn"].ToString(), referencedTableRow["FromConstraint"].ToString(),
                        referencedTableRow["FromTable"].ToString(), referencedTableRow["FromColumn"].ToString(),
                        referencedTableRow["ToConstraint"].ToString(), referencedTableRow["ToTable"].ToString(), referencedTableRow["ToColumn"].ToString());

                    // Load the content of this table
                    dimensionContentDataTable = GetTableContent(referencedTableRow["ToTable"].ToString());

                    // create DimensionContent-Objects and add them to the current dimension
                    foreach (DataRow dimensionContentRow in dimensionContentDataTable.Rows)
                    {
                        string description = "";
                        if (dimensionContentRow.ItemArray.Count() > 2)
                            description = dimensionContentRow[2].ToString();
                        newDimension.DimensionContentsList.Add(new DimensionContent(dimensionContentRow[0].ToString(), dimensionContentRow[1].ToString(), description));
                    }

                    // save the DimensionColumnNames for generated DB-querys
                    newDimension.DimensionColumnNames = new DimensionColumnNames(dimensionContentDataTable.Columns[0].ColumnName,
                        dimensionContentDataTable.Columns[1].ColumnName, dimensionContentDataTable.Columns[2].ColumnName);

                    dimensionContentDataTable.Reset();
                    // now recursively find all sub-ListOfDimensions of this Table and add them to the current dimension
                    newDimension.AddDimensionLevel(GetDimensionsOf(referencedTableRow["ToTable"].ToString()));

                    // add the current dimension to the list that will be returned eventually
                    resultingListOfDimensions.Add(newDimension);
                }
                return resultingListOfDimensions;
            }
            finally
            {
                Close();
            }
        }