<commit_before>﻿using System.IO;
using System.Reflection;
using System.Text;
using NBi.Core.Analysis.Metadata;
using NUnit.Framework;

namespace NBi.Testing.Unit.Core.Analysis.Metadata
{
    [TestFixture]
    public class MetadataCsvReaderTest
    {
        [Test]
        public void Read_SimpleLine_PerspectiveIsCorrectlyRead()
        {
            var header = GetHeader();
            var testContent = header + "\"p\";\"mg\";\"m1\";\"[m1]\";\"df\";\"d\";\"[d]\";\"h1\";\"[h1]\";\"l1\";\"[l1]\";\"0\";\"p1\";\"[p1]\"\r\n";
            var testFilename = Path.Combine(DiskOnFile.GetDirectoryPath(), string.Format("ReadCSV-{0}.csv", MethodInfo.GetCurrentMethod()));
            if (File.Exists(testFilename))
                File.Delete(testFilename);
            File.AppendAllText(testFilename, testContent, Encoding.UTF8);

            //set the object to test
            var mcr = new MetadataCsvReader(testFilename);
            var metadata = mcr.Read();

            //Assertion
            Assert.That(metadata.Perspectives.Count, Is.EqualTo(1));
            Assert.That(metadata.Perspectives["p"].Name, Is.EqualTo("p"));
        }

        [Test]
        public void Read_TwoLinesWithPerspectivesCompletelyDifferent_PerspectiveAreCorrectlyRead()
        {
            var header = GetHeader();
            var testContent = header
                + "\"p1\";\"mg1\";\"m1\";\"[m1]\";\"df\";\"d1\";\"[d1]\";\"h1\";\"[h1]\";\"l1\";\"[l1]\";\"0\";\"p1\";\"[p1]\"\r\n"
                + "\"p2\";\"mg2\";\"m2\";\"[m2]\";\"df\";\"d2\";\"[d2]\";\"h2\";\"[h2]\";\"l2\";\"[l2]\";\"0\";\"p2\";\"[p2]\"\r\n"
                ;
            var testFilename = Path.Combine(DiskOnFile.GetDirectoryPath(), string.Format("ReadCSV-{0}.csv", MethodInfo.GetCurrentMethod()));
            if (File.Exists(testFilename))
                File.Delete(testFilename);
            File.AppendAllText(testFilename, testContent, Encoding.UTF8);

            //set the object to test
            var mcr = new MetadataCsvReader(testFilename);
            var metadata = mcr.Read();

            //Assertion
            Assert.That(metadata.Perspectives.Count, Is.EqualTo(2));
            Assert.That(metadata.Perspectives["p1"].Name, Is.EqualTo("p1"));
            Assert.That(metadata.Perspectives["p2"].Name, Is.EqualTo("p2"));
        }


        [Test]
        public void Read_TwoMeasureGroups_MeasureGroupsAreCorrectlyRead()
        {
            var header = GetHeader();
            var testContent = header
                + "\"p\";\"mg1\";\"m1\";\"[m1]\";\"df\";\"d1\";\"[d1]\";\"h1\";\"[h1]\";\"l1\";\"[l1]\";\"0\";\"p1\";\"[p1]\"\r\n"
                + "\"p\";\"mg2\";\"m2\";\"[m2]\";\"df\";\"d1\";\"[d1]\";\"h1\";\"[h1]\";\"l1\";\"[l1]\";\"0\";\"p1\";\"[p1]\"\r\n"
                ;
            var testFilename = Path.Combine(DiskOnFile.GetDirectoryPath(), string.Format("ReadCSV-{0}.csv", MethodInfo.GetCurrentMethod()));
            if (File.Exists(testFilename))
                File.Delete(testFilename);
            File.AppendAllText(testFilename, testContent, Encoding.UTF8);
            
            //set the object to test
            var mcr = new MetadataCsvReader(testFilename);
            var metadata = mcr.Read();

            //Assertion
            Assert.That(metadata.Perspectives["p"].MeasureGroups.Count, Is.EqualTo(2));
            Assert.That(metadata.Perspectives["p"].MeasureGroups["mg1"].Name, Is.EqualTo("mg1"));
            Assert.That(metadata.Perspectives["p"].MeasureGroups["mg2"].Name, Is.EqualTo("mg2"));
        }


