/// <summary> /// Validate VirtualSeq Contains method exception /// </summary> /// <param name="virtualSeq">Virtual seq</param> static void VirtualSeqContainsValidation(VirtualSequence virtualSeq) { foreach (Nucleotide nucleotide in Alphabets.DNA) { Assert.IsFalse(virtualSeq.Contains(nucleotide)); } }
public void TestVirtualSequence() { VirtualSequence virtualSeq = new VirtualSequence(Alphabets.DNA); string id = Guid.NewGuid().ToString(string.Empty); virtualSeq.ID = id; Assert.AreEqual(virtualSeq.Alphabet, Alphabets.DNA); Assert.AreEqual(virtualSeq.Count, 0); Assert.AreEqual(virtualSeq.ID, id); // By default Displayid should show value of id. Assert.AreEqual(virtualSeq.DisplayID, virtualSeq.ID); virtualSeq.DisplayID = "VirtualSeq1"; Assert.AreEqual(virtualSeq.DisplayID, "VirtualSeq1"); Assert.AreNotEqual(virtualSeq.DisplayID, virtualSeq.ID); Assert.AreEqual(virtualSeq.IsReadOnly, true); Assert.AreEqual(virtualSeq.IndexOf(Alphabets.DNA.A), -1); foreach (Nucleotide nucleotide in Alphabets.DNA) { Assert.AreEqual(virtualSeq.IndexOf(nucleotide), -1); Assert.IsFalse(virtualSeq.Contains(nucleotide)); } // Verify the above test using ISequence interface. ISequence seq = virtualSeq as ISequence; Assert.AreEqual(seq.Alphabet, Alphabets.DNA); Assert.AreEqual(seq.Count, 0); Assert.AreEqual(seq.ID, id); Assert.AreNotEqual(seq.DisplayID, virtualSeq.ID); Assert.AreEqual(seq.DisplayID, "VirtualSeq1"); Assert.AreEqual(seq.IsReadOnly, true); foreach (Nucleotide nucleotide in Alphabets.DNA) { Assert.AreEqual(seq.IndexOf(nucleotide), -1); Assert.IsFalse(seq.Contains(nucleotide)); } #region Test not supported members try { seq.Add(Alphabets.DNA.A); Assert.Fail(); } catch (NotSupportedException) { Assert.AreEqual(seq.Count, 0); } try { seq.Clear(); Assert.Fail(); } catch (NotSupportedException) { Assert.AreEqual(seq.Count, 0); } ISequence tmpSeq = null; try { tmpSeq = seq.Complement; Assert.Fail(); } catch (NotSupportedException) { Assert.IsNull(tmpSeq); } try { ISequenceItem[] seqItems = new ISequenceItem[10]; seq.CopyTo(seqItems, 0); Assert.Fail(); } catch (NotSupportedException) { } try { seq.Insert(0, 'A'); Assert.Fail(); } catch (NotSupportedException) { Assert.AreEqual(seq.Count, 0); } try { seq.InsertRange(0, "ACG"); Assert.Fail(); } catch (NotSupportedException) { Assert.AreEqual(seq.Count, 0); } try { tmpSeq = seq.Range(0, 1); Assert.Fail(); } catch (NotSupportedException) { Assert.IsNull(tmpSeq); } try { seq.Remove(Alphabets.DNA.A); Assert.Fail(); } catch (NotSupportedException) { Assert.IsNull(tmpSeq); } try { seq.RemoveAt(0); Assert.Fail(); } catch (NotSupportedException) { Assert.AreEqual(seq.Count, 0); } try { seq.RemoveRange(0, 1); Assert.Fail(); } catch (NotSupportedException) { Assert.AreEqual(seq.Count, 0); } try { seq.Replace(0, Alphabets.DNA.A.Symbol); Assert.Fail(); } catch (NotSupportedException) { Assert.AreEqual(seq.IndexOf(Alphabets.DNA.A), -1); } try { seq.ReplaceRange(0, "GA"); Assert.Fail(); } catch (NotSupportedException) { Assert.AreEqual(seq.Count, 0); } try { tmpSeq = seq.Reverse; Assert.Fail(); } catch (NotSupportedException) { Assert.IsNull(tmpSeq); } try { tmpSeq = seq.ReverseComplement; Assert.Fail(); } catch (NotSupportedException) { Assert.IsNull(tmpSeq); } string sequence = string.Empty; try { sequence = seq.ToString(); Assert.Fail(); } catch (NotSupportedException) { Assert.IsTrue(string.IsNullOrEmpty(sequence)); } ISequenceItem seqItem = null; try { seqItem = seq[0]; Assert.Fail(); } catch (NotSupportedException) { Assert.IsNull(seqItem); } #endregion Test not supported members }
/// <summary> /// Validate virtual seqeunce methods general exception. /// <param name="methodName">Virtual seqeunce method parameters</param> /// </summary> static void ValidateGeneralVirtualSequenceException( VirtualSequenceParameters methodName) { // Gets the alphabet from the Xml string alphabet = Utility._xmlUtil.GetTextValue( Constants.DnaVirtualSeqNode, Constants.AlphabetNameNode); string expectedException = Utility._xmlUtil.GetTextValue( Constants.DnaVirtualSeqNode, Constants.ExceptionMessage); string expectedValue = Utility._xmlUtil.GetTextValue( Constants.DnaVirtualSeqNode, Constants.IndexValue); bool exThrown = false; // Logs information to the log file ApplicationLog.WriteLine(string.Format(null, "Virtual Sequence P1: Sequence {0} is expected.", alphabet)); // create virtual seqeunce for an alphabet. VirtualSequence virtualSeq = new VirtualSequence( Utility.GetAlphabet(alphabet)); switch (methodName) { case VirtualSequenceParameters.Add: try { virtualSeq.Add(Alphabets.DNA.A); } catch (NotSupportedException e) { exThrown = true; Assert.AreEqual(expectedException, e.Message); Console.WriteLine(string.Format(null, " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message)); } // Validate an exception. Assert.IsTrue(exThrown); break; case VirtualSequenceParameters.Clear: try { virtualSeq.Clear(); } catch (NotSupportedException e) { exThrown = true; Assert.AreEqual(expectedException, e.Message); Console.WriteLine(string.Format(null, " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message)); } // Validate an exception. Assert.IsTrue(exThrown); break; case VirtualSequenceParameters.CopyTo: try { ISequenceItem[] iseqItems = new ISequenceItem[20]; virtualSeq.CopyTo(iseqItems, 0); } catch (NotSupportedException e) { exThrown = true; Assert.AreEqual(expectedException, e.Message); Console.WriteLine(string.Format(null, " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message)); } // Validate an exception. Assert.IsTrue(exThrown); break; case VirtualSequenceParameters.Remove: try { virtualSeq.Remove(virtualSeq[0]); } catch (NotSupportedException e) { exThrown = true; Assert.AreEqual(expectedException, e.Message); Console.WriteLine(string.Format(null, " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message)); } // Validate an exception. Assert.IsTrue(exThrown); break; case VirtualSequenceParameters.GetEnumerator: try { virtualSeq.GetEnumerator(); } catch (NotSupportedException e) { exThrown = true; Assert.AreEqual(expectedException, e.Message); Console.WriteLine(string.Format(null, " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message)); } // Validate an exception. Assert.IsTrue(exThrown); break; case VirtualSequenceParameters.Insert: try { virtualSeq.Insert(0, 'G'); } catch (NotSupportedException e) { exThrown = true; Assert.AreEqual(expectedException, e.Message); Console.WriteLine(string.Format(null, " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message)); } // Validate an exception. Assert.IsTrue(exThrown); break; case VirtualSequenceParameters.Range: try { virtualSeq.Range(0, 5); } catch (NotSupportedException e) { exThrown = true; Assert.AreEqual(expectedException, e.Message); Console.WriteLine(string.Format(null, " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message)); } // Validate an exception. Assert.IsTrue(exThrown); break; case VirtualSequenceParameters.InsertRange: try { virtualSeq.InsertRange(0, "GCCAAAATTTAGGCAGAGA"); } catch (NotSupportedException e) { exThrown = true; Assert.AreEqual(expectedException, e.Message); Console.WriteLine(string.Format(null, " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message)); } // Validate an exception. Assert.IsTrue(exThrown); break; case VirtualSequenceParameters.RemoveAt: try { virtualSeq.RemoveAt(0); } catch (NotSupportedException e) { exThrown = true; Assert.AreEqual(expectedException, e.Message); Console.WriteLine(string.Format(null, " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message)); } // Validate an exception. Assert.IsTrue(exThrown); break; case VirtualSequenceParameters.RemoveRange: try { virtualSeq.RemoveRange(0, 1); } catch (NotSupportedException e) { exThrown = true; Assert.AreEqual(expectedException, e.Message); Console.WriteLine(string.Format(null, " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message)); } // Validate an exception. Assert.IsTrue(exThrown); break; case VirtualSequenceParameters.ReplaceRange: try { virtualSeq.ReplaceRange(0, "AUGAUGAUGAG"); } catch (NotSupportedException e) { exThrown = true; Assert.AreEqual(expectedException, e.Message); Console.WriteLine(string.Format(null, " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message)); } // Validate an exception. Assert.IsTrue(exThrown); break; case VirtualSequenceParameters.ReplaceChar: try { virtualSeq.Replace(0, Alphabets.DNA.A.Symbol); } catch (NotSupportedException e) { exThrown = true; Assert.AreEqual(expectedException, e.Message); Console.WriteLine(string.Format(null, " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message)); } break; case VirtualSequenceParameters.ReplaceSeqItem: try { virtualSeq.Replace(0, virtualSeq[0]); } catch (NotSupportedException e) { exThrown = true; Assert.AreEqual(expectedException, e.Message); Console.WriteLine(string.Format(null, " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message)); } // Validate an exception. Assert.IsTrue(exThrown); break; case VirtualSequenceParameters.ToString: try { virtualSeq.ToString(); } catch (NotSupportedException e) { exThrown = true; Assert.AreEqual(expectedException, e.Message); Console.WriteLine(string.Format(null, " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message)); } break; case VirtualSequenceParameters.Complement: try { ISequence complSeq = virtualSeq.Complement; // Below line is the dummy code // for fixing FxCop error "RemoveUnusedLocals". Assert.AreEqual(complSeq, null); } catch (NotSupportedException e) { exThrown = true; Assert.AreEqual(expectedException, e.Message); Console.WriteLine(string.Format(null, " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message)); } // Validate an exception. Assert.IsTrue(exThrown); try { ISequence rev = virtualSeq.Reverse; // Below line is the dummy code // for fixing FxCop error "RemoveUnusedLocals". Assert.AreEqual(rev, null); } catch (NotSupportedException e) { exThrown = true; Assert.AreEqual(expectedException, e.Message); Console.WriteLine(string.Format(null, " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message)); } // Validate an exception. Assert.IsTrue(exThrown); try { ISequence complSeq = virtualSeq.ReverseComplement; } catch (NotSupportedException e) { exThrown = true; Assert.AreEqual(expectedException, e.Message); Console.WriteLine(string.Format(null, " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message)); } // Validate an exception. Assert.IsTrue(exThrown); break; case VirtualSequenceParameters.IndexOf: foreach (Nucleotide nucleotide in Alphabets.RNA) { Assert.AreEqual(virtualSeq.IndexOf(nucleotide).ToString((IFormatProvider)null), expectedValue); } break; case VirtualSequenceParameters.Contains: foreach (Nucleotide nucleotide in Alphabets.DNA) { Assert.IsFalse(virtualSeq.Contains(nucleotide)); } break; default: break; } }