public void EnableCodeCoverageForJacocoTest()
 {
     SetupMocks(_sourceDirectory);
     LoadBuildFile(CodeCoverageTestConstants.BuildXml);
     var enableCodeCoverage = new CodeCoverageEnablerForJacocoAnt();
     enableCodeCoverage.Initialize(_hc);
     var ccInputs = new Dictionary<string, string>();
     ccInputs.Add("buildfile", _sampleBuildFilePath);
     ccInputs.Add("classfilesdirectories", _classDirectories);
     ccInputs.Add("classfilter", _classFilter);
     ccInputs.Add("sourcedirectories", _srcDirectory);
     ccInputs.Add("summaryfile", _summaryFile);
     ccInputs.Add("reportdirectory", _reportDirectory);
     ccInputs.Add("ccreporttask", _cCReportTask);
     ccInputs.Add("reportbuildfile", _sampleReportBuildFilePath);
     enableCodeCoverage.EnableCodeCoverage(_ec.Object, new CodeCoverageEnablerInputs(_ec.Object, "Ant", ccInputs));
     VerifyJacocoCoverageForAnt(numberOfTestNodes: 1, buildFilePath: _sampleBuildFilePath);
     VerifyJacocoReportForAnt();
     Assert.Equal(_warnings.Count, 0);
     Assert.Equal(_errors.Count, 0);
 }
 public void MoreThanOneBuildFilesWithAnInvalidMainBuildXmlThrowsException()
 {
     SetupMocks(_sourceDirectory);
     LoadBuildFile(CodeCoverageTestConstants.BuildXml);
     var invalidXml = Path.Combine(_sourceDirectory, "invalid.xml");
     File.WriteAllText(invalidXml, "invalidXmlData");
     var enableCodeCoverage = new CodeCoverageEnablerForJacocoAnt();
     enableCodeCoverage.Initialize(_hc);
     var ccInputs = new Dictionary<string, string>();
     ccInputs.Add("buildfile", invalidXml);
     ccInputs.Add("classfilesdirectories", _classDirectories);
     ccInputs.Add("classfilter", _classFilter);
     ccInputs.Add("sourcedirectories", _srcDirectory);
     ccInputs.Add("summaryfile", _summaryFile);
     ccInputs.Add("reportdirectory", _reportDirectory);
     ccInputs.Add("ccreporttask", _cCReportTask);
     ccInputs.Add("reportbuildfile", _sampleReportBuildFilePath);
     Assert.Throws<XmlException>(() => enableCodeCoverage.EnableCodeCoverage(_ec.Object, new CodeCoverageEnablerInputs(_ec.Object, "Ant", ccInputs)));
 }
 public void MoreThanOneBuildFilesWithAnInvalidXmlDoesnotThrow()
 {
     SetupMocks(_sourceDirectory);
     LoadBuildFile(CodeCoverageTestConstants.BuildXml);
     var invalidXml = Path.Combine(_sourceDirectory, "invalid.xml");
     File.WriteAllText(invalidXml, "invalidXmlData");
     var enableCodeCoverage = new CodeCoverageEnablerForJacocoAnt();
     enableCodeCoverage.Initialize(_hc);
     var ccInputs = new Dictionary<string, string>();
     ccInputs.Add("buildfile", _sampleBuildFilePath);
     ccInputs.Add("classfilesdirectories", _classDirectories);
     ccInputs.Add("classfilter", _classFilter);
     ccInputs.Add("sourcedirectories", _srcDirectory);
     ccInputs.Add("summaryfile", _summaryFile);
     ccInputs.Add("reportdirectory", _reportDirectory);
     ccInputs.Add("ccreporttask", _cCReportTask);
     ccInputs.Add("reportbuildfile", _sampleReportBuildFilePath);
     enableCodeCoverage.EnableCodeCoverage(_ec.Object, new CodeCoverageEnablerInputs(_ec.Object, "Ant", ccInputs));
     VerifyJacocoCoverageForAnt(numberOfTestNodes: 1, buildFilePath: Path.Combine(_sourceDirectory, "build.xml"));
     VerifyJacocoReportForAnt();
     Assert.Equal(_warnings.Count, 0);
     Assert.Equal(_errors.Count, 0);
 }
 public void EnableJacocoCodeCoverageForAntIfSourceDirectoryIsNotAvailable()
 {
     LoadBuildFile(CodeCoverageTestConstants.BuildXml);
     SetupMocks("");
     var enableCodeCoverage = new CodeCoverageEnablerForJacocoAnt();
     enableCodeCoverage.Initialize(_hc);
     var ccInputs = new Dictionary<string, string>();
     ccInputs.Add("buildfile", _sampleBuildFilePath);
     ccInputs.Add("classfilesdirectories", _classDirectories);
     ccInputs.Add("classfilter", _classFilter);
     ccInputs.Add("sourcedirectories", _srcDirectory);
     ccInputs.Add("summaryfile", _summaryFile);
     ccInputs.Add("reportdirectory", _reportDirectory);
     ccInputs.Add("ccreporttask", _cCReportTask);
     ccInputs.Add("reportbuildfile", _sampleReportBuildFilePath);
     Assert.Throws<InvalidOperationException>(() => enableCodeCoverage.EnableCodeCoverage(_ec.Object, new CodeCoverageEnablerInputs(_ec.Object, "Ant", ccInputs)));
 }
 public void EnableCodeCoverageForAntDoesNotThrowWithNoTests()
 {
     SetupMocks(_sourceDirectory);
     LoadBuildFile(CodeCoverageTestConstants.BuildWithNoTestsXml);
     var enableCodeCoverage = new CodeCoverageEnablerForJacocoAnt();
     enableCodeCoverage.Initialize(_hc);
     var ccInputs = new Dictionary<string, string>();
     ccInputs.Add("buildfile", _sampleBuildFilePath);
     ccInputs.Add("classfilesdirectories", _classDirectories);
     ccInputs.Add("classfilter", _classFilter);
     ccInputs.Add("sourcedirectories", _srcDirectory);
     ccInputs.Add("summaryfile", _summaryFile);
     ccInputs.Add("reportdirectory", _reportDirectory);
     ccInputs.Add("ccreporttask", _cCReportTask);
     ccInputs.Add("reportbuildfile", _sampleReportBuildFilePath);
     try
     {
         enableCodeCoverage.EnableCodeCoverage(_ec.Object, new CodeCoverageEnablerInputs(_ec.Object, "Ant", ccInputs));
     }
     catch (Exception ex)
     {
         Assert.True(false, "Expected no exception. But got " + ex.GetType());
     }
     Assert.Equal(_warnings.Count, 0);
     Assert.Equal(_errors.Count, 0);
 }
 public void EnableCodeCoverageForAntThrowsExceptionWithNoReportTask()
 {
     SetupMocks(_sourceDirectory);
     LoadBuildFile(CodeCoverageTestConstants.BuildXml);
     var enableCodeCoverage = new CodeCoverageEnablerForJacocoAnt();
     enableCodeCoverage.Initialize(_hc);
     var ccInputs = new Dictionary<string, string>();
     ccInputs.Add("buildfile", _sampleBuildFilePath);
     ccInputs.Add("classfilesdirectories", _classDirectories);
     ccInputs.Add("classfilter", _classFilter);
     ccInputs.Add("sourcedirectories", _srcDirectory);
     ccInputs.Add("summaryfile", _summaryFile);
     ccInputs.Add("reportdirectory", _reportDirectory);
     ccInputs.Add("reportbuildfile", _sampleReportBuildFilePath);
     Assert.Throws<ArgumentException>(() => enableCodeCoverage.EnableCodeCoverage(_ec.Object, new CodeCoverageEnablerInputs(_ec.Object, "Ant", ccInputs)));
 }
 public void EnableCodeCoverageForJacocoTestWithFullClassNameFilters()
 {
     SetupMocks(_sourceDirectory);
     LoadBuildFile(CodeCoverageTestConstants.BuildXml);
     var enableCodeCoverage = new CodeCoverageEnablerForJacocoAnt();
     enableCodeCoverage.Initialize(_hc);
     var ccInputs = new Dictionary<string, string>();
     ccInputs.Add("buildfile", _sampleBuildFilePath);
     ccInputs.Add("classfilesdirectories", _classDirectories);
     ccInputs.Add("classfilter", "+:app.com.SampleTest,+:app.*.UtilTest,+:app2*,-:app.com.SampleTest,-:app.*.UtilTest,-:app3*");
     ccInputs.Add("sourcedirectories", _srcDirectory);
     ccInputs.Add("summaryfile", _summaryFile);
     ccInputs.Add("reportdirectory", _reportDirectory);
     ccInputs.Add("ccreporttask", _cCReportTask);
     ccInputs.Add("reportbuildfile", _sampleReportBuildFilePath);
     enableCodeCoverage.EnableCodeCoverage(_ec.Object, new CodeCoverageEnablerInputs(_ec.Object, "Ant", ccInputs));
     VerifyJacocoCoverageForAnt(numberOfTestNodes: 1, buildFilePath: _sampleBuildFilePath, includes: "app.com.SampleTest:app.*.UtilTest:app2*", excludes: "app.com.SampleTest:app.*.UtilTest:app3*");
     VerifyJacocoReportForAnt("**/app/com/SampleTest.class,**/app/*/UtilTest.class,**/app2*/**", "**/app/com/SampleTest.class,**/app/*/UtilTest.class,**/app3*/**");
     Assert.Equal(_warnings.Count, 0);
     Assert.Equal(_errors.Count, 0);
 }