public void Conv_HasThreeArguments() { // Arrange var logger = new TestLogger(); var testDir = TestUtils.CreateTestSpecificFolderWithSubPaths(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, @" set argC=0 for %%x in (%*) do Set /A argC+=1 echo Converter called with %argC% args echo success > """ + outputFilePath + @""""); // Act var success = BinaryToXmlCoverageReportConverter.ConvertBinaryToXml(converterFilePath, inputFilePath, outputFilePath, logger); // Assert success.Should().BeTrue("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 var logger = new TestLogger(); var testDir = TestUtils.CreateTestSpecificFolderWithSubPaths(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, @" echo Normal output... echo Error output...>&2 echo Create a new file using the output parameter echo foo > """ + outputFilePath + @""""); // Act var success = BinaryToXmlCoverageReportConverter.ConvertBinaryToXml(converterFilePath, inputFilePath, outputFilePath, logger); // Assert success.Should().BeTrue("Expecting the process to succeed"); File.Exists(outputFilePath).Should().BeTrue("Expecting the output file to exist"); TestContext.AddResultFile(outputFilePath); logger.AssertMessageLogged("Normal output..."); logger.AssertErrorLogged("Error output..."); }
[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 var logger = new TestLogger(); var testDir = TestUtils.CreateTestSpecificFolderWithSubPaths(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, @"exit -1"); // Act var success = BinaryToXmlCoverageReportConverter.ConvertBinaryToXml(converterFilePath, inputFilePath, outputFilePath, logger); // Assert success.Should().BeFalse("Expecting the process to fail"); logger.AssertErrorsLogged(); logger.AssertSingleErrorExists(inputFilePath); // error message should refer to the input file File.Exists(outputFilePath).Should().BeFalse("Not expecting the output file to exist"); }
[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 = BinaryToXmlCoverageReportConverter.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 Initialize_CanGetGetExeToolPathFromSetupConfigurationForBuildAgent() { // Arrange var logger = new TestLogger(); var factory = CreateVisualStudioSetupConfigurationFactory("Microsoft.VisualStudio.TestTools.CodeCoverage.Msi"); var reporter = new BinaryToXmlCoverageReportConverter(factory, logger, new AnalysisConfig()); // Act var result = reporter.Initialize(); // Assert result.Should().BeTrue(); logger.AssertDebugLogged("Code coverage command line tool: x:\\foo\\Team Tools\\Dynamic Code Coverage Tools\\CodeCoverage.exe"); }
public void Conv_ConvertToXml_InvalidArgs_Throws() { ILogger loggerMock = new Mock <ILogger>().Object; var testSubject = new BinaryToXmlCoverageReportConverter(loggerMock, new AnalysisConfig()); // 1. Null input path Action op = () => testSubject.ConvertToXml(null, "dummypath"); op.Should().Throw <ArgumentNullException>().And.ParamName.Should().Be("inputFilePath"); op = () => testSubject.ConvertToXml("\t\n", "dummypath"); op.Should().Throw <ArgumentNullException>().And.ParamName.Should().Be("inputFilePath"); // 2. Null output path op = () => testSubject.ConvertToXml("dummypath", null); op.Should().Throw <ArgumentNullException>().And.ParamName.Should().Be("outputFilePath"); op = () => testSubject.ConvertToXml("dummypath", " "); op.Should().Throw <ArgumentNullException>().And.ParamName.Should().Be("outputFilePath"); }
public void Initialize_CanGetGetExeToolPathFromEnvironmentVariable_FileDoesntExist_ShouldFallback() { // Arrange var logger = new TestLogger(); var config = new AnalysisConfig(); var factory = CreateVisualStudioSetupConfigurationFactory("Microsoft.VisualStudio.TestTools.CodeCoverage"); config.SetVsCoverageConverterToolPath(Path.GetTempPath()); var reporter = new BinaryToXmlCoverageReportConverter(factory, logger, config); // Act var result = reporter.Initialize(); // Assert result.Should().BeTrue(); logger.Warnings.Contains("CodeCoverage.exe was not found in the standard locations. Please provide the full path of the tool using the VsTestToolsInstallerInstalledToolLocation variable."); logger.AssertDebugLogged("Code coverage command line tool: x:\\foo\\Team Tools\\Dynamic Code Coverage Tools\\CodeCoverage.exe"); }
public void Initialize_CanGetGetExeToolPathFromEnvironmentVariable_FullPathToCodeCoverageToolGiven() { // Arrange var logger = new TestLogger(); var config = new AnalysisConfig(); var filePath = Path.Combine(Environment.CurrentDirectory, "CodeCoverage.exe"); File.Create(filePath); config.SetVsCoverageConverterToolPath(filePath); var reporter = new BinaryToXmlCoverageReportConverter(logger, config); // Act var result = reporter.Initialize(); // Assert result.Should().BeTrue(); logger.AssertDebugLogged($@"CodeCoverage.exe found at {filePath}."); }
public void Initialize_CanGetGetExeToolPathFromEnvironmentVariable_NoExeInThePath_ShouldSeekForStandardInstall() { // Arrange var logger = new TestLogger(); var config = new AnalysisConfig(); var filePath = Path.Combine(Environment.CurrentDirectory, @"tools\net451\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe"); Directory.CreateDirectory(Path.GetDirectoryName(filePath)); File.Create(filePath); config.SetVsCoverageConverterToolPath(Environment.CurrentDirectory); var reporter = new BinaryToXmlCoverageReportConverter(logger, config); // Act var result = reporter.Initialize(); // Assert result.Should().BeTrue(); logger.AssertDebugLogged($@"CodeCoverage.exe found at {filePath}."); }
public void GetRegistryPath_When32BitProcess_Returns32BitPath() { BinaryToXmlCoverageReportConverter.GetVsRegistryPath(false).Should().Be(@"SOFTWARE\Microsoft\VisualStudio"); }
public void GetRegistryPath_When64BitProcess_Returns64BitPath() { BinaryToXmlCoverageReportConverter.GetVsRegistryPath(true).Should().Be(@"SOFTWARE\Wow6432Node\Microsoft\VisualStudio"); }