        [Test]
        public void Read_TwoDimensionsSameMeasureGroup_DimensionsAreCorrectlyRead()
        {
            var header = GetHeader();
            var testContent = header
                + "\"p\";\"mg\";\"m1\";\"[m1]\";\"df\";\"d1\";\"[d1]\";\"h1\";\"[h1]\";\"l1\";\"[l1]\";\"0\";\"p1\";\"[p1]\"\r\n"
                + "\"p\";\"mg\";\"m1\";\"[m1]\";\"df\";\"d2\";\"[d2]\";\"h2\";\"[h2]\";\"l2\";\"[l2]\";\"1\";\"p2\";\"[p2]\"\r\n"
                ;
            var testFilename = Path.Combine(DiskOnFile.GetDirectoryPath(), string.Format("ReadCSV-{0}.csv", MethodInfo.GetCurrentMethod()));
            if (File.Exists(testFilename))
                File.Delete(testFilename);
            File.AppendAllText(testFilename, testContent, Encoding.UTF8);

            //set the object to test
            var mcr = new MetadataCsvReader(testFilename);
            var metadata = mcr.Read();

            //Assertion
            Assert.That(metadata.Perspectives["p"].MeasureGroups["mg"].LinkedDimensions.Count, Is.EqualTo(2));
            Assert.That(metadata.Perspectives["p"].MeasureGroups["mg"].LinkedDimensions["[d1]"].Caption, Is.EqualTo("d1"));
            Assert.That(metadata.Perspectives["p"].MeasureGroups["mg"].LinkedDimensions["[d2]"].Caption, Is.EqualTo("d2"));
            Assert.That(metadata.Perspectives["p"].MeasureGroups["mg"].LinkedDimensions["[d1]"].UniqueName, Is.EqualTo("[d1]"));
            Assert.That(metadata.Perspectives["p"].MeasureGroups["mg"].LinkedDimensions["[d2]"].UniqueName, Is.EqualTo("[d2]"));
        }


        [Test]
        public void Read_TwoHierarchiesSameDimension_HierarchiesAreCorrectlyRead()
        {
            var header = GetHeader();
            var testContent = header
                + "\"p\";\"mg\";\"m1\";\"[m1]\";\"df\";\"d1\";\"[d1]\";\"h1\";\"[h1]\";\"l1\";\"[l1]\";\"0\";\"p1\";\"[p1]\"\r\n"
                + "\"p\";\"mg\";\"m1\";\"[m1]\";\"df\";\"d1\";\"[d1]\";\"h2\";\"[h2]\";\"l2\";\"[l2]\";\"1\";\"p2\";\"[p2]\"\r\n"
                ;
            var testFilename = Path.Combine(DiskOnFile.GetDirectoryPath(), string.Format("ReadCSV-{0}.csv", MethodInfo.GetCurrentMethod()));
            if (File.Exists(testFilename))
                File.Delete(testFilename);
            File.AppendAllText(testFilename, testContent, Encoding.UTF8);


            //set the object to test
            var mcr = new MetadataCsvReader(testFilename);
            var metadata = mcr.Read();

            var dim = metadata.Perspectives["p"].MeasureGroups["mg"].LinkedDimensions["[d1]"];
            //Assertion
            Assert.That(dim.Hierarchies.Count, Is.EqualTo(2));
            Assert.That(dim.Hierarchies["[h1]"].Caption, Is.EqualTo("h1"));
            Assert.That(dim.Hierarchies["[h2]"].Caption, Is.EqualTo("h2"));
            Assert.That(dim.Hierarchies["[h1]"].UniqueName, Is.EqualTo("[h1]"));
            Assert.That(dim.Hierarchies["[h2]"].UniqueName, Is.EqualTo("[h2]"));
        }

        [Test]
        public void Read_TwoLevelsSameHierarchy_LevelsAreCorrectlyRead()
        {
            var header = GetHeader();
            var testContent = header
                + "\"p\";\"mg\";\"m1\";\"[m1]\";\"df\";\"d\";\"[d]\";\"h1\";\"[h1]\";\"l1\";\"[l1]\";\"0\";\"p1\";\"[p1]\"\r\n"
                + "\"p\";\"mg\";\"m1\";\"[m1]\";\"df\";\"d\";\"[d]\";\"h1\";\"[h1]\";\"l2\";\"[l2]\";\"1\";\"p2\";\"[p2]\"\r\n"
                ;
            var testFilename = Path.Combine(DiskOnFile.GetDirectoryPath(), string.Format("ReadCSV-{0}.csv", MethodInfo.GetCurrentMethod()));
            if (File.Exists(testFilename))
                File.Delete(testFilename);
            File.AppendAllText(testFilename, testContent, Encoding.UTF8);

            //set the object to test
            var mcr = new MetadataCsvReader(testFilename);
            var metadata = mcr.Read();

            var hie = metadata.Perspectives["p"].MeasureGroups["mg"].LinkedDimensions["[d]"].Hierarchies["[h1]"];
            
            //Assertion
            Assert.That(hie.Levels.Count, Is.EqualTo(2));
            Assert.That(hie.Levels["[l1]"].Caption, Is.EqualTo("l1"));
            Assert.That(hie.Levels["[l2]"].Caption, Is.EqualTo("l2"));
            Assert.That(hie.Levels["[l1]"].UniqueName, Is.EqualTo("[l1]"));
            Assert.That(hie.Levels["[l2]"].UniqueName, Is.EqualTo("[l2]"));
            Assert.That(hie.Levels["[l1]"].Number, Is.EqualTo(0));
            Assert.That(hie.Levels["[l2]"].Number, Is.EqualTo(1));
        }

