using System;
using NUnit.Framework;
using NCover;
using NCover.Objects;
namespace AcceptenceTests.Cs{
[TestFixture]
public class WhileTest
{
[SetUp]
public void SetUp()
{
NCoverCheck.ResetForTests();
}
[Test]
public void TestGoingIntoAWhileLoopIsCovered()
{
const string COVER = @"
public class A
{
public static bool[] B()
{
int i = 0;
while (i < 10)//7
{
i++;//9
}
return NCover.NCoverCheck.covered;//12
}
}";
string instrumentedCode;
TestUtilities.AssertCompiles(new string[] { COVER}, "A");
CoveragePoint[] points = new Instrumenter( 0, COVER, "").Do(out instrumentedCode, null);
Assert.AreEqual(2, points.Length);
bool[] results = (bool[]) TestUtilities.AssertCompiles(new string[] { instrumentedCode }, "A");
Assert.AreEqual(2, results.Length);
Assert.IsTrue(TestUtilities.WasHit(points, results, 7));
Assert.IsTrue(TestUtilities.WasHit(points, results, 12));
}
[Test]
public void TestNotIntoAWhileLoopIsPointedOut()
{
const string COVER = @"
public class A
{
public static bool[] B()
{
int i = 10;
while (i < 10)//7
{
i++;//9
}
return NCover.NCoverCheck.covered;//12
}
}";
string instrumentedCode;
TestUtilities.AssertCompiles(new string[] { COVER }, "A");
CoveragePoint[] points = new Instrumenter( 0, COVER, "").Do(out instrumentedCode, null);
Assert.AreEqual(2, points.Length);
bool[] results = (bool[]) TestUtilities.AssertCompiles(new string[] { instrumentedCode }, "A");
//Assert.AreEqual(2, results.Length);
Assert.IsFalse(TestUtilities.WasHit(points, results, 7));
Assert.IsTrue(TestUtilities.WasHit(points, results, 12));
}
}
}
|