using System;
using NUnit.Framework;
using NCover;
namespace NCoverCheckTests.AcceptenceTests.Vb{
/// <summary>
/// Summary description for IfTest.
/// </summary>
[TestFixture]
public class TryCatchTest
{
[SetUp]
public void SetUp()
{
NCoverCheck.ResetForTests();
}
[Test]
public void CorrectCoverageOfThrow()
{
const string COVER = @"
Public Class A
Public Shared Function B() As Boolean()
Try
Throw new System.ApplicationException() ' 5
Catch ex as System.Exception
End Try
Return NCover.NCoverCheck.covered 'todo
End Function
End Class";
string instrumentedCode;
TestUtilities.AssertVbCompiles(new string[] { COVER }, "A");
CoveragePoint[] points = new VbInstrumenter( 0, COVER, "").Do(out instrumentedCode, null);
Assert.AreEqual(1, points.Length);
bool[] results = (bool[]) TestUtilities.AssertVbCompiles(new string[] { instrumentedCode }, "A");
Assert.AreEqual(1, results.Length);
Assert.IsTrue(TestUtilities.WasHit(points, results, 5));
}
[Test]
public void CorrectCoverageOfFalseIf()
{
const string COVER_TRUE_IF = @"
Public Class A
Public Shared Function B() As Boolean()
If System.Environment.TickCount < 0 Then '4
Return NCover.NCoverCheck.covered 'todo
End If
Return NCover.NCoverCheck.covered 'todo
End Function
End Class";
string instrumentedCode;
TestUtilities.AssertVbCompiles(new string[] { COVER_TRUE_IF }, "A");
CoveragePoint[] points = new VbInstrumenter( 0, COVER_TRUE_IF, "").Do(out instrumentedCode, null);
Assert.AreEqual(1, points.Length);
bool[] results = (bool[]) TestUtilities.AssertVbCompiles(new string[] { instrumentedCode }, "A");
Assert.AreEqual(0, results.Length);
Assert.IsFalse(TestUtilities.WasHit(points, results, 4));
//Assert.IsTrue(TestUtilities.WasHit(points, results, 5));
//Assert.IsFalse(TestUtilities.WasHit(points, results, 8));
}
}
}
|