Пример #1
0
        public void Write_OneElementAtEachStep_FileIsCorrectlyBuilt()
        {
            var header = GetHeader();
            var expectedContent = header + "\"p\";\"mg\";\"m1\";\"[m1]\";\"d\";\"[d]\";\"h1\";\"[h1]\";\"l1\";\"[l1]\";\"0\";\"p1\";\"[p1]\"\r\n";
            var expectedFilename = Path.Combine(DiskOnFile.GetDirectoryPath(), "ExpectedCSV-" + MethodBase.GetCurrentMethod() + ".csv");
            if (File.Exists(expectedFilename))
                File.Delete(expectedFilename);
            File.AppendAllText(expectedFilename, expectedContent, Encoding.UTF8);

            var filename = Path.Combine(DiskOnFile.GetDirectoryPath(), @"ActualCSV-" + MethodBase.GetCurrentMethod() + ".csv");

            var metadata = new CubeMetadata();
            var p = new Perspective("p");
            metadata.Perspectives.Add(p);
            var mg = new MeasureGroup("mg");
            p.MeasureGroups.Add(mg);
            var m1 = new Measure("[m1]", "m1", "df");
            mg.Measures.Add(m1);
            var d = new Dimension("[d]", "d");
            mg.LinkedDimensions.Add(d);
            var h1 = new Hierarchy("[h1]", "h1", "df");
            d.Hierarchies.Add(h1);
            var l1 = new Level("[l1]", "l1", 0);
            h1.Levels.Add(l1);
            var p1 = new Property("[p1]", "p1");
            l1.Properties.Add(p1);

            //set the object to test
            var mcw = new MetadataCsvWriter(filename);
            mcw.Write(metadata);

            //Assertion
            FileAssert.AreEqual(expectedFilename, filename);
        }
Пример #2
0
        private void LoadMetadata(XlsMetadata r, bool filter, ref CubeMetadata metadata)
        {
            MeasureGroup mg = null;

            if ((!filter) || r.isChecked)
            {
                metadata.Perspectives.AddOrIgnore(r.perspectiveName);
                var perspective = metadata.Perspectives[r.perspectiveName];

                if (perspective.MeasureGroups.ContainsKey(r.measureGroupName))
                {
                    mg = perspective.MeasureGroups[r.measureGroupName];
                }
                else
                {
                    mg = new MeasureGroup(r.measureGroupName);
                    perspective.MeasureGroups.Add(mg);
                }

                if (!mg.Measures.ContainsKey(r.measureUniqueName))
                {
                    mg.Measures.Add(r.measureUniqueName, r.measureCaption, r.measureDisplayFolder);
                }

                Dimension dim = null;

                if (perspective.Dimensions.ContainsKey(r.dimensionUniqueName))
                {
                    dim = perspective.Dimensions[r.dimensionUniqueName];
                }
                else
                {
                    dim = new Dimension(r.dimensionUniqueName, r.dimensionCaption, new HierarchyCollection());
                    perspective.Dimensions.Add(dim);
                }

                if (!dim.Hierarchies.ContainsKey(r.hierarchyUniqueName))
                {
                    var hierarchy = new Hierarchy(r.hierarchyUniqueName, r.hierarchyCaption, string.Empty);
                    dim.Hierarchies.Add(r.hierarchyUniqueName, hierarchy);
                }

                if (r.levelUniqueName != null)
                {
                    if (!dim.Hierarchies[r.hierarchyUniqueName].Levels.ContainsKey(r.levelUniqueName))
                    {
                        var level = new Level(r.levelUniqueName, r.levelCaption, r.levelNumber);
                        dim.Hierarchies[r.hierarchyUniqueName].Levels.Add(r.levelUniqueName, level);
                    }

                    if (!string.IsNullOrEmpty(r.propertyUniqueName))
                    {
                        if (!dim.Hierarchies[r.hierarchyUniqueName].Levels[r.levelUniqueName].Properties.ContainsKey(r.propertyUniqueName))
                        {
                            var prop = new Property(r.propertyUniqueName, r.propertyCaption);
                            dim.Hierarchies[r.hierarchyUniqueName].Levels[r.levelUniqueName].Properties.Add(r.propertyUniqueName, prop);
                        }
                    }
                }
                if (!mg.LinkedDimensions.ContainsKey(r.dimensionUniqueName))
                    mg.LinkedDimensions.Add(dim);
            }
        }
Пример #3
0
        public void Write_TwoPerspectivesCompletelyDifferent_FileIsCorrectlyBuilt()
        {
            var header = GetHeader();
            var expectedContent = header
                + "\"p1\";\"mg1\";\"m1\";\"[m1]\";\"d1\";\"[d1]\";\"h1\";\"[h1]\";\"l1\";\"[l1]\";\"0\";\"p1\";\"[p1]\"\r\n"
                + "\"p2\";\"mg2\";\"m2\";\"[m2]\";\"d2\";\"[d2]\";\"h2\";\"[h2]\";\"l2\";\"[l2]\";\"0\";\"p2\";\"[p2]\"\r\n"
                ;
            var expectedFilename = Path.Combine(DiskOnFile.GetDirectoryPath(), "ExpectedCSV-" + MethodBase.GetCurrentMethod() + ".csv");
            if (File.Exists(expectedFilename))
                File.Delete(expectedFilename);
            File.AppendAllText(expectedFilename, expectedContent, Encoding.UTF8);

            var filename = Path.Combine(DiskOnFile.GetDirectoryPath(), @"ActualCSV-" + MethodBase.GetCurrentMethod() + ".csv");

            var metadata = new CubeMetadata();
            var pe1 = new Perspective("p1");
            metadata.Perspectives.Add(pe1);
            var mg1 = new MeasureGroup("mg1");
            pe1.MeasureGroups.Add(mg1);
            var m1 = new Measure("[m1]", "m1", "df");
            mg1.Measures.Add(m1);
            var d1 = new Dimension("[d1]", "d1");
            mg1.LinkedDimensions.Add(d1);
            var h1 = new Hierarchy("[h1]", "h1", "df");
            d1.Hierarchies.Add(h1);
            var l1 = new Level("[l1]", "l1", 0);
            h1.Levels.Add(l1);
            var p1 = new Property("[p1]", "p1");
            l1.Properties.Add(p1);

            var pe2 = new Perspective("p2");
            metadata.Perspectives.Add(pe2);
            var mg2 = new MeasureGroup("mg2");
            pe2.MeasureGroups.Add(mg2);
            var m2 = new Measure("[m2]", "m2", "df");
            mg2.Measures.Add(m2);
            var d2 = new Dimension("[d2]", "d2");
            mg2.LinkedDimensions.Add(d2);
            var h2 = new Hierarchy("[h2]", "h2", "df");
            d2.Hierarchies.Add(h2);
            var l2 = new Level("[l2]", "l2", 0);
            h2.Levels.Add(l2);
            var p2 = new Property("[p2]", "p2");
            l2.Properties.Add(p2);

            //set the object to test
            var mcw = new MetadataCsvWriter(filename);
            mcw.Write(metadata);

            //Assertion
            FileAssert.AreEqual(expectedFilename, filename);
        }