using System;
using NUnit.Framework;
using NCover;
using NCover.Objects;
namespace AcceptenceTests.Cs{
[TestFixture]
public class TryCatchTest
{
[SetUp]
public void SetUp()
{
NCoverCheck.ResetForTests();
}
[Test]
public void TestCatchIsNotCovered()
{
const string COVER = @"
public class A
{
public static bool[] B()
{
try
{
}
catch(System.Exception)
{//11
}
return NCover.NCoverCheck.covered;//13
}
}";
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, 11));
Assert.IsTrue(TestUtilities.WasHit(points, results, 13));
}
[Test]
public void TestCatchIsCovered()
{
const string COVER = @"
public class A
{
public static bool[] B()
{
try
{
throw new System.Exception(" + "\"\"" + @");//8
}
catch(System.Exception)
{//11
}
return NCover.NCoverCheck.covered;//13
}
}";
string instrumentedCode;
TestUtilities.AssertCompiles(new string[] { COVER }, "A");
CoveragePoint[] points = new Instrumenter( 0, COVER, "").Do(out instrumentedCode, null);
Assert.AreEqual(3, points.Length);
bool[] results = (bool[]) TestUtilities.AssertCompiles(new string[] { instrumentedCode }, "A");
Assert.AreEqual(3, results.Length);
Assert.IsTrue(TestUtilities.WasHit(points, results, 8));
Assert.IsTrue(TestUtilities.WasHit(points, results, 11));
Assert.IsTrue(TestUtilities.WasHit(points, results, 13));
}
}
}
|