Beispiel #1
0
 /// <summary>
 /// Validate VirtualSeq Add method exception
 /// </summary>
 /// <param name="virtualSeq">Virtual seq</param>
 /// <param name="exThrown">true if an exception</param>
 /// <param name="expectedException">exception message</param>
 static void VirtualSeqAddValidation(VirtualSequence virtualSeq,
                                     bool exThrown, string expectedException)
 {
     try
     {
         virtualSeq.Add(Alphabets.DNA.A);
     }
     catch (NotSupportedException e)
     {
         exThrown = true;
         Assert.IsTrue(exThrown);
         Assert.AreEqual(expectedException, e.Message);
         Console.WriteLine(string.Format((IFormatProvider)null,
                                         " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message));
     }
 }
Beispiel #2
0
        /// <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;
            }
        }