@Before
  public void init() throws Exception {

    fileSystem = mock(ProjectFileSystem.class);
    when(fileSystem.getSonarWorkingDirectory()).thenReturn(TestUtils.getResource("/Sensor"));

    vsProject = mock(VisualStudioProject.class);
    when(vsProject.getName()).thenReturn("Project #1");
    when(vsProject.getGeneratedAssemblies("Debug", "Any CPU"))
        .thenReturn(
            Sets.newHashSet(TestUtils.getResource("/Sensor/FakeAssemblies/Fake1.assembly")));
    VisualStudioProject project2 = mock(VisualStudioProject.class);
    when(project2.getName()).thenReturn("Project Test");
    when(project2.isTest()).thenReturn(true);
    solution = mock(VisualStudioSolution.class);
    when(solution.getProjects()).thenReturn(Lists.newArrayList(vsProject, project2));

    microsoftWindowsEnvironment = new MicrosoftWindowsEnvironment();
    microsoftWindowsEnvironment.setCurrentSolution(solution);
    microsoftWindowsEnvironment.setWorkingDirectory("target");

    rulesProfile = mock(RulesProfile.class);
    when(rulesProfile.getActiveRulesByRepository(anyString()))
        .thenReturn(Collections.singletonList(new ActiveRule()));

    resultParser = mock(GendarmeResultParser.class);

    profileExporter = mock(GendarmeProfileExporter.RegularGendarmeProfileExporter.class);

    conf = new BaseConfiguration();

    initializeSensor();
  }
  @Test
  public void testAnalyse() {
    parser = mock(CoverageResultParser.class); // create the parser before the sensor
    CoverageReportSensor sensor = buildSensor();

    microsoftWindowsEnvironment.setTestExecutionDone();
    File solutionDir = TestUtils.getResource("/Results/coverage/");
    microsoftWindowsEnvironment.setWorkingDirectory("");
    when(solution.getSolutionDir()).thenReturn(solutionDir);
    when(solution.getProject("MyAssembly")).thenReturn(vsProject1);

    List<FileCoverage> sourceFiles = new ArrayList<FileCoverage>();
    List<ProjectCoverage> projects = new ArrayList<ProjectCoverage>();
    ParserResult parserResult = new ParserResult(projects, sourceFiles);
    when(parser.parse(eq(project), any(File.class))).thenReturn(parserResult);

    ProjectCoverage projectCoverage = mock(ProjectCoverage.class);
    when(projectCoverage.getAssemblyName()).thenReturn("MyAssembly");
    projects.add(projectCoverage);

    SensorContext context = mock(SensorContext.class);

    sensor.analyse(project, context);

    verify(projectCoverage).getFileCoverageCollection();
  }
 /** {@inheritDoc} */
 public boolean shouldExecuteOnProject(Project project) {
   if (project.isRoot() || !CSharpConstants.LANGUAGE_KEY.equals(project.getLanguageKey())) {
     return false;
   }
   boolean skipMode = AbstractCSharpSensor.MODE_SKIP.equalsIgnoreCase(executionMode);
   boolean isTestProject =
       microsoftWindowsEnvironment.getCurrentProject(project.getName()).isTest();
   return !isTestProject && !skipMode;
 }
 protected CoverageDecorator(
     CSharpConfiguration configuration,
     MicrosoftWindowsEnvironment microsoftWindowsEnvironment,
     ResourceHelper resourceHelper) {
   this.microsoftWindowsEnvironment = microsoftWindowsEnvironment;
   this.vsSolution = microsoftWindowsEnvironment.getCurrentSolution();
   String[] exclusions = configuration.getStringArray(GallioConstants.COVERAGE_EXCLUDES_KEY);
   if (exclusions == null) {
     this.excludedAssemblies = Collections.EMPTY_SET;
   } else {
     this.excludedAssemblies = Sets.newHashSet(exclusions);
   }
   this.resourceHelper = resourceHelper;
 }
  @Before
  public void init() {
    vsProject1 = mock(VisualStudioProject.class);
    when(vsProject1.getName()).thenReturn("Project #1");
    vsTestProject2 = mock(VisualStudioProject.class);
    when(vsTestProject2.getName()).thenReturn("Project Test #2");
    when(vsTestProject2.isTest()).thenReturn(true);
    solution = mock(VisualStudioSolution.class);
    when(solution.getProjects()).thenReturn(Lists.newArrayList(vsProject1, vsTestProject2));
    when(solution.getTestProjects()).thenReturn(Lists.newArrayList(vsTestProject2));

    microsoftWindowsEnvironment = new MicrosoftWindowsEnvironment();
    microsoftWindowsEnvironment.setCurrentSolution(solution);

    project = mock(Project.class);
    when(project.getLanguageKey()).thenReturn("cs");
    when(project.getName()).thenReturn("Project #1");
  }
  @BeforeClass
  public static void init() {
    aRule = Rule.create("gendarme", "Rule", "Rule").setSeverity(RulePriority.BLOCKER);
    aFileIMoney = new org.sonar.api.resources.File("IMoney");
    aFileMoney = new org.sonar.api.resources.File("Money");

    env = mock(MicrosoftWindowsEnvironment.class);
    VisualStudioSolution solution = mock(VisualStudioSolution.class);
    when(env.getCurrentSolution()).thenReturn(solution);
    VisualStudioProject vsProject = mock(VisualStudioProject.class);
    when(solution.getProjectFromSonarProject(any(Project.class))).thenReturn(vsProject);
    when(solution.getProject(any(File.class))).thenReturn(vsProject);

    project = mock(Project.class);
    ProjectFileSystem fileSystem = mock(ProjectFileSystem.class);
    when(fileSystem.getSourceDirs()).thenReturn(Lists.newArrayList(new File("C:\\Sonar\\Example")));
    when(project.getFileSystem()).thenReturn(fileSystem);
    resourcesBridge = createFakeBridge();

    resourceHelper = mock(ResourceHelper.class);
    when(resourceHelper.isResourceInProject(any(Resource.class), eq(project))).thenReturn(true);
  }