public void TestSuggestVersion(string startingVersion, bool hasBreakingChanges, bool hasNonBreakingChanges, string expectedVersion) { var changes = new List <Change>(); if (hasBreakingChanges) { changes.Add(Change.Breaking("breaking")); } if (hasNonBreakingChanges) { changes.Add(Change.NonBreaking("non-breaking")); } var suggestedVersion = PackageDiff.SuggestVersion(new NuGetVersion(startingVersion), changes); Assert.Equal(expectedVersion, suggestedVersion.ToString()); }
public static IReadOnlyDictionary <NuGetFramework, IReadOnlyList <TypeChanges> > ComparePackageTypes(PackageReaderBase package1, PackageReaderBase package2, out NuGetVersion suggestedVersion) { if (package1 == null) { throw new ArgumentNullException(nameof(package1)); } if (package2 == null) { throw new ArgumentNullException(nameof(package2)); } var frameworkChanges = new Dictionary <NuGetFramework, IReadOnlyList <TypeChanges> >(); foreach (var targetFramework in package1.GetSupportedFrameworks()) { var typeChanges = new List <TypeChanges>(); frameworkChanges.Add(targetFramework, typeChanges.AsReadOnly()); var dlls1 = package1.GetAssemblyReferences(targetFramework).ToList(); var dlls2 = package2.GetAssemblyReferences(targetFramework).ToList(); if (dlls1.Count != 0 && dlls2.Count == 0) { typeChanges.Add(new TypeChanges(null, new[] { Change.NonBreaking("Framework support removed: {0}", targetFramework) }.ToList().AsReadOnly())); continue; } var changes = new List <Change>(); foreach (var file1 in dlls1) { if (dlls2.Contains(file1)) { typeChanges.AddRange(FindChanges(package1.GetStream(file1), package2.GetStream(file1))); } else { changes.Add(Change.Breaking("Assembly removed: {0}", file1)); } } if (changes.Count != 0) { typeChanges.Add(new TypeChanges(null, changes.AsReadOnly())); } } suggestedVersion = SuggestVersion(package1.GetIdentity().Version, frameworkChanges.SelectMany(x => x.Value.SelectMany(y => y.Changes)).ToList()); return(frameworkChanges); }