コード例 #1
0
        protected void ParseFile(string fileName, params IModelParser[] additionalParsers)
        {
            string methodName = new StackTrace().GetFrame(1).GetMethod().Name.Replace("_", "-");

            FileInfo file = new FileInfo(fileName);

            Assert.That(file.Exists, Is.True, "File doesn't exist {0}", fileName);

            FileReader          reader = new FileReader(fileName);
            List <IModelParser> list   = new List <IModelParser> {
                new T()
            };

            if (additionalParsers.Length > 0)
            {
                list.AddRange(additionalParsers);
            }
            IDataParser dataParser = new DataParser(reader, list.ToArray());

            dataParser.OnMissingParser = s =>
            {
                Assert.Fail("Unable to Parse: {0}", reader);
                return(false);
            };
            dataParser.Parse();

            Assert.That(dataParser.Results, Is.Not.Empty, "Results should not be empty");
            Assert.That(dataParser.Results[0], Is.TypeOf <ClassModel>(), "Expected a Class Model");

            ClassModel classModel = dataParser.Results[0] as ClassModel;

            Assert.That(classModel, Is.Not.Null, "Class Model not found: {0}", dataParser.Results[0]);
            if (classModel != null)
            {
                Assert.That(file.Name, Is.StringContaining(classModel.Data), "Class name doesn't match the filename");
                Assert.That(classModel.Data, Is.EqualTo(methodName), "Class name doesn't match the method name");
            }
        }
コード例 #2
0
        public void SystemBlockTests()
        {
            IReader reader = new FileReader(@".\Resources\DataDictionary\datadict.rpt");

            IModelParser[] parsers = new IModelParser[] {
                new AccessInformationParser(),
                new DescriptionParser(),
                new DetailsParser(),
                new ModifiedParser(),
                new ModuleParser(),
                new PageHeaderParser(),
                new RecordLengthParser(),
                new RecordParser(),
                new TechnicalInformationParser(),
                new CobolBlockParser(),
            };
            IDataParser dataParser = new DataParser(reader, parsers);

            dataParser.Corrections     = corrections;
            dataParser.OnMissingParser = (line) => {
                throw new InvalidOperationException("No Parser for: " + reader);
            };
            dataParser.Parse();
        }
コード例 #3
0
 public void HeaderSystemTests()
 {
     IReader reader = new FileReader(@".\Resources\DataDictionary\datadict.rpt");
     IModelParser[] parsers = new IModelParser[] {
             new PageHeaderParser(),
             new AccessInformationParser(),
             new DescriptionParser(),
             new DetailsParser(),
             new ModifiedParser(),
             new ModuleParser(),
             new RecordLengthParser(),
             new RecordParser(),
             new TechnicalInformationParser(),
             CobolParser.CobolHierarchy(),
             new IgnoreParser(),
         };
     IDataParser dataParser = new DataParser(reader, parsers);
     dataParser.Corrections = corrections;
     dataParser.OnMissingParser = (line) =>
     {
         throw new InvalidOperationException("No Parser for: " + reader);
     };
     dataParser.Parse();
 }
コード例 #4
0
        public void HierarchySystemTests()
        {
            IReader reader = new FileReader(@".\Resources\DataDictionary\datadict.rpt");

            IModelParser[] parsers = new IModelParser[] {
                new AccessInformationParser(),
                new DescriptionParser(),
                new DetailsParser(),
                new ModifiedParser(),
                new ModuleParser(),
                new PageHeaderParser(),
                new RecordLengthParser(),
                new RecordParser(),
                new TechnicalInformationParser(),
                CobolParser.CobolHierarchy(),
                new IgnoreParser(),
            };
            IDataParser dataParser = new DataParser(reader, parsers);

            dataParser.Corrections     = corrections;
            dataParser.OnMissingParser = (line) =>
            {
                throw new InvalidOperationException("No Parser for: " + reader);
            };
            dataParser.Parse();

            string typename  = GetType().Name;
            string directory = Path.Combine(".", typename);

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            foreach (IModel model in dataParser.Results)
            {
                HierarchyModel hiearchyModel = model as HierarchyModel;
                if (hiearchyModel != null)
                {
                    ClassModel classModel = hiearchyModel.Model as ClassModel;
                    if (classModel != null)
                    {
                        ModelXmlFormatter formatter  = new ModelXmlFormatter(model);
                        string            xml        = formatter.Render();
                        string            objectName = classModel.Data;

                        string fileName = directory + @"\" + objectName + ".xml";
                        if (File.Exists(fileName))
                        {
                            File.Delete(fileName);
                        }

                        Assert.That(File.Exists(fileName), Is.False);
                        using (StreamWriter writer = new StreamWriter(fileName))
                        {
                            writer.Write(xml);
                        }
                    }
                }
            }
        }
コード例 #5
0
        public void HierarchySystemTests()
        {
            IReader reader = new FileReader(@".\Resources\DataDictionary\datadict.rpt");
            IModelParser[] parsers = new IModelParser[] {
                    new AccessInformationParser(),
                    new DescriptionParser(),
                    new DetailsParser(),
                    new ModifiedParser(),
                    new ModuleParser(),
                    new PageHeaderParser(),
                    new RecordLengthParser(),
                    new RecordParser(),
                    new TechnicalInformationParser(),
                    CobolParser.CobolHierarchy(),
                    new IgnoreParser(),
                };
            IDataParser dataParser = new DataParser(reader, parsers);
            dataParser.Corrections = corrections;
            dataParser.OnMissingParser = (line) =>
            {
                throw new InvalidOperationException("No Parser for: " + reader);
            };
            dataParser.Parse();

            string typename = GetType().Name;
            string directory = Path.Combine(".", typename);

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            foreach (IModel model in dataParser.Results)
            {
                HierarchyModel hiearchyModel = model as HierarchyModel;
                if (hiearchyModel != null)
                {
                    ClassModel classModel = hiearchyModel.Model as ClassModel;
                    if (classModel != null)
                    {
                        ModelXmlFormatter formatter = new ModelXmlFormatter(model);
                        string xml = formatter.Render();
                        string objectName = classModel.Data;

                        string fileName = directory + @"\" + objectName + ".xml";
                        if (File.Exists(fileName))
                        {
                            File.Delete(fileName);
                        }

                        Assert.That(File.Exists(fileName), Is.False);
                        using (StreamWriter writer = new StreamWriter(fileName))
                        {
                            writer.Write(xml);
                        }
                    }
                }
            }
        }