private MOIFile ParseMOIExpectSuccess(byte[] moiData)
        {
            MOIFileParser fileParser = new MOIFileParser(moiData);
            bool result = fileParser.Parse();

            Assert.IsTrue(result, "Parsing failed due to the following error: {0}", fileParser.ParseError);

            Assert.NotNull(fileParser.MOIFile, "No MOIFile generated.");
            Assert.Null(fileParser.ParseError, "ParseError should not have been set if parsing succeeded.");

            return fileParser.MOIFile;
        }
Example #2
0
        /// <summary>
        /// This parses the MOI files and populates ParsedMOIFiles and ParseExceptions.
        /// </summary>
        /// <returns>If there were no parsing errors</returns>
        public bool Parse()
        {
            parsedMoiFiles = new List<MOIFile>();
            parseErrors = new List<MOIParserError>();

            //Parse each path to create an MOIFile or ParserError
            foreach (string moiFilePath in moiFilePaths)
            {
                try
                {
                    byte[] moiFileData = File.ReadAllBytes(moiFilePath);
                    MOIFileParser fileParser = new MOIFileParser(moiFileData);

                    if (fileParser.Parse())
                    {
                        fileParser.MOIFile.FileName = Path.GetFileName(moiFilePath);
                        parsedMoiFiles.Add(fileParser.MOIFile);
                    }
                    else
                    {
                        fileParser.ParseError.FilePath = moiFilePath;
                        parseErrors.Add(fileParser.ParseError);
                    }
                }
                catch (Exception e) //if an unexpected error occured, create a ParserError for it.
                {
                    MOIParserError parseError = new MOIParserError(e);
                    parseError.FilePath = moiFilePath;
                    parseErrors.Add(parseError);
                }
            }

            return parseErrors.Count == 0;
        }
        private MOIParserError ParseMOIExpectFail(byte[] moiData)
        {
            MOIFileParser fileParser = new MOIFileParser(moiData);
            bool result = fileParser.Parse();

            Assert.IsFalse(result, "Parsing should have failed");

            Assert.NotNull(fileParser.ParseError, "No ParseError generated.");
            Assert.Null(fileParser.MOIFile, "MOIFile should not have been set if parsing failed.");

            return fileParser.ParseError;
        }