public void GffFormatterValidateOpen() { using (GffFormatter formatter = new GffFormatter()) { try { formatter.Open(Constants.GffTempFileName); } catch (System.IO.IOException exception) { Assert.Fail("Exception thrown on opening a file " + exception.Message); } } ApplicationLog.WriteLine("Opened the file successfully"); }
public void GffFormatterValidateStreams() { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue(Constants.SimpleGffNodeName, Constants.FilePathNode); Assert.IsTrue(File.Exists(filePath)); IList <ISequence> seqs = null; Sequence originalSequence = null; using (GffParser parserObj = new GffParser(filePath)) { seqs = parserObj.Parse().ToList(); originalSequence = (Sequence)seqs[0]; } // Use the formatter to write the original sequences to a temp file ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Gff Formatter BVT: Creating the Temp file '{0}'.", Constants.GffTempFileName)); using (StreamWriter writer = new StreamWriter(Constants.GffTempFileName)) { using (GffFormatter formatter = new GffFormatter()) { formatter.ShouldWriteSequenceData = true; formatter.Open(writer); formatter.Write(originalSequence); } } // Read the new file, then compare the sequences IList <ISequence> seqsNew = null; using (GffParser newParser = new GffParser(Constants.GffTempFileName)) { seqsNew = newParser.Parse().ToList(); } Assert.IsNotNull(seqsNew); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Gff Formatter BVT: New Sequence is '{0}'.", seqsNew[0].ToString())); bool val = ValidateFeatures(seqsNew[0], Constants.SimpleGffNodeName); Assert.IsTrue(val); ApplicationLog.WriteLine( "GFF Formatter BVT : All the features validated successfully."); // Now compare the sequences. int countNew = seqsNew.Count(); int expectedCount = 1; Assert.AreEqual(expectedCount, countNew); ApplicationLog.WriteLine("The Number of sequences are matching."); Assert.AreEqual(originalSequence.ID, seqsNew[0].ID); ISequence newSeq = seqsNew.FirstOrDefault(); Assert.AreEqual(new string(originalSequence.Select(x => (char)x).ToArray()), new string(newSeq.Select(x => (char)x).ToArray())); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Gff Formatter BVT: The Gff sequences '{0}' are matching with Write() method.", seqsNew[0].ToString())); // Passed all the tests, delete the tmp file. If we failed an Assert, // the tmp file will still be there in case we need it for debugging. if (File.Exists(Constants.GffTempFileName)) { File.Delete(Constants.GffTempFileName); } ApplicationLog.WriteLine("Deleted the temp file created."); }