public void ProjectLoader()
        {
            // Arrange
            var testSourcePath = TestUtils.CreateTestSpecificFolder(TestContext);

            // Create sub-directories, some with project info XML files and some without
            TestUtils.EnsureTestSpecificFolder(TestContext, "EmptyDir1");

            var validTestProject = new ProjectDescriptor()
            {
                ParentDirectoryPath = testSourcePath,
                ProjectFolderName = "validTestProjectDir",
                ProjectFileName = "validTestProject.csproj",
                ProjectGuid = Guid.NewGuid(),
                IsTestProject = true
            };
            validTestProject.AddCompileInputFile("TestFile1.cs", true);
            validTestProject.AddCompileInputFile("TestFile1.cs", true);
            validTestProject.AddContentFile("contentFile1.js", true);
            CreateFilesFromDescriptor(validTestProject, "testCompileListFile", "testVisualStudioCodeCoverageReport");

            TestUtils.EnsureTestSpecificFolder(TestContext, "EmptyDir2");

            var validNonTestProject = new ProjectDescriptor()
            {
                ParentDirectoryPath = testSourcePath,
                ProjectFolderName = "validNonTestProjectDir",
                ProjectFileName = "validNonTestproject.proj",
                ProjectGuid = Guid.NewGuid(),
                IsTestProject = false
            };
            validNonTestProject.AddContentFile("ASourceFile.vb", true);
            validNonTestProject.AddContentFile("AnotherSourceFile.vb", true);
            CreateFilesFromDescriptor(validNonTestProject, "list.txt", "visualstudio-codecoverage.xml");

            var validNonTestNoReportsProject = new ProjectDescriptor()
            {
                ParentDirectoryPath = testSourcePath,
                ProjectFolderName = "validNonTestNoReportsProjectDir",
                ProjectFileName = "validNonTestNoReportsProject.proj",
                ProjectGuid = Guid.NewGuid(),
                IsTestProject = false
            };
            validNonTestNoReportsProject.AddContentFile("SomeFile.cs", true);
            CreateFilesFromDescriptor(validNonTestNoReportsProject, "SomeList.txt", null);

            // Act
            IEnumerable<ProjectInfo> projects = SonarScanner.MSBuild.Shim.ProjectLoader.LoadFrom(testSourcePath);

            // Assert
            Assert.AreEqual(3, projects.Count());

            AssertProjectResultExists(validTestProject.ProjectName, projects);

            AssertProjectResultExists(validNonTestProject.ProjectName, projects);

            AssertProjectResultExists(validNonTestNoReportsProject.ProjectName, projects);
        }
Example #2
0
        private static void AddEmptyContentFile(ProjectDescriptor descriptor, string projectFolder)
        {
            string filePath = CreateEmptyFile(projectFolder, "txt");

            descriptor.AddContentFile(filePath, true);
        }