        /// <summary>
        /// //////////////////////////////////////////////////////////////////////////////////////////////
        /// </summary>
        [Test]
        public void Read_NoPropertyForTheLevel_PropertyCountIsEqualToZero()
        {
            var header = GetHeader();
            var testContent = header + "\"p\";\"mg\";\"m1\";\"[m1]\";\"df\";\"d\";\"[d]\";\"h1\";\"[h1]\";\"l1\";\"[l1]\";\"0\";\"\";\"\"\r\n";
            var testFilename = Path.Combine(DiskOnFile.GetDirectoryPath(), string.Format("ReadCSV-{0}.csv", MethodInfo.GetCurrentMethod()));
            if (File.Exists(testFilename))
                File.Delete(testFilename);
            File.AppendAllText(testFilename, testContent, Encoding.UTF8);

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

            //set the object to test
            var mcr = new MetadataCsvReader(testFilename);
            var metadata = mcr.Read();

            var lev = metadata.Perspectives["p"].MeasureGroups["mg"].LinkedDimensions["[d]"].Hierarchies["[h1]"].Levels["[l1]"];

            //Assertion
            Assert.That(lev.Properties.Count, Is.EqualTo(0));
        }
<commit_msg>Removed useless code line in a test<commit_after>﻿using System.IO;
using System.Reflection;
using System.Text;
using NBi.Core.Analysis.Metadata;
using NUnit.Framework;

namespace NBi.Testing.Unit.Core.Analysis.Metadata
{
    [TestFixture]
    public class MetadataCsvReaderTest
    {
        [Test]
        public void Read_SimpleLine_PerspectiveIsCorrectlyRead()
        {
            var header = GetHeader();
            var testContent = header + "\"p\";\"mg\";\"m1\";\"[m1]\";\"df\";\"d\";\"[d]\";\"h1\";\"[h1]\";\"l1\";\"[l1]\";\"0\";\"p1\";\"[p1]\"\r\n";
            var testFilename = Path.Combine(DiskOnFile.GetDirectoryPath(), string.Format("ReadCSV-{0}.csv", MethodInfo.GetCurrentMethod()));
            if (File.Exists(testFilename))
                File.Delete(testFilename);
            File.AppendAllText(testFilename, testContent, Encoding.UTF8);

            //set the object to test
            var mcr = new MetadataCsvReader(testFilename);
            var metadata = mcr.Read();

            //Assertion
            Assert.That(metadata.Perspectives.Count, Is.EqualTo(1));
            Assert.That(metadata.Perspectives["p"].Name, Is.EqualTo("p"));
        }

        [Test]
        public void Read_TwoLinesWithPerspectivesCompletelyDifferent_PerspectiveAreCorrectlyRead()
        {
            var header = GetHeader();
            var testContent = header
                + "\"p1\";\"mg1\";\"m1\";\"[m1]\";\"df\";\"d1\";\"[d1]\";\"h1\";\"[h1]\";\"l1\";\"[l1]\";\"0\";\"p1\";\"[p1]\"\r\n"
                + "\"p2\";\"mg2\";\"m2\";\"[m2]\";\"df\";\"d2\";\"[d2]\";\"h2\";\"[h2]\";\"l2\";\"[l2]\";\"0\";\"p2\";\"[p2]\"\r\n"
                ;
            var testFilename = Path.Combine(DiskOnFile.GetDirectoryPath(), string.Format("ReadCSV-{0}.csv", MethodInfo.GetCurrentMethod()));
            if (File.Exists(testFilename))
                File.Delete(testFilename);
            File.AppendAllText(testFilename, testContent, Encoding.UTF8);

            //set the object to test
            var mcr = new MetadataCsvReader(testFilename);
            var metadata = mcr.Read();

            //Assertion
            Assert.That(metadata.Perspectives.Count, Is.EqualTo(2));
            Assert.That(metadata.Perspectives["p1"].Name, Is.EqualTo("p1"));
            Assert.That(metadata.Perspectives["p2"].Name, Is.EqualTo("p2"));
        }


        [Test]
        public void Read_TwoMeasureGroups_MeasureGroupsAreCorrectlyRead()
        {
            var header = GetHeader();
            var testContent = header
                + "\"p\";\"mg1\";\"m1\";\"[m1]\";\"df\";\"d1\";\"[d1]\";\"h1\";\"[h1]\";\"l1\";\"[l1]\";\"0\";\"p1\";\"[p1]\"\r\n"
                + "\"p\";\"mg2\";\"m2\";\"[m2]\";\"df\";\"d1\";\"[d1]\";\"h1\";\"[h1]\";\"l1\";\"[l1]\";\"0\";\"p1\";\"[p1]\"\r\n"
                ;
            var testFilename = Path.Combine(DiskOnFile.GetDirectoryPath(), string.Format("ReadCSV-{0}.csv", MethodInfo.GetCurrentMethod()));
            if (File.Exists(testFilename))
                File.Delete(testFilename);
            File.AppendAllText(testFilename, testContent, Encoding.UTF8);
            
            //set the object to test
            var mcr = new MetadataCsvReader(testFilename);
            var metadata = mcr.Read();

            //Assertion
            Assert.That(metadata.Perspectives["p"].MeasureGroups.Count, Is.EqualTo(2));
            Assert.That(metadata.Perspectives["p"].MeasureGroups["mg1"].Name, Is.EqualTo("mg1"));
            Assert.That(metadata.Perspectives["p"].MeasureGroups["mg2"].Name, Is.EqualTo("mg2"));
        }


        [Test]
        public void Read_TwoDimensionsSameMeasureGroup_DimensionsAreCorrectlyRead()
        {
            var header = GetHeader();
            var testContent = header
                + "\"p\";\"mg\";\"m1\";\"[m1]\";\"df\";\"d1\";\"[d1]\";\"h1\";\"[h1]\";\"l1\";\"[l1]\";\"0\";\"p1\";\"[p1]\"\r\n"
                + "\"p\";\"mg\";\"m1\";\"[m1]\";\"df\";\"d2\";\"[d2]\";\"h2\";\"[h2]\";\"l2\";\"[l2]\";\"1\";\"p2\";\"[p2]\"\r\n"
                ;
            var testFilename = Path.Combine(DiskOnFile.GetDirectoryPath(), string.Format("ReadCSV-{0}.csv", MethodInfo.GetCurrentMethod()));
            if (File.Exists(testFilename))
                File.Delete(testFilename);
            File.AppendAllText(testFilename, testContent, Encoding.UTF8);

            //set the object to test
            var mcr = new MetadataCsvReader(testFilename);
            var metadata = mcr.Read();

            //Assertion
            Assert.That(metadata.Perspectives["p"].MeasureGroups["mg"].LinkedDimensions.Count, Is.EqualTo(2));
            Assert.That(metadata.Perspectives["p"].MeasureGroups["mg"].LinkedDimensions["[d1]"].Caption, Is.EqualTo("d1"));
            Assert.That(metadata.Perspectives["p"].MeasureGroups["mg"].LinkedDimensions["[d2]"].Caption, Is.EqualTo("d2"));
            Assert.That(metadata.Perspectives["p"].MeasureGroups["mg"].LinkedDimensions["[d1]"].UniqueName, Is.EqualTo("[d1]"));
            Assert.That(metadata.Perspectives["p"].MeasureGroups["mg"].LinkedDimensions["[d2]"].UniqueName, Is.EqualTo("[d2]"));
        }


        [Test]
        public void Read_TwoHierarchiesSameDimension_HierarchiesAreCorrectlyRead()
        {
            var header = GetHeader();
            var testContent = header
                + "\"p\";\"mg\";\"m1\";\"[m1]\";\"df\";\"d1\";\"[d1]\";\"h1\";\"[h1]\";\"l1\";\"[l1]\";\"0\";\"p1\";\"[p1]\"\r\n"
                + "\"p\";\"mg\";\"m1\";\"[m1]\";\"df\";\"d1\";\"[d1]\";\"h2\";\"[h2]\";\"l2\";\"[l2]\";\"1\";\"p2\";\"[p2]\"\r\n"
                ;
            var testFilename = Path.Combine(DiskOnFile.GetDirectoryPath(), string.Format("ReadCSV-{0}.csv", MethodInfo.GetCurrentMethod()));
            if (File.Exists(testFilename))
                File.Delete(testFilename);
            File.AppendAllText(testFilename, testContent, Encoding.UTF8);


            //set the object to test
            var mcr = new MetadataCsvReader(testFilename);
            var metadata = mcr.Read();

            var dim = metadata.Perspectives["p"].MeasureGroups["mg"].LinkedDimensions["[d1]"];
            //Assertion
            Assert.That(dim.Hierarchies.Count, Is.EqualTo(2));
            Assert.That(dim.Hierarchies["[h1]"].Caption, Is.EqualTo("h1"));
            Assert.That(dim.Hierarchies["[h2]"].Caption, Is.EqualTo("h2"));
            Assert.That(dim.Hierarchies["[h1]"].UniqueName, Is.EqualTo("[h1]"));
            Assert.That(dim.Hierarchies["[h2]"].UniqueName, Is.EqualTo("[h2]"));
        }

        [Test]
        public void Read_TwoLevelsSameHierarchy_LevelsAreCorrectlyRead()
        {
            var header = GetHeader();
            var testContent = header
                + "\"p\";\"mg\";\"m1\";\"[m1]\";\"df\";\"d\";\"[d]\";\"h1\";\"[h1]\";\"l1\";\"[l1]\";\"0\";\"p1\";\"[p1]\"\r\n"
                + "\"p\";\"mg\";\"m1\";\"[m1]\";\"df\";\"d\";\"[d]\";\"h1\";\"[h1]\";\"l2\";\"[l2]\";\"1\";\"p2\";\"[p2]\"\r\n"
                ;
            var testFilename = Path.Combine(DiskOnFile.GetDirectoryPath(), string.Format("ReadCSV-{0}.csv", MethodInfo.GetCurrentMethod()));
            if (File.Exists(testFilename))
                File.Delete(testFilename);
            File.AppendAllText(testFilename, testContent, Encoding.UTF8);

            //set the object to test
            var mcr = new MetadataCsvReader(testFilename);
            var metadata = mcr.Read();

            var hie = metadata.Perspectives["p"].MeasureGroups["mg"].LinkedDimensions["[d]"].Hierarchies["[h1]"];
            
            //Assertion
            Assert.That(hie.Levels.Count, Is.EqualTo(2));
            Assert.That(hie.Levels["[l1]"].Caption, Is.EqualTo("l1"));
            Assert.That(hie.Levels["[l2]"].Caption, Is.EqualTo("l2"));
            Assert.That(hie.Levels["[l1]"].UniqueName, Is.EqualTo("[l1]"));
            Assert.That(hie.Levels["[l2]"].UniqueName, Is.EqualTo("[l2]"));
            Assert.That(hie.Levels["[l1]"].Number, Is.EqualTo(0));
            Assert.That(hie.Levels["[l2]"].Number, Is.EqualTo(1));
        }

        /// <summary>
        /// //////////////////////////////////////////////////////////////////////////////////////////////
        /// </summary>
        [Test]
        public void Read_NoPropertyForTheLevel_PropertyCountIsEqualToZero()
        {
            var header = GetHeader();
            var testContent = header + "\"p\";\"mg\";\"m1\";\"[m1]\";\"df\";\"d\";\"[d]\";\"h1\";\"[h1]\";\"l1\";\"[l1]\";\"0\";\"\";\"\"\r\n";
            var testFilename = Path.Combine(DiskOnFile.GetDirectoryPath(), string.Format("ReadCSV-{0}.csv", MethodInfo.GetCurrentMethod()));
            if (File.Exists(testFilename))
                File.Delete(testFilename);
            File.AppendAllText(testFilename, testContent, Encoding.UTF8);

            //set the object to test
            var mcr = new MetadataCsvReader(testFilename);
            var metadata = mcr.Read();

            var lev = metadata.Perspectives["p"].MeasureGroups["mg"].LinkedDimensions["[d]"].Hierarchies["[h1]"].Levels["[l1]"];

            //Assertion
            Assert.That(lev.Properties.Count, Is.EqualTo(0));
        }

{'fraction_non_alphanumeric': 0.2323649199022536, 'fraction_numerical': 0.020526744501764865, 'mean_word_length': 2.1806563039723663, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1115007', 'n_tokens_mistral': 6190, 'n_tokens_neox': 6093, 'n_words': 668}