@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();
  }
Ejemplo n.º 2
0
 private boolean isExcludedFromCoverage(Resource resource) {
   if (excludedAssemblies.isEmpty()) {
     return false;
   }
   Project project = resourceHelper.findParentProject(resource);
   VisualStudioProject vsProject = vsSolution.getProjectFromSonarProject(project);
   return excludedAssemblies.contains(vsProject.getName());
 }
  @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 initData() {
   project = mock(VisualStudioProject.class);
   when(project.getProjectFile())
       .thenReturn(new File("target/sonar/solution/project/project.csproj"));
   new File("target/sonar/solution").mkdirs();
   solution = mock(VisualStudioSolution.class);
   when(solution.getSolutionDir()).thenReturn(new File("target/sonar/solution"));
   when(solution.getSolutionFile()).thenReturn(new File("target/sonar/solution/solution.sln"));
 }
  @Test
  public void testShouldNotExecuteOnProjectUsingPatterns() throws Exception {

    conf.setProperty(GendarmeConstants.ASSEMBLIES_TO_SCAN_KEY, new String[] {"**/*.whatever"});
    conf.setProperty(
        CSharpConstants.BUILD_CONFIGURATION_KEY,
        "DummyBuildConf"); // we simulate no generated assemblies

    when(solution.getSolutionDir()).thenReturn(TestUtils.getResource("/Sensor"));
    when(vsProject.getDirectory()).thenReturn(TestUtils.getResource("/Sensor"));

    Project project = mock(Project.class);
    when(project.getName()).thenReturn("Project #1");
    when(project.getLanguageKey()).thenReturn("cs");

    assertFalse(sensor.shouldExecuteOnProject(project));
  }