Esempio n. 1
0
        /// <summary>
        /// Validate Read characters from curent line
        /// </summary>
        /// <param name="nodeName">Name of the node used for different test case.</param>
        private void ValidateChars(string nodeName)
        {
            // Get values from xml
            string FilePath = Utility._xmlUtil.GetTextValue(
                nodeName, Constants.FilePathNode);
            string startIndex = Utility._xmlUtil.GetTextValue(
                nodeName, Constants.CharsStartIndexNode);
            string count = Utility._xmlUtil.GetTextValue(
                nodeName, Constants.CharsCountNode);

            MBFStreamReader streamReader = new MBFStreamReader(FilePath);
            string          currentLine  = streamReader.Line;

            char[] charsArray = streamReader.ReadChars(Int32.Parse(startIndex), Int32.Parse(count));

            // Validate array.
            for (int i = 0; i < charsArray.Length; i++)
            {
                Assert.AreEqual(currentLine[i], charsArray[i]);
                Console.WriteLine("Validated the char {0} successfully", charsArray[i]);
                ApplicationLog.WriteLine("Validated the char successfully");
            }

            // Dispose stream reader.
            streamReader.Close();
            streamReader.Dispose();
        }
Esempio n. 2
0
        public void ValidateMBFStreamReaderProperties()
        {
            // Get values from xml
            string FilePath = Utility._xmlUtil.GetTextValue(
                Constants.SimpleFastAStreamReaderNode, Constants.FilePathNode);
            string newLineCharsCount = Utility._xmlUtil.GetTextValue(
                Constants.SimpleFastAStreamReaderNode, Constants.NewLineCharacterCountNode);
            string pos = Utility._xmlUtil.GetTextValue(
                Constants.SimpleFastAStreamReaderNode, Constants.PositionNode);
            string startingIndex = Utility._xmlUtil.GetTextValue(
                Constants.SimpleFastAStreamReaderNode, Constants.CurrentLineStartingIndexNode);

            MBFStreamReader streamReader = new MBFStreamReader(FilePath, true);

            // Validate Properties
            Assert.IsTrue(streamReader.CanRead);
            Assert.IsTrue(streamReader.SkipBlankLines);
            Assert.IsTrue(streamReader.HasLines);
            Assert.AreEqual(newLineCharsCount,
                            streamReader.NewLineCharacterCount.ToString());
            Assert.AreEqual(pos,
                            streamReader.Position.ToString());
            Assert.AreEqual(newLineCharsCount,
                            streamReader.NewLineCharacterCount.ToString());
            Assert.AreEqual(startingIndex,
                            streamReader.CurrentLineStartingIndex.ToString());

            Console.WriteLine("Validated the StreamReader properties successfully");
            ApplicationLog.WriteLine("Validated the StreamReader properties successfully");

            // Dispose StreamReader.
            streamReader.Close();
            streamReader.Dispose();
        }
Esempio n. 3
0
        /// <summary>
        /// Validate Read Biological sequences using MBFStreamReader
        /// </summary>
        /// <param name="nodeName">Name of the node used for different test case.</param>
        /// <param name="inputType">Different streaming ipnuts used for different test cases</param>
        void ValidateMBFStreamReader(string nodeName,
                                     StreamReaderInputType inputType)
        {
            // Get values from xml
            string FilePath = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.FilePathNode);

            string[] expectedOutput = _utilityObj._xmlUtil.GetTextValues(
                nodeName, Constants.ExpectedLinesNode);
            MBFStreamReader streamReader = null;

            try
            {
                // Read Fasta file.
                switch (inputType)
                {
                case StreamReaderInputType.FileName:
                    streamReader = new MBFStreamReader(FilePath);
                    break;

                case StreamReaderInputType.FileNameWithSkipBlankLines:
                    streamReader = new MBFStreamReader(FilePath, true);
                    break;

                case StreamReaderInputType.Stream:
                    using (Stream stream = new FileStream(FilePath, FileMode.Open,
                                                          FileAccess.ReadWrite))
                    {
                        streamReader = new MBFStreamReader(stream);
                    }
                    break;

                case StreamReaderInputType.StreamWithSkipBlankLines:
                    using (Stream stream = new FileStream(FilePath, FileMode.Open,
                                                          FileAccess.ReadWrite))
                    {
                        streamReader = new MBFStreamReader(stream, true);
                    }
                    break;
                }
                for (int i = 0; i < expectedOutput.Length; i++)
                {
                    Assert.AreEqual(expectedOutput[i], streamReader.Line);

                    Console.WriteLine("Validated the line {0} successfully", streamReader.Line);
                    ApplicationLog.WriteLine("Validated the MBF StreamReader successfully");

                    // Move to next line
                    streamReader.GoToNextLine();
                }
            }
            finally
            {
                if (streamReader != null)
                {
                    streamReader.Dispose();
                }
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Disposes of all resources held by this object.
 /// </summary>
 /// <param name="disposing">If disposing equals true, dispose all resources</param>
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (_mbfStreamReader != null)
         {
             _mbfStreamReader.Dispose();
         }
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Disposes this object.
        /// </summary>
        /// <param name="disposing">If true disposes resourses held by this instance.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_sidecarFileProvider != null)
                {
                    _sidecarFileProvider.Close();
                }

                if (_mbfStreamReader != null)
                {
                    _mbfStreamReader.Dispose();
                }
            }
        }
