Skip to content

Commit

Permalink
Fixes #12
Browse files Browse the repository at this point in the history
  • Loading branch information
hvanbakel committed Jun 8, 2017
1 parent 78e85cd commit df5c36e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Project2015To2017/NugetPackageTransformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,30 @@ private void ExtractPackageConfiguration(Project definition, XDocument nuspec, X
ReleaseNotes = ReadValueAndReplace(metadata, ns + "releaseNotes", definition.AssemblyAttributes),
RequiresLicenseAcceptance = metadata.Element(ns + "requireLicenseAcceptance")?.Value != null ? bool.Parse(metadata.Element(ns + "requireLicenseAcceptance")?.Value) : false
};

var dependencies = metadata.Element(ns + "dependencies")?.Elements(ns + "dependency");
if (dependencies != null)
{
foreach (var dependency in dependencies)
{
var packageId = dependency.Attribute("id").Value;
var constraint = dependency.Attribute("version").Value;

var packageReference = definition.PackageReferences?.FirstOrDefault(x => x.Id.Equals(packageId, StringComparison.OrdinalIgnoreCase));
if (packageReference != null)
{
packageReference.Version = constraint;
}
}
}
}
}

private void ConvertVersionConstraints(XElement dependencies, IReadOnlyList<PackageReference> packageReferences)
{
throw new NotImplementedException();
}

private string ReadValueAndReplace(XElement metadata, XName elementName, AssemblyAttributes assemblyAttributes)
{
var value = metadata.Element(elementName)?.Value;
Expand Down
20 changes: 20 additions & 0 deletions Project2015To2017Tests/NugetPackageTransformationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
Expand Down Expand Up @@ -41,5 +42,24 @@ public async Task ConvertsNuspecAsync()
Assert.AreEqual("someurl", project.PackageConfiguration.LicenseUrl);
Assert.AreEqual("Some long\n text\n with newlines", project.PackageConfiguration.ReleaseNotes.Trim());
}

[TestMethod]
public async Task ConvertsDependencies()
{
var project = new Project();

var directoryInfo = new DirectoryInfo(".\\TestFiles");
var doc = XDocument.Load("TestFiles\\net46console.testcsproj");

project.PackageReferences = new[]
{
new PackageReference { Id = "Newtonsoft.Json", Version = "10.0.2" },
new PackageReference { Id = "Other.Package", Version = "1.0.2" }
};
await new NugetPackageTransformation().TransformAsync(doc, directoryInfo, project).ConfigureAwait(false);

Assert.AreEqual("[10.0.2,11)", project.PackageReferences.Single(x => x.Id == "Newtonsoft.Json").Version);
Assert.AreEqual("1.0.2", project.PackageReferences.Single(x => x.Id == "Other.Package").Version);
}
}
}
Binary file modified Project2015To2017Tests/TestFiles/test.nuspec
Binary file not shown.

0 comments on commit df5c36e

Please sign in to comment.