示例#1
0
        public void EqualsTest()
        {
            Stream cs1Stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Citities.Library.Test.Files.Cs1.txt");

            StreamReader cs1Reader = new StreamReader(cs1Stream);
            string cs1Text = cs1Reader.ReadToEnd();

            CsParser cs1Parser = new CsParser();
            ParseResult cs1Result = cs1Parser.Parse(cs1Text);
            Entity cs1Entity1 = new Entity(cs1Result, DateTime.Now, 1);
            Entity cs1Entity2 = new Entity(cs1Result, DateTime.Now, 2);
            Entity cs1Entity3 = new Entity(cs1Result, DateTime.Now, 1);

            Stream cs2Stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Citities.Library.Test.Files.Cs2.txt");
            StreamReader cs2Reader = new StreamReader(cs2Stream);
            string cs2Text = cs2Reader.ReadToEnd();

            CsParser cs2Parser = new CsParser();
            ParseResult cs2Result = cs2Parser.Parse(cs2Text);
            Entity cs2Entity1 = new Entity(cs2Result, DateTime.Now, 1);
            Entity cs2Entity2 = new Entity(cs2Result, DateTime.Now, 2);

            Assert.AreNotEqual(cs2Entity2, cs2Entity1);
            Assert.AreNotEqual(cs1Entity2, cs1Entity1);
            Assert.AreEqual(cs1Entity1, cs1Entity3);
        }
示例#2
0
        public void GetAggragationsTest()
        {
            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Citities.Library.Test.Files.Cs1.txt"))
            {
                StreamReader reader = new StreamReader(stream);
                string text = reader.ReadToEnd();

                CsParser csParser = new CsParser();
                List<string> aggragations = csParser.GetAggragations(CsParser.RemoveComments(text));
                string value = "int,char,int,int,int,String,String,String,String,String,int,int,int,int,String,int,String,String,String,String,String,String,String,String,String,String,string,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,TypeCode,CharEnumerator";
                Assert.AreEqual(value, string.Join(",", aggragations));

            }

            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Citities.Library.Test.Files.Cs2.txt"))
            {
                StreamReader reader = new StreamReader(stream);
                string text = reader.ReadToEnd();

                CsParser csParser = new CsParser();
                List<string> aggragations = csParser.GetAggragations(text);
                string value = string.Join(",", aggragations);
                Assert.AreEqual(value, string.Join(",", aggragations));
            }
        }
示例#3
0
        public void GetNamespaceTest()
        {
            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Citities.Library.Test.Files.Cs1.txt"))
            {
                StreamReader reader = new StreamReader(stream);
                string text = reader.ReadToEnd();

                CsParser csParser = new CsParser();
                string nameSpace = csParser.GetNamespace(text);
                Assert.AreEqual("System", nameSpace);
            }

            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Citities.Library.Test.Files.Cs2.txt"))
            {
                StreamReader reader = new StreamReader(stream);
                string text = reader.ReadToEnd();

                CsParser csParser = new CsParser();
                string nameSpace = csParser.GetNamespace(text);
                Assert.AreEqual("System.Collections.Generic", nameSpace);
            }
        }
示例#4
0
        public void GetInheritanceTest()
        {
            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Citities.Library.Test.Files.Cs1.txt"))
            {
                StreamReader reader = new StreamReader(stream);
                string text = reader.ReadToEnd();

                CsParser csParser = new CsParser();
                string test = CsParser.RemoveComments(text);
                string inheritance = csParser.GetInheritance(test);
                Assert.AreEqual("IComparable", inheritance);
            }

            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Citities.Library.Test.Files.Cs2.txt"))
            {
                StreamReader reader = new StreamReader(stream);
                string text = reader.ReadToEnd();

                CsParser csParser = new CsParser();
                string inheritance = csParser.GetInheritance(CsParser.RemoveComments(text));
                Assert.AreEqual("IDictionary<TKey,TValue>", inheritance);
            }
        }
示例#5
0
        /// <summary>
        /// Creates a collection of entities from a collection go IFiles.
        /// </summary>
        /// <returns>The entities.</returns>
        /// <param name="files">Files.</param>
        public static EntityCollection MakeEntities(IEnumerable<IFile> files)
        {
            EntityCollection entities = new EntityCollection();

            ParallelOptions parallelOptions = new ParallelOptions
            {
                    MaxDegreeOfParallelism = 8
            };

            switch (CheckProjectType(files))
            {
                case ProjectType.CSharp:
                    CsParser csParser = new CsParser();
                    Parallel.ForEach(files.Where(x => Path.GetExtension(x.Path) == ".cs"), parallelOptions, item => {
                        entities.Add(csParser.Parse(item), item.Date.DateTime, item.Revisions);
                    });
                    break;

                case ProjectType.Unicon:
                    IcnParser icnParser = new IcnParser();
                    Parallel.ForEach(files.Where(x => Path.GetExtension(x.Path) == ".icn"), parallelOptions, item => {
                        entities.Add(icnParser.Parse(item), item.Date.DateTime, item.Revisions);
                    });
                    break;

                case ProjectType.Java:
                    JavaParser javaParser = new JavaParser();
                    Parallel.ForEach(files.Where(x => Path.GetExtension(x.Path) == ".java"), parallelOptions, item => {
                        entities.Add(javaParser.Parse(item), item.Date.DateTime, item.Revisions);
                    });
                    break;
            }

            return entities;
        }
示例#6
0
        public void GetTypeTest()
        {
            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Citities.Library.Test.Files.Cs1.txt"))
            {
                StreamReader reader = new StreamReader(stream);
                string text = reader.ReadToEnd();

                CsParser csParser = new CsParser();
                string type = csParser.GetClassName(CsParser.RemoveComments(text));
                Assert.AreEqual("String", type);
            }

            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Citities.Library.Test.Files.Cs2.txt"))
            {
                StreamReader reader = new StreamReader(stream);
                string text = reader.ReadToEnd();

                CsParser csParser = new CsParser();
                string type = csParser.GetClassName(CsParser.RemoveComments(text));
                Assert.AreEqual("Dictionary", type);
            }
        }