Esempio n. 6
0
        public void TestMBFTextReaderCoreFunctionality()
        {
            string testFileFullName = @"testdata\Fasta\5_sequences.fasta";

            using (StreamReader streamReader = new StreamReader(testFileFullName))
            {
                using (MBFStreamReader mbfReader = new MBFStreamReader(testFileFullName))
                {
                    //Test line access members.
                    Assert.IsTrue(mbfReader.HasLines);

                    // Test line reads
                    string streamLine = streamReader.ReadLine();
                    Assert.AreEqual(streamLine, mbfReader.Line);

                    // Test getting of line fields
                    Assert.AreEqual(streamLine.Substring(26, 10), mbfReader.GetLineField(27, 36));
                    Assert.AreEqual(streamLine.Substring(14), mbfReader.GetLineField(15));

                    // Test moving to next line
                    mbfReader.GoToNextLine();
                    Assert.AreEqual(streamReader.ReadLine(), mbfReader.Line);

                    char[] streamBuffer = new char[10];
                    char[] bioBuffer;

                    // Test seeking to a position in the stream
                    streamReader.DiscardBufferedData();
                    streamReader.BaseStream.Seek(100, SeekOrigin.Begin);
                    mbfReader.Seek(100, SeekOrigin.Begin);
                    Assert.AreEqual(streamReader.BaseStream.Position, mbfReader.Position);

                    // Test character reading
                    streamReader.ReadBlock(streamBuffer, 0, 10);
                    bioBuffer = mbfReader.ReadChars(100, 10);
                    Assert.AreEqual(streamBuffer, bioBuffer);

                    // Test disposal
                    mbfReader.Dispose();
                    Assert.IsFalse(mbfReader.CanRead);
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Validate Read Biological sequences using MBFStreamReader
        /// </summary>
        /// <param name="nodeName">Name of the node used for different test case.</param>
        /// <param name="IsStartAndEndIndex">True if validating from start to end index substring,
        /// else false</param>
        private void ValidateSubString(string nodeName,
                                       bool IsStartAndEndIndex)
        {
            // Get values from xml
            string FilePath = Utility._xmlUtil.GetTextValue(
                nodeName, Constants.FilePathNode);
            string expectedString = Utility._xmlUtil.GetTextValue(
                nodeName, Constants.ExpectedString);
            string startIndex = Utility._xmlUtil.GetTextValue(
                nodeName, Constants.StartIndexNode);
            string endIndex = Utility._xmlUtil.GetTextValue(
                nodeName, Constants.EndIndexNode);

            string subString = string.Empty;

            MBFStreamReader streamReader = new MBFStreamReader(FilePath);

            if (IsStartAndEndIndex)
            {
                subString = streamReader.GetLineField(Int32.Parse(startIndex),
                                                      Int32.Parse(endIndex));
            }
            else
            {
                subString = streamReader.GetLineField(Int32.Parse(startIndex));
            }

            // Validate sub string of a line.
            Assert.AreEqual(expectedString, subString);
            Console.WriteLine("The expected substring is {0}", subString);
            ApplicationLog.WriteLine("Validated the substring successfully");

            // Dispose stream reader.
            streamReader.Close();
            streamReader.Dispose();
        }