private ProjectMetadata ProcessProject(SourceInformation projectSourceInformation) { _logger.Trace("Entering"); OnItemProcessing(new ItemParsingEventArgs(projectSourceInformation)); Tools.FixPathSeparators(projectSourceInformation); Tools.FixPathEnding(projectSourceInformation); var filename = Path.GetFileName(projectSourceInformation.SourcePath); var sourceTool = GetSourceTool(); var sw = Stopwatch.StartNew(); var projectContent = sourceTool.GetItemContent(projectSourceInformation); sw.Stop(); _logger.Trace($"Getting items took {sw.Elapsed}"); var project = CsProjectParser.ParseProjectFileContent(projectContent, filename); var output = ProjectMetadata.MapFromProject(project); output.SourceInformation = projectSourceInformation; return(output); }
public static void ParseProjectFileContent_ReturnsExpectedResult_Old() { const string filename = "old.csproj.txt"; var content = Helpers.ReadEmbeddedResourceFile(filename); var result = CsProjectParser.ParseProjectFileContent(content, System.IO.Path.GetFileNameWithoutExtension(filename)); Assert.That(result, Is.Not.Null); Assert.Multiple( () => { Assert.That( result.AssemblyInformation.FirstOrDefault( x => x.Key.Equals("AssemblyName", StringComparison.CurrentCultureIgnoreCase)) .Value, Is.EqualTo("UPMC.Web.WcfRestHttp")); Assert.That(result.HasMessages, Is.False); Assert.That(result.ProjectFileFormat, Is.EqualTo(ProjectFileFormat.Vs2015OrEarlier)); Assert.That(result.ProjectOutputType, Is.EqualTo(ProjectOutputType.Library)); Assert.That(result.Sdk, Is.Null); Helpers.AssertHasCountOf(result.AssemblyReferences, 60); Helpers.AssertHasCountOf(result.Configurations, 2); Helpers.AssertHasCountOf(result.Frameworks, 1); Assert.That(result.Frameworks.FirstOrDefault(), Is.EqualTo("net461")); Helpers.AssertHasCountOf(result.PackageReferences, 0); Helpers.AssertHasCountOf(result.ProjectReferences, 8); AssertSolutionInformationMissing(result); }); // todo Do more asserts here. }
public static void ParseProjectFileContent_ReturnsExpectedResult_New() { // Arrange const string filename = "new.csproj.txt"; var content = Helpers.ReadEmbeddedResourceFile(filename); // Act var result = CsProjectParser.ParseProjectFileContent(content, System.IO.Path.GetFileNameWithoutExtension(filename)); // Assert Assert.That(result, Is.Not.Null); Assert.Multiple( () => { Assert.That( result.AssemblyInformation.FirstOrDefault( x => x.Key.Equals("AssemblyName", StringComparison.CurrentCultureIgnoreCase)) .Value, Is.Null); Assert.That(result.HasMessages, Is.False); Assert.That(result.ProjectFileFormat, Is.EqualTo(ProjectFileFormat.Vs2017OrLater)); Assert.That(result.ProjectOutputType, Is.EqualTo(ProjectOutputType.Library)); Assert.That(result.Sdk, Is.EqualTo("Microsoft.NET.Sdk")); Helpers.AssertHasCountOf(result.AssemblyReferences, 6); Helpers.AssertHasCountOf(result.Configurations, 2); Helpers.AssertHasCountOf(result.Frameworks, 2); Assert.That(result.Frameworks.FirstOrDefault(), Is.EqualTo("net461")); // ReSharper disable once StringLiteralTypo Assert.That(result.Frameworks.LastOrDefault(), Is.EqualTo("netcoreapp2.0")); Helpers.AssertHasCountOf(result.PackageReferences, 8); Helpers.AssertHasCountOf(result.ProjectReferences, 0); AssertSolutionInformationMissing(result); }); // todo Do more asserts here. }
public static void ParseProjectFileContent_Throws(string content, string path) { Assert.Throws <ArgumentException>(() => CsProjectParser.ParseProjectFileContent(content, path)); }