[WorkItem(145)] // Regression test for bug #145: Poor UX if the code coverage report could not be converted to XML public void Conv_FailsIfFileConverterReturnsAnErrorCode() { // Arrange TestLogger logger = new TestLogger(); string testDir = TestUtils.CreateTestSpecificFolder(this.TestContext); string outputFilePath = Path.Combine(testDir, "output.txt"); string inputFilePath = Path.Combine(testDir, "input.txt"); File.WriteAllText(inputFilePath, "dummy input file"); string converterFilePath = Path.Combine(testDir, "converter.bat"); File.WriteAllText(converterFilePath, @"exit -1"); // Act bool success = CoverageReportConverter.ConvertBinaryToXml(converterFilePath, inputFilePath, outputFilePath, logger); // Assert Assert.IsFalse(success, "Expecting the process to fail"); logger.AssertErrorsLogged(); logger.AssertSingleErrorExists(inputFilePath); // error message should refer to the input file Assert.IsFalse(File.Exists(outputFilePath), "Not expecting the output file to exist"); }
public void Conv_HasThreeArguments() { // Arrange TestLogger logger = new TestLogger(); string testDir = TestUtils.CreateTestSpecificFolder(this.TestContext); string outputFilePath = Path.Combine(testDir, "output.txt"); string inputFilePath = Path.Combine(testDir, "input.txt"); File.WriteAllText(inputFilePath, "dummy input file"); string converterFilePath = Path.Combine(testDir, "converter.bat"); File.WriteAllText(converterFilePath, @" set argC=0 for %%x in (%*) do Set /A argC+=1 echo Converter called with %argC% args echo success > """ + outputFilePath + @""""); // Act bool success = CoverageReportConverter.ConvertBinaryToXml(converterFilePath, inputFilePath, outputFilePath, logger); // Assert Assert.IsTrue(success, "Expecting the process to succeed"); logger.AssertMessageLogged("Converter called with 3 args"); }
[WorkItem(72)] // Regression test for bug #72: CodeCoverage conversion - conversion errors should be detected and reported public void Conv_OutputIsCaptured() { // Arrange TestLogger logger = new TestLogger(); string testDir = TestUtils.CreateTestSpecificFolder(this.TestContext); string outputFilePath = Path.Combine(testDir, "output.txt"); string inputFilePath = Path.Combine(testDir, "input.txt"); File.WriteAllText(inputFilePath, "dummy input file"); string converterFilePath = Path.Combine(testDir, "converter.bat"); File.WriteAllText(converterFilePath, @" echo Normal output... echo Error output...>&2 echo Create a new file using the output parameter echo foo > """ + outputFilePath + @""""); // Act bool success = CoverageReportConverter.ConvertBinaryToXml(converterFilePath, inputFilePath, outputFilePath, logger); // Assert Assert.IsTrue(success, "Expecting the process to succeed"); Assert.IsTrue(File.Exists(outputFilePath), "Expecting the output file to exist"); this.TestContext.AddResultFile(outputFilePath); logger.AssertMessageLogged("Normal output..."); logger.AssertErrorLogged("Error output..."); }
public void Conv_Initialize_InvalidArgs_Throws() { var testSubject = new CoverageReportConverter(); Action op = () => testSubject.Initialize(null); op.ShouldThrow <ArgumentNullException>().And.ParamName.Should().Be("logger"); }
[WorkItem(72)] // Regression test for bug #72: fail the conversion if the output file is not created public void Conv_FailsIfFileNotFound() { // Arrange var logger = new TestLogger(); var testDir = TestUtils.CreateTestSpecificFolder(TestContext); var outputFilePath = Path.Combine(testDir, "output.txt"); var inputFilePath = Path.Combine(testDir, "input.txt"); File.WriteAllText(inputFilePath, "dummy input file"); var converterFilePath = Path.Combine(testDir, "converter.bat"); File.WriteAllText(converterFilePath, @"REM Do nothing - don't create a file"); // Act var success = CoverageReportConverter.ConvertBinaryToXml(converterFilePath, inputFilePath, outputFilePath, logger); // Assert Assert.IsFalse(success, "Expecting the process to fail"); logger.AssertErrorsLogged(); logger.AssertSingleErrorExists(outputFilePath); // error message should refer to the output file Assert.IsFalse(File.Exists(outputFilePath), "Not expecting the output file to exist"); }
public void CoverageReportGeneratorShouldInvokeGenerateOnReportGeneratorWrapper() { const string path = "somePath"; const string outPath = "someLocation"; var ioMock = new Mock <IDiskIOWrapper>(); var reportGeneratorMock = new Mock <IReportGeneratorWrapper>(); ioMock.Setup(mock => mock.FileExists(path)) .Returns(true); var converter = new CoverageReportConverter(ioMock.Object, reportGeneratorMock.Object); converter.Convert(path, outPath); reportGeneratorMock.Verify(mock => mock.Generate(path, outPath), Times.Once); }
public void ReturnOriginalFilePathIfNoConversionIsNecessary(string path) { const string outPath = "someLocation"; var ioMock = new Mock <IDiskIOWrapper>(); var reportGeneratorMock = new Mock <IReportGeneratorWrapper>(); ioMock.Setup(mock => mock.FileExists(path)) .Returns(true); var converter = new CoverageReportConverter(ioMock.Object, reportGeneratorMock.Object); var result = converter.Convert(path, outPath); result.Match(x => x, string.Empty) .Should() .Be(path); reportGeneratorMock.Verify(mock => mock.Generate(It.IsAny <string>(), It.IsAny <string>()), Times.Never); }
public void CoverageReportConverterShouldThrowFileNotFoundExceptionIfInputFileWasNotFound() { const string path = "invalidPath"; var ioMock = new Mock <IDiskIOWrapper>(); var reportGeneratorMock = new Mock <IReportGeneratorWrapper>(); ioMock.Setup(mock => mock.FileExists(path)) .Returns(false); var converter = new CoverageReportConverter(ioMock.Object, reportGeneratorMock.Object); Action act = () => converter.Convert(path, "any"); act.Should() .Throw <FileNotFoundException>() .WithMessage($"*{path}*"); ioMock.Verify(mock => mock.FileExists(path), Times.Once); }
public void Initialize_CanGetGetExeToolPathFromSetupConfigurationForBuildAgent() { // Arrange var logger = new TestLogger(); var factory = CreateVisualStudioSetupConfigurationFactory("Microsoft.VisualStudio.TestTools.CodeCoverage.Msi"); var reporter = new CoverageReportConverter(factory); // Act var result = reporter.Initialize(logger); // Assert Assert.IsTrue(result); logger.AssertDebugLogged("Code coverage command line tool: x:\\foo\\Team Tools\\Dynamic Code Coverage Tools\\CodeCoverage.exe"); }
public void IfReportGeneratorFailsConvertShouldReturnNone() { const string path = "somePath"; const string outPath = "someLocation"; var ioMock = new Mock <IDiskIOWrapper>(); var reportGeneratorMock = new Mock <IReportGeneratorWrapper>(); reportGeneratorMock.Setup(mock => mock.Generate(path, outPath)) .Returns(false); ioMock.Setup(mock => mock.FileExists(path)) .Returns(true); var converter = new CoverageReportConverter(ioMock.Object, reportGeneratorMock.Object); var result = converter.Convert(path, outPath); result.IsNone .Should() .BeTrue(); }
public void IfReportConversionIsSuccessfulConvertShouldReturnFullPathToNewReport() { const string path = "somePath"; const string outPath = "someLocation"; var ioMock = new Mock <IDiskIOWrapper>(); var reportGeneratorMock = new Mock <IReportGeneratorWrapper>(); reportGeneratorMock.Setup(mock => mock.Generate(path, outPath)) .Returns(true); ioMock.Setup(mock => mock.FileExists(path)) .Returns(true); var converter = new CoverageReportConverter(ioMock.Object, reportGeneratorMock.Object); var result = converter.Convert(path, outPath); result.Match(x => x, () => string.Empty) .Should() .BeEquivalentTo(Path.Join(outPath, "Cobertura.xml")); }
public void Conv_ConvertToXml_InvalidArgs_Throws() { ILogger loggerMock = new Mock <ILogger>().Object; var testSubject = new CoverageReportConverter(); // 1. Null input path Action op = () => testSubject.ConvertToXml(null, "dummypath", loggerMock); op.ShouldThrow <ArgumentNullException>().And.ParamName.Should().Be("inputFilePath"); op = () => testSubject.ConvertToXml("\t\n", "dummypath", loggerMock); op.ShouldThrow <ArgumentNullException>().And.ParamName.Should().Be("inputFilePath"); // 2. Null output path op = () => testSubject.ConvertToXml("dummypath", null, loggerMock); op.ShouldThrow <ArgumentNullException>().And.ParamName.Should().Be("outputFilePath"); op = () => testSubject.ConvertToXml("dummypath", " ", loggerMock); op.ShouldThrow <ArgumentNullException>().And.ParamName.Should().Be("outputFilePath"); // 3. Null logger op = () => testSubject.ConvertToXml("dummyInput", "dummyOutput", null); op.ShouldThrow <ArgumentNullException>().And.ParamName.Should().Be("logger"); }