// For unit testing purposes internal static async ValueTask <PackageItemLoader> CreateAsync( IServiceBroker serviceBroker, PackageLoadContext context, IReadOnlyCollection <PackageSourceContextInfo> packageSources, ContractItemFilter itemFilter, IReconnectingNuGetSearchService searchService, INuGetPackageFileService packageFileService, string searchText = null, bool includePrerelease = true, bool useRecommender = false) { var itemLoader = new PackageItemLoader( serviceBroker, searchService, context, packageSources, itemFilter, searchText, includePrerelease, useRecommender); await itemLoader.InitializeAsync(packageFileService); return(itemLoader); }
public ValueTask <IReadOnlyCollection <PackageSearchMetadataContextInfo> > GetAllPackagesAsync( IReadOnlyCollection <IProjectContextInfo> projectContextInfos, IReadOnlyCollection <PackageSourceContextInfo> packageSources, IReadOnlyCollection <string> targetFrameworks, SearchFilter searchFilter, NuGet.VisualStudio.Internal.Contracts.ItemFilter itemFilter, CancellationToken cancellationToken) { return(_parent._service.GetAllPackagesAsync(projectContextInfos, packageSources, targetFrameworks, searchFilter, itemFilter, cancellationToken)); }
public ValueTask <int> GetTotalCountAsync( int maxCount, IReadOnlyCollection <IProjectContextInfo> projectContextInfos, IReadOnlyCollection <PackageSourceContextInfo> packageSources, IReadOnlyCollection <string> targetFrameworks, SearchFilter searchFilter, NuGet.VisualStudio.Internal.Contracts.ItemFilter itemFilter, CancellationToken cancellationToken) { return(_parent._service.GetTotalCountAsync(maxCount, projectContextInfos, packageSources, targetFrameworks, searchFilter, itemFilter, cancellationToken)); }
public ValueTask <SearchResultContextInfo> SearchAsync( IReadOnlyCollection <IProjectContextInfo> projectContextInfos, IReadOnlyCollection <PackageSourceContextInfo> packageSources, IReadOnlyCollection <string> targetFrameworks, string searchText, SearchFilter searchFilter, NuGet.VisualStudio.Internal.Contracts.ItemFilter itemFilter, bool useRecommender, CancellationToken cancellationToken) { return(_parent._service.SearchAsync(projectContextInfos, packageSources, targetFrameworks, searchText, searchFilter, itemFilter, useRecommender, cancellationToken)); }
private PackageItemLoader( IServiceBroker serviceBroker, PackageLoadContext context, IReadOnlyCollection <PackageSourceContextInfo> packageSources, ContractItemFilter itemFilter, string searchText, bool includePrerelease, bool useRecommender) { Assumes.NotNull(serviceBroker); Assumes.NotNull(context); Assumes.NotNullOrEmpty(packageSources); _serviceBroker = serviceBroker; _context = context; _searchText = searchText ?? string.Empty; _includePrerelease = includePrerelease; _packageSources = packageSources; _itemFilter = itemFilter; _useRecommender = useRecommender; }
public async Task CreateInstallAction_OnInstallingProject_EmitsPkgWasTransitiveTelemetryAndTabAndIsSolutionPropertiesAsync(ContractsItemFilter activeTab, bool isSolutionLevel, string packageIdToInstall, bool?expectedPkgWasTransitive) { // Arrange var telemetrySession = new Mock <ITelemetrySession>(); TelemetryEvent lastTelemetryEvent = null; telemetrySession .Setup(x => x.PostEvent(It.IsAny <TelemetryEvent>())) .Callback <TelemetryEvent>(x => lastTelemetryEvent = x); var telemetryService = new NuGetVSTelemetryService(telemetrySession.Object); TelemetryActivity.NuGetTelemetryService = telemetryService; var sourceProvider = new Mock <ISourceRepositoryProvider>(); var settings = new Mock <ISettings>(); var nugetPM = new NuGetPackageManager(sourceProvider.Object, settings.Object, @"\packagesFolder"); var lockService = new NuGetLockService(ThreadHelper.JoinableTaskContext); var uiEngine = new UIActionEngine(sourceProvider.Object, nugetPM, lockService); var installedAndTransitive = new InstalledAndTransitivePackages( new[] { new PackageReferenceContextInfo(new PackageIdentity("installedA", NuGetVersion.Parse("1.0.0")), NuGetFramework.Parse("net472")), new PackageReferenceContextInfo(new PackageIdentity("installedB", NuGetVersion.Parse("1.0.0")), NuGetFramework.Parse("net472")) }, new[] { new TransitivePackageReferenceContextInfo(new PackageIdentity("transitiveA", NuGetVersion.Parse("1.0.0")), NuGetFramework.Parse("net472")) }); var prjMgrSvc = new Mock <INuGetProjectManagerService>(); prjMgrSvc .Setup(mgr => mgr.GetInstalledAndTransitivePackagesAsync(It.IsAny <IReadOnlyCollection <string> >(), It.IsAny <CancellationToken>())) .Returns(new ValueTask <IInstalledAndTransitivePackages>(installedAndTransitive)); var dictMetadata = new Dictionary <string, object> { [NuGetProjectMetadataKeys.UniqueName] = "a", [NuGetProjectMetadataKeys.ProjectId] = "a" }; ProjectMetadataContextInfo metadataCtxtInfo = ProjectMetadataContextInfo.Create(dictMetadata); prjMgrSvc .Setup(mgr => mgr.GetMetadataAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())) .Returns(new ValueTask <IProjectMetadataContextInfo>(metadataCtxtInfo)); var uiService = new Mock <INuGetUI>(); var uiContext = new Mock <INuGetUIContext>(); var projectContext = new Mock <INuGetProjectContext>(); var serviceBroker = new Mock <IServiceBroker>(); _ = serviceBroker.Setup(sb => sb.GetProxyAsync <INuGetProjectManagerService>( It.Is <ServiceRpcDescriptor>(s => s == NuGetServices.ProjectManagerService), It.IsAny <ServiceActivationOptions>(), It.IsAny <CancellationToken>())) .Returns(new ValueTask <INuGetProjectManagerService>(prjMgrSvc.Object)); uiContext.Setup(ctx => ctx.ServiceBroker).Returns(serviceBroker.Object); uiService.Setup(ui => ui.UIContext).Returns(uiContext.Object); uiService.Setup(ui => ui.ProjectContext).Returns(projectContext.Object); uiService.Setup(ui => ui.Settings).Returns(settings.Object); uiService.Setup(ui => ui.Projects).Returns(new[] { new ProjectContextInfo("a", ProjectModel.ProjectStyle.PackageReference, NuGetProjectKind.PackageReference) }); var action = UserAction.CreateInstallAction(packageIdToInstall, NuGetVersion.Parse("1.0.0"), isSolutionLevel, activeTab); // Act await uiEngine.PerformInstallOrUninstallAsync(uiService.Object, action, CancellationToken.None); // Assert Assert.NotNull(lastTelemetryEvent); // expect failed action because we mocked just enough objects to emit telemetry Assert.Equal(NuGetOperationStatus.Failed, lastTelemetryEvent[nameof(ActionEventBase.Status)]); Assert.Equal(NuGetOperationType.Install, lastTelemetryEvent[nameof(ActionsTelemetryEvent.OperationType)]); Assert.Equal(isSolutionLevel, lastTelemetryEvent[nameof(VSActionsTelemetryEvent.IsSolutionLevel)]); Assert.Equal(activeTab, lastTelemetryEvent[nameof(VSActionsTelemetryEvent.Tab)]); Assert.Equal(expectedPkgWasTransitive, lastTelemetryEvent[nameof(VSActionsTelemetryEvent.PackageToInstallWasTransitive)]); }