Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' into test-the-api-package-lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Cohen authored Jul 24, 2017
2 parents 1cbc2cd + 4018d22 commit 5bab41d
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 21 deletions.
2 changes: 1 addition & 1 deletion NuKeeper.Tests/Engine/CommitReportTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void TwoUpdates_MakeCommitDetails_HasVersionInfo()
var report = CommitReport.MakeCommitDetails(updates);

Assert.That(report, Does.StartWith("NuKeeper has generated an update of `foo.bar` to `1.2.3`"));
Assert.That(report, Does.Contain("2 versions of `foo.bar` were found in use: `1.1.0`,`1.0.0`"));
Assert.That(report, Does.Contain("2 versions of `foo.bar` were found in use: `1.1.0`, `1.0.0`"));
}

[Test]
Expand Down
11 changes: 11 additions & 0 deletions NuKeeper.Tests/RepositoryInspection/PackagesFileReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ public void ResultIsReiterable()
Assert.That(packages.Select(p => p.Path), Is.All.EqualTo(path));
}

[Test]
public void WhenOnePackageCannotBeRead_TheOthersAreStillRead()
{
var badVersion = PackagesFileWithTwoPackages.Replace("1.2.3.4", "notaversion");
var packages = PackagesFileReader.Read(badVersion, TempPath())
.ToList();

Assert.That(packages.Count, Is.EqualTo(1));
PackageAssert.IsPopulated(packages[0]);
}

private PackagePath TempPath()
{
return new PackagePath("c:\\temp\\somewhere", "src\\packages.config",
Expand Down
16 changes: 16 additions & 0 deletions NuKeeper.Tests/RepositoryInspection/ProjectFileReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,22 @@ public void ResultIsReiterable()
Assert.That(packages.Select(p=>p.Path), Is.All.EqualTo(path));
}

[Test]
public void WhenOnePackageCannotBeRead_TheOthersAreStillRead()
{
const string packagesText =
@"<PackageReference Include=""foo"" Version=""notaversion""></PackageReference>
<PackageReference Include=""bar"" Version=""2.3.4""></PackageReference>";

var projectFile = Vs2017ProjectFileTemplateWithPackages.Replace("{{Packages}}", packagesText);

var packages = ProjectFileReader.Read(projectFile, TempPath())
.ToList();

Assert.That(packages.Count, Is.EqualTo(1));
PackageAssert.IsPopulated(packages[0]);
}

private PackagePath TempPath()
{
return new PackagePath("c:\\temp\\somewhere", "src\\packages.config",
Expand Down
10 changes: 5 additions & 5 deletions NuKeeper/Engine/CommitReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ public static string MakeCommitMessage(PackageUpdateSet updates)
public static string MakeCommitDetails(PackageUpdateSet updates)
{
var oldVersions = updates.CurrentPackages
.Select(u => CodeQuote(u.Version.ToString()))
.Select(u => u.Version)
.Distinct()
.Select(v => CodeQuote(v.ToString()))
.ToList();

var oldVersionsString = string.Join(",", oldVersions);

var newVersion = CodeQuote(updates.NewVersion.ToString());
var packageId = CodeQuote(updates.PackageId);

var builder = new StringBuilder();

if (oldVersions.Count == 1)
{
builder.AppendLine($"NuKeeper has generated an update of {packageId} to {newVersion} from {oldVersionsString}");
builder.AppendLine($"NuKeeper has generated an update of {packageId} to {newVersion} from {oldVersions.JoinWithCommas()}");
}
else
{
builder.AppendLine($"NuKeeper has generated an update of {packageId} to {newVersion}");
builder.AppendLine($"{oldVersions.Count} versions of {packageId} were found in use: {oldVersionsString}");
builder.AppendLine($"{oldVersions.Count} versions of {packageId} were found in use: {oldVersions.JoinWithCommas()}");
}

if (updates.CurrentPackages.Count == 1)
Expand Down
7 changes: 2 additions & 5 deletions NuKeeper/Engine/EngineReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public static void PackagesFound(List<PackageInProject> packages)

Console.WriteLine($"Found {packages.Count} packages in use, {packageIds.Count} distinct, in {projectPathCount} projects.");

var packageIdsText = string.Join(", ", packageIds);
Console.WriteLine(packageIdsText);
Console.WriteLine(packageIds.JoinWithCommas());
}

public static void UpdatesFound(List<PackageUpdateSet> updates)
Expand All @@ -45,9 +44,7 @@ public static void OldVersionsToBeUpdated(PackageUpdateSet updateSet)
.Select(u => u.Version.ToString())
.Distinct();

var oldVersionsString = string.Join(", ", oldVersions);

Console.WriteLine($"Updating '{updateSet.PackageId}' from {oldVersionsString} to {updateSet.NewVersion} in {updateSet.CurrentPackages.Count()} projects");
Console.WriteLine($"Updating '{updateSet.PackageId}' from {oldVersions.JoinWithCommas()} to {updateSet.NewVersion} in {updateSet.CurrentPackages.Count()} projects");
}
}
}
3 changes: 1 addition & 2 deletions NuKeeper/RepositoryInspection/PackageUpdateSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public PackageUpdateSet(PackageIdentity newPackage, IEnumerable<PackageInProject
.Distinct()
.Where(id => id != newPackage.Id);

var errorIdString = string.Join(", ", errorIds);
throw new ArgumentException($"Updates must all be for package '{newPackage.Id}', got '{errorIdString}'");
throw new ArgumentException($"Updates must all be for package '{newPackage.Id}', got '{errorIds.JoinWithCommas()}'");
}

NewPackage = newPackage;
Expand Down
19 changes: 15 additions & 4 deletions NuKeeper/RepositoryInspection/PackagesFileReader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
Expand Down Expand Up @@ -28,15 +29,25 @@ public static IEnumerable<PackageInProject> Read(string fileContents, PackagePat

return packageNodeList
.Select(el => XmlToPackage(el, path))
.Where(el => el != null)
.ToList();
}

private static PackageInProject XmlToPackage(XElement el, PackagePath path)
{
var id = el.Attribute("id")?.Value;
var version = el.Attribute("version")?.Value;
try
{
var id = el.Attribute("id")?.Value;
var version = el.Attribute("version")?.Value;

return new PackageInProject(id, version, path);

return new PackageInProject(id, version, path);
}
catch (Exception ex)
{
Console.WriteLine($"Could not read package from {el}: {ex.Message}");
return null;
}
}
}
}
18 changes: 14 additions & 4 deletions NuKeeper/RepositoryInspection/ProjectFileReader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
Expand Down Expand Up @@ -28,15 +29,24 @@ public static IEnumerable<PackageInProject> Read(string fileContents, PackagePat

return packageRefs
.Select(el => XmlToPackage(el, path))
.Where(el => el != null)
.ToList();
}

private static PackageInProject XmlToPackage(XElement el, PackagePath path)
{
var id = el.Attribute("Include")?.Value;
var version = el.Attribute("Version")?.Value;
try
{
var id = el.Attribute("Include")?.Value;
var version = el.Attribute("Version")?.Value;

return new PackageInProject(id, version, path);
return new PackageInProject(id, version, path);
}
catch (Exception ex)
{
Console.WriteLine($"Could not read package from {el}: {ex.Message}");
return null;
}
}
}
}
17 changes: 17 additions & 0 deletions NuKeeper/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Collections.Generic;

namespace NuKeeper
{
public static class StringExtensions
{
public static string JoinWithCommas(this IEnumerable<string> values)
{
if (values == null)
{
return string.Empty;
}

return string.Join(", ", values);
}
}
}

0 comments on commit 5bab41d

Please sign in to comment.