using System;
using NUnit.Framework;
using NCover;
namespace NCoverCheckTests.AcceptenceTests.Vb{
/// <summary>
/// Summary description for IfTest.
/// </summary>
[TestFixture]
public class WhileTest
{
[SetUp]
public void SetUp()
{
NCoverCheck.ResetForTests();
}
[Test]
public void WhileInstrumentsCorrectly()
{
string instrumentedCode;
const string COVER = @"
While x AndAlso x
x = False
End While";
CoveragePoint[] points = new VbInstrumenter( 0, COVER, "").Do(out instrumentedCode, null);
Assert.AreEqual(@"
While x AndAlso x AndAlso NCover.NCoverCheck.Add(1)
x = False
End While", instrumentedCode);
}
[Test]
public void CorrectCoverageOfWhile()
{
const string COVER = @"
Public Class A
Public Shared Function B() As Boolean()
Dim x as Boolean = True
While x
x = False
End While
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 CorrectCoverageOfSkippedWhile()
{
const string COVER = @"
Public Class A
Public Shared Function B() As Boolean()
Dim x as Boolean = False
While x
x = False
End While
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(0, results.Length);
Assert.IsFalse(TestUtilities.WasHit(points, results, 5));
}
[Test]
public void CorrectCoverageOfWhileWithCommentAfter()
{
const string COVER = @"
Public Class A
Public Shared Function B() As Boolean()
Dim x as Boolean = True
While x ' This should not throw you.
x = False
End While
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));
}
}
}
|