Exemplo n.º 1
0
        public static bool TryLoadFromFile(string path, out Project project)
        {
            if (string.IsNullOrEmpty(path))
            {
                project = null;
                return(false);
            }

            XDocument doc;

            try
            {
                doc = XDocument.Load(path);
            }
            catch (DirectoryNotFoundException)
            {
                project = null;
                return(false);
            }
            catch (FileNotFoundException)
            {
                project = null;
                return(false);
            }

            var        nameNode             = doc.XPathSelectElement(@"/x:Project/x:PropertyGroup/x:AssemblyName", NamespaceManager);
            var        projectInfoNode      = doc.XPathSelectElement(ProjectInfoXPath, NamespaceManager);
            XAttribute projectTypeAttribute = null;

            if (projectInfoNode != null)
            {
                projectTypeAttribute = projectInfoNode.Attribute("Type");
            }
            if (nameNode == null)
            {
                project = null;
                return(false);
            }
            if (projectInfoNode != null)
            {
                var skippedNode = projectInfoNode.Attribute("Skip");
                if (skippedNode != null && skippedNode.Value == "true")
                {
                    project = null;
                    return(false);
                }

                var type = projectTypeAttribute != null?ProjectTypeHelper.Parse(projectTypeAttribute.Value) : ProjectType.Unknown;

                project = type.CreateInstance(nameNode.Value, path);
            }
            else
            {
                project = new UnknownProject(nameNode.Value, path);
            }

            return(project.TryLoad(doc));
        }
Exemplo n.º 2
0
 public void IsTestAssemblyName_ReturnsExpectedValue()
 {
     ProjectTypeHelper.IsTestAssemblyName("SonarAnalyzer.UnitTest").Should().BeTrue();
     ProjectTypeHelper.IsTestAssemblyName("SonarLint.VisualStudio.Integration.UnitTests").Should().BeTrue();
     ProjectTypeHelper.IsTestAssemblyName("SonarLint.VisualStudio.Integration.TestInfrastructure").Should().BeTrue();
     ProjectTypeHelper.IsTestAssemblyName("Nancy.Demo.Authentication.Forms.TestingDemo").Should().BeFalse();
     ProjectTypeHelper.IsTestAssemblyName("SonarAnalyzer.BestEstimator").Should().BeFalse();
     ProjectTypeHelper.IsTestAssemblyName("RainbowTeam.TheCutestPony").Should().BeFalse();
 }