/// <summary> /// Convert NuGetProjectActions into PreviewResult types /// </summary> protected IEnumerable <PreviewResult> GetPreviewResults(IEnumerable <Tuple <NuGetProject, NuGetProjectAction> > projectActions) { List <PreviewResult> results = new List <PreviewResult>(); var actionsByProject = projectActions.GroupBy(action => action.Item1); foreach (var actions in actionsByProject) { var installed = new Dictionary <string, PackageIdentity>(StringComparer.OrdinalIgnoreCase); var uninstalled = new Dictionary <string, PackageIdentity>(StringComparer.OrdinalIgnoreCase); var packageIds = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (var actionTuple in actions) { packageIds.Add(actionTuple.Item2.PackageIdentity.Id); if (actionTuple.Item2.NuGetProjectActionType == NuGetProjectActionType.Install) { installed[actionTuple.Item2.PackageIdentity.Id] = actionTuple.Item2.PackageIdentity; } else { uninstalled[actionTuple.Item2.PackageIdentity.Id] = actionTuple.Item2.PackageIdentity; } } List <PackageIdentity> added = new List <PackageIdentity>(); List <PackageIdentity> deleted = new List <PackageIdentity>(); List <UpdatePreviewResult> updated = new List <UpdatePreviewResult>(); foreach (var packageId in packageIds) { var isInstalled = installed.ContainsKey(packageId); var isUninstalled = uninstalled.ContainsKey(packageId); if (isInstalled && isUninstalled) { // the package is updated updated.Add(new UpdatePreviewResult(uninstalled[packageId], installed[packageId])); installed.Remove(packageId); } else if (isInstalled && !isUninstalled) { // the package is added added.Add(installed[packageId]); } else if (!isInstalled && isUninstalled) { // the package is deleted deleted.Add(uninstalled[packageId]); } } PreviewResult result = new PreviewResult(actions.Key, added, deleted, updated); results.Add(result); } return(results); }
public void ToString_Always_ReturnsPreviewDescription() { const string ProjectName = "ProjectA"; var added = new List <AccessiblePackageIdentity>(); var deleted = new List <AccessiblePackageIdentity>(); var updated = new List <UpdatePreviewResult>(); added.Add(new AccessiblePackageIdentity(new PackageIdentity("PkgA", new Versioning.NuGetVersion("1.2.3")))); deleted.Add(new AccessiblePackageIdentity(new PackageIdentity("PkgB", new Versioning.NuGetVersion("3.2.1")))); updated.Add(new UpdatePreviewResult( new PackageIdentity("PkgC", new Versioning.NuGetVersion("1.0.0")), new PackageIdentity("PkgC", new Versioning.NuGetVersion("2.0.0")))); var previewResult = new PreviewResult(ProjectName, added, deleted, updated); var allResults = new List <PreviewResult>(); allResults.Add(previewResult); var model = new PreviewWindowModel(allResults); var sb = new StringBuilder(); sb.AppendLine(ProjectName); sb.AppendLine(); sb.AppendLine(Resources.Label_UninstalledPackages); sb.AppendLine(); foreach (AccessiblePackageIdentity packageIdentity in deleted) { sb.AppendLine(packageIdentity.ToString()); } sb.AppendLine(); sb.AppendLine(Resources.Label_UpdatedPackages); sb.AppendLine(); foreach (UpdatePreviewResult result in updated) { sb.AppendLine(result.ToString()); } sb.AppendLine(); sb.AppendLine(Resources.Label_InstalledPackages); sb.AppendLine(); foreach (AccessiblePackageIdentity packageIdentity in added) { sb.AppendLine(packageIdentity.ToString()); } sb.AppendLine(); Assert.Equal(sb.ToString(), model.ToString()); }
public void PreviewWindowModelToString_Test() { var added = new List <AccessiblePackageIdentity>(); var deleted = new List <AccessiblePackageIdentity>(); var updated = new List <UpdatePreviewResult>(); added.Add(new AccessiblePackageIdentity(new PackageIdentity("PkgA", new Versioning.NuGetVersion("1.2.3")))); deleted.Add(new AccessiblePackageIdentity(new PackageIdentity("PkgB", new Versioning.NuGetVersion("3.2.1")))); updated.Add(new UpdatePreviewResult( new PackageIdentity("PkgC", new Versioning.NuGetVersion("1.0.0")), new PackageIdentity("PkgC", new Versioning.NuGetVersion("2.0.0")) )); var ProjA = new MockProject(); var previewResult = new PreviewResult(ProjA, added, deleted, updated); var allResults = new List <PreviewResult>(); allResults.Add(previewResult); var model = new PreviewWindowModel(allResults); var sb = new StringBuilder(); sb.AppendLine(Resources.Preview_UnknownProject); sb.AppendLine(); sb.AppendLine(Resources.Label_UninstalledPackages); sb.AppendLine(); foreach (var p in deleted) { sb.AppendLine(p.ToString()); } sb.AppendLine(); sb.AppendLine(Resources.Label_UpdatedPackages); sb.AppendLine(); foreach (var p in updated) { sb.AppendLine(p.ToString()); } sb.AppendLine(); sb.AppendLine(Resources.Label_InstalledPackages); sb.AppendLine(); foreach (var p in added) { sb.AppendLine(p.ToString()); } sb.AppendLine(); Assert.Equal(sb.ToString(), model.ToString()); }
/// <summary> /// Convert NuGetProjectActions into PreviewResult types /// </summary> private static IReadOnlyList <PreviewResult> GetPreviewResults(IEnumerable <ResolvedAction> projectActions) { var results = new List <PreviewResult>(); var expandedActions = new List <ResolvedAction>(); // BuildIntegratedProjectActions contain all project actions rolled up into a single action, // to display these we need to expand them into the low level actions. foreach (var action in projectActions) { var buildIntegratedAction = action.Action as BuildIntegratedProjectAction; if (buildIntegratedAction != null) { foreach (var buildAction in buildIntegratedAction.GetProjectActions()) { expandedActions.Add(new ResolvedAction(action.Project, buildAction)); } } else { // leave the action as is expandedActions.Add(action); } } // Group actions by project var actionsByProject = expandedActions.GroupBy(action => action.Project); // Group actions by operation foreach (var actions in actionsByProject) { var installed = new Dictionary <string, PackageIdentity>(StringComparer.OrdinalIgnoreCase); var uninstalled = new Dictionary <string, PackageIdentity>(StringComparer.OrdinalIgnoreCase); var packageIds = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (var action in actions.Select(a => a.Action)) { var package = action.PackageIdentity; packageIds.Add(package.Id); // Create new identities without the dependency graph if (action.NuGetProjectActionType == NuGetProjectActionType.Install) { installed[package.Id] = new PackageIdentity(package.Id, package.Version); } else { uninstalled[package.Id] = new PackageIdentity(package.Id, package.Version); } } var added = new List <PackageIdentity>(); var deleted = new List <PackageIdentity>(); var updated = new List <UpdatePreviewResult>(); foreach (var packageId in packageIds) { var isInstalled = installed.ContainsKey(packageId); var isUninstalled = uninstalled.ContainsKey(packageId); if (isInstalled && isUninstalled) { // the package is updated updated.Add(new UpdatePreviewResult(uninstalled[packageId], installed[packageId])); installed.Remove(packageId); } else if (isInstalled && !isUninstalled) { // the package is added added.Add(installed[packageId]); } else if (!isInstalled && isUninstalled) { // the package is deleted deleted.Add(uninstalled[packageId]); } } var result = new PreviewResult(actions.Key, added, deleted, updated); results.Add(result); } return(results); }
/// <summary> /// Convert NuGetProjectActions into PreviewResult types /// </summary> protected IEnumerable<PreviewResult> GetPreviewResults(IEnumerable<Tuple<NuGetProject, NuGetProjectAction>> projectActions) { List<PreviewResult> results = new List<PreviewResult>(); var actionsByProject = projectActions.GroupBy(action => action.Item1); foreach (var actions in actionsByProject) { var installed = new Dictionary<string, PackageIdentity>(StringComparer.OrdinalIgnoreCase); var uninstalled = new Dictionary<string, PackageIdentity>(StringComparer.OrdinalIgnoreCase); var packageIds = new HashSet<string>(StringComparer.OrdinalIgnoreCase); foreach (var actionTuple in actions) { packageIds.Add(actionTuple.Item2.PackageIdentity.Id); if (actionTuple.Item2.NuGetProjectActionType == NuGetProjectActionType.Install) { installed[actionTuple.Item2.PackageIdentity.Id] = actionTuple.Item2.PackageIdentity; } else { uninstalled[actionTuple.Item2.PackageIdentity.Id] = actionTuple.Item2.PackageIdentity; } } List<PackageIdentity> added = new List<PackageIdentity>(); List<PackageIdentity> deleted = new List<PackageIdentity>(); List<UpdatePreviewResult> updated = new List<UpdatePreviewResult>(); foreach (var packageId in packageIds) { var isInstalled = installed.ContainsKey(packageId); var isUninstalled = uninstalled.ContainsKey(packageId); if (isInstalled && isUninstalled) { // the package is updated updated.Add(new UpdatePreviewResult(uninstalled[packageId], installed[packageId])); installed.Remove(packageId); } else if (isInstalled && !isUninstalled) { // the package is added added.Add(installed[packageId]); } else if (!isInstalled && isUninstalled) { // the package is deleted deleted.Add(uninstalled[packageId]); } } PreviewResult result = new PreviewResult(actions.Key, added, deleted, updated); results.Add(result); } return results; }