public void GetCoverage_ShouldMarkInTestFile_OnlyAssertionLineAsFailed_When_AssertionFailed_ButNoOtherExceptionWasThrown() { // arrange string nodePath = "SampleHelloWorldTests.HelloWorldTests.HelloWorld.Method"; var variables = new[] { new AuditVariablePlaceholder(@"c:\HelloWorld.cs", nodePath, 1), new AuditVariablePlaceholder(@"c:\HelloWorldTests.cs", nodePath, 2), new AuditVariablePlaceholder(@"c:\HelloWorldTests.cs", nodePath, 3)}; var testResult = new TestRunResult("test_name", variables, "assertion error", true); var testNode = CSharpSyntaxTree.ParseText("class HelloWorldTests{" + " public void TestMethod()" + "{}" + "}"); var testMethodNode = testNode.GetRoot().DescendantNodes().OfType<MethodDeclarationSyntax>().Single(); // act LineCoverage[] totalCoverage = testResult.GetCoverage(testMethodNode, "SampleHelloWorldTests", @"c:\HelloWorldTests.cs"); // assert Assert.That(totalCoverage.Length, Is.EqualTo(3)); Assert.That(totalCoverage[1].IsSuccess, Is.EqualTo(true)); Assert.That(totalCoverage[2].IsSuccess, Is.EqualTo(false)); }
public void GetCoverage_ShouldReturnEmptyCoverage_When_ThereAreNoAuditVariables() { // arrange var variables = new AuditVariablePlaceholder[0]; var testResult = new TestRunResult("test_name", variables, "error", false); var testNode = CSharpSyntaxTree.ParseText("class HelloWorldTests{" + " public void TestMethod()" + "{}" + "}"); var testMethodNode = testNode.GetRoot().DescendantNodes().OfType<MethodDeclarationSyntax>().Single(); // act LineCoverage[] totalCoverage = testResult.GetCoverage(testMethodNode, "SampleHelloWorldTests", @"c:\HelloWorldTests.cs"); // assert Assert.That(totalCoverage.Length, Is.EqualTo(0)); }
public void GetCoverage_Should_MarkOnlyLastLine_As_FailedOne_When_ExceptionWasThrown_And_WeAreInSutDocument() { // arrange string nodePath = "SampleHelloWorldTests.HelloWorldTests.HelloWorld.Method"; var variables = new[] { new AuditVariablePlaceholder(@"c:\HelloWorld.cs", nodePath, 1), new AuditVariablePlaceholder(@"c:\HelloWorld.cs", nodePath, 2), new AuditVariablePlaceholder(@"c:\HelloWorldTests.cs", nodePath, 3)}; var testResult = new TestRunResult("test_name",variables, "error",false); var testNode = CSharpSyntaxTree.ParseText("class HelloWorldTests{" + " public void TestMethod()" + "{}" + "}"); var testMethodNode = testNode.GetRoot().DescendantNodes().OfType<MethodDeclarationSyntax>().Single(); // act LineCoverage[] totalCoverage = testResult.GetCoverage(testMethodNode, "SampleHelloWorldTests", @"c:\HelloWorldTests.cs"); // assert Assert.That(totalCoverage.Length, Is.EqualTo(3)); Assert.That(totalCoverage[0].IsSuccess, Is.EqualTo(true)); Assert.That(totalCoverage[1].IsSuccess, Is.EqualTo(false)); Assert.That(totalCoverage[0].ErrorMessage, Is.Null); Assert.That(totalCoverage[1].ErrorMessage, Is.EqualTo(testResult.ErrorMessage)); }
public void GetCoverage_Should_ReturnOnePassedCoverage_When_ThereIsOneVariable_And_AssertionDidNotFail() { // arrange var variables = new[] { new AuditVariablePlaceholder("HelloWorldTests.cs", "", 1) }; var testResult = new TestRunResult("test_name",variables, null,false); var testNode = CSharpSyntaxTree.ParseText(""); // act LineCoverage[] totalCoverage = testResult.GetCoverage(testNode.GetRoot(), "SampleHelloWorldTests", "HelloWorldTests.cs"); // assert Assert.That(totalCoverage.Length, Is.EqualTo(1)); Assert.That(totalCoverage[0].IsSuccess, Is.EqualTo(true)); }