static ConflictResults GetConflicts(MockConflictItem[] itemsToCommit, MockConflictItem[] itemsNotToCommit, ITaskItem[] packageOverrides) { ConflictResults ret = new ConflictResults(); void ConflictHandler(MockConflictItem item) { ret.Conflicts.Add(item); } void UnresolvedConflictHandler(MockConflictItem item) { ret.UnresolvedConflicts.Add(item); } string[] packagesForRank = itemsToCommit.Concat(itemsNotToCommit) .Select(i => i.PackageId) .Where(id => !id.StartsWith("Unranked", StringComparison.OrdinalIgnoreCase)) .Distinct() .OrderBy(id => id) .ToArray(); var overrideResolver = new PackageOverrideResolver <MockConflictItem>(packageOverrides); var resolver = new ConflictResolver <MockConflictItem>(new PackageRank(packagesForRank), overrideResolver, new MockLog()); resolver.ResolveConflicts(itemsToCommit, GetItemKey, ConflictHandler, unresolvedConflict: UnresolvedConflictHandler); resolver.ResolveConflicts(itemsNotToCommit, GetItemKey, ConflictHandler, commitWinner: false, unresolvedConflict: UnresolvedConflictHandler); return(ret); }
public void ItMergesPackageOverridesUsingHighestVersion() { ITaskItem[] packageOverrides = new[] { new MockTaskItem("Platform", new Dictionary <string, string> { { MetadataKeys.OverriddenPackages, "System.Ben|4.2.0;System.Immo|4.2.0;System.Livar|4.3.0;System.Dave|4.2.0" } }), new MockTaskItem("Platform", new Dictionary <string, string> { { MetadataKeys.OverriddenPackages, "System.Ben|4.2.0;System.Immo|4.3.0;System.Livar|4.2.0;System.Nick|4.2.0" } }) }; var resolver = new PackageOverrideResolver <MockConflictItem>(packageOverrides); Assert.Single(resolver.PackageOverrides); PackageOverride packageOverride = resolver.PackageOverrides["Platform"]; Assert.Equal(5, packageOverride.OverriddenPackages.Count); Assert.Equal(new Version(4, 2, 0), packageOverride.OverriddenPackages["System.Ben"]); Assert.Equal(new Version(4, 3, 0), packageOverride.OverriddenPackages["System.Immo"]); Assert.Equal(new Version(4, 3, 0), packageOverride.OverriddenPackages["System.Livar"]); Assert.Equal(new Version(4, 2, 0), packageOverride.OverriddenPackages["System.Dave"]); Assert.Equal(new Version(4, 2, 0), packageOverride.OverriddenPackages["System.Nick"]); }
public void ItHandlesNullITaskItemArray() { var resolver = new PackageOverrideResolver <MockConflictItem>(null); Assert.Null(resolver.PackageOverrides); Assert.Null(resolver.Resolve(new MockConflictItem(), new MockConflictItem())); }
public void ItHandlesNullPackageIds() { ITaskItem[] packageOverrides = new[] { new MockTaskItem("FakePlatform", new Dictionary <string, string> { { MetadataKeys.OverriddenPackages, "System.Ben|4.2.0;System.Jobst-Immo|4.2.0;System.Livar|4.3.0;System.Dave|4.2.0" } }) }; var resolver = new PackageOverrideResolver <MockConflictItem>(packageOverrides); Assert.NotNull(resolver.PackageOverrides); var packageItem = new MockConflictItem("System.Eric") { PackageId = "System.Eric", PackageVersion = new Version(4, 0, 0), AssemblyVersion = new Version(4, 0, 0, 0), ItemType = ConflictItemType.Reference }; var platformItem = new MockConflictItem("System.Eric") { PackageId = null, AssemblyVersion = new Version(4, 1, 0, 0), ItemType = ConflictItemType.Platform }; Assert.Null(resolver.Resolve(packageItem, platformItem)); Assert.Null(resolver.Resolve(platformItem, packageItem)); var packageItem2 = new MockConflictItem("System.Eric") { PackageId = "FakePlatform", PackageVersion = new Version(4, 0, 0), AssemblyVersion = new Version(4, 0, 0, 0), ItemType = ConflictItemType.Reference }; Assert.Null(resolver.Resolve(packageItem2, platformItem)); Assert.Null(resolver.Resolve(platformItem, packageItem2)); }