protected override Task LoadPackagesAsync (PackageItemLoader loader, CancellationToken token) { if (LoadPackagesAsyncTask != null) { return LoadPackagesAsyncTask (loader, token); } return base.LoadPackagesAsync (loader, token); }
public async Task PackagePrefixReservation_FromOneSource() { var solutionManager = Mock.Of <INuGetSolutionManagerService>(); var uiContext = new Mock <INuGetUIContext>(); uiContext.Setup(x => x.SolutionManagerService) .Returns(solutionManager); uiContext.Setup(x => x.ServiceBroker) .Returns(Mock.Of <IServiceBroker>()); // Arrange var responses = new Dictionary <string, string> { { "https://api-v3search-0.nuget.org/query?q=EntityFramework&skip=0&take=26&prerelease=false&semVerLevel=2.0.0", ProtocolUtility.GetResource("NuGet.PackageManagement.UI.Test.compiler.resources.EntityFrameworkSearch.json", GetType()) }, { "http://testsource.com/v3/index.json", JsonData.IndexWithoutFlatContainer } }; var repo = StaticHttpHandler.CreateSource("http://testsource.com/v3/index.json", Repository.Provider.GetCoreV3(), responses); var repositories = new List <SourceRepository> { repo }; var context = new PackageLoadContext(repositories, isSolution: false, uiContext.Object); var packageFeed = new MultiSourcePackageFeed(repositories, logger: null, telemetryService: null); var loader = new PackageItemLoader(context, packageFeed, "EntityFramework", includePrerelease: false); var loaded = new List <PackageItemListViewModel>(); foreach (var page in Enumerable.Range(0, 5)) { await loader.LoadNextAsync(progress : null, CancellationToken.None); while (loader.State.LoadingStatus == LoadingStatus.Loading) { await Task.Delay(TimeSpan.FromSeconds(1)); await loader.UpdateStateAsync(progress : null, CancellationToken.None); } var items = loader.GetCurrent(); loaded.AddRange(items); if (loader.State.LoadingStatus != LoadingStatus.Ready) { break; } } // Resource only has one item var item = loaded.First(); Assert.True(item.PrefixReserved); }
protected override Task LoadPackagesAsync(PackageItemLoader loader, CancellationToken token) { if (LoadPackagesAsyncTask != null) { return(LoadPackagesAsyncTask(loader, token)); } return(base.LoadPackagesAsync(loader, token)); }
public async Task GetCurrent_WithAnySearchResults_PreservesSearchResultsOrderAsync(string[] inputIds) { // Arrange var psmContextInfos = new List <PackageSearchMetadataContextInfo>(); foreach (var id in inputIds) { psmContextInfos.Add(PackageSearchMetadataContextInfo.Create(new PackageSearchMetadataBuilder.ClonedPackageSearchMetadata() { Identity = new PackageIdentity(id, new NuGetVersion("1.0")), })); } var searchResult = new SearchResultContextInfo(psmContextInfos, new Dictionary <string, LoadingStatus> { { "Search", LoadingStatus.Loading } }, hasMoreItems: false); var serviceBroker = Mock.Of <IServiceBroker>(); var packageFileService = new Mock <INuGetPackageFileService>(); var searchService = new Mock <IReconnectingNuGetSearchService>(MockBehavior.Strict); searchService.Setup(s => s.SearchAsync(It.IsAny <IReadOnlyCollection <IProjectContextInfo> >(), It.IsAny <IReadOnlyCollection <PackageSourceContextInfo> >(), It.IsAny <IReadOnlyCollection <string> >(), It.IsAny <string>(), It.IsAny <SearchFilter>(), It.IsAny <NuGet.VisualStudio.Internal.Contracts.ItemFilter>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <CancellationToken>())) .Returns(new ValueTask <SearchResultContextInfo>(searchResult)); var uiContext = new Mock <INuGetUIContext>(); uiContext.Setup(ui => ui.ServiceBroker).Returns(serviceBroker); var context = new PackageLoadContext(isSolution: false, uiContext.Object); var mockProgress = Mock.Of <IProgress <IItemLoaderState> >(); using var localFeedDir = TestDirectory.Create(); // local feed var localSource = new PackageSource(localFeedDir); var loader = await PackageItemLoader.CreateAsync( serviceBroker, context, new List <PackageSourceContextInfo>() { PackageSourceContextInfo.Create(localSource) }, NuGet.VisualStudio.Internal.Contracts.ItemFilter.All, searchService.Object, packageFileService.Object, TestSearchTerm); // Act await loader.LoadNextAsync(progress : mockProgress, CancellationToken.None); IEnumerable <PackageItemViewModel> items = loader.GetCurrent(); // Assert string[] result = items.Select(pkg => pkg.Id).ToArray(); Assert.Equal(inputIds, result); }
public void ReadPackages() { if (SelectedPackageSource == null) { return; } HasNextPage = false; IsLoadingNextPage = false; currentLoader = null; StartReadPackagesTask(); }
protected virtual Task LoadPackagesAsync(PackageItemLoader loader, CancellationToken token) { return(Task.Run(async() => { await loader.LoadNextAsync(null, token); while (loader.State.LoadingStatus == LoadingStatus.Loading) { token.ThrowIfCancellationRequested(); await loader.UpdateStateAsync(null, token); } })); }
public async Task MultipleSources_Works() { var solutionManager = Mock.Of <INuGetSolutionManagerService>(); var uiContext = new Mock <INuGetUIContext>(); uiContext.Setup(x => x.SolutionManagerService) .Returns(solutionManager); uiContext.Setup(x => x.ServiceBroker) .Returns(Mock.Of <IServiceBroker>()); var source1 = new PackageSource("https://pkgs.dev.azure.com/dnceng/public/_packaging/nuget-build/nuget/v3/index.json", "NuGetBuild"); var source2 = new PackageSource("https://api.nuget.org/v3/index.json", "NuGet.org"); var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateSourceRepositoryProvider(new[] { source1, source2 }); var repositories = sourceRepositoryProvider.GetRepositories(); var context = new PackageLoadContext(repositories, isSolution: false, uiContext.Object); var packageFeed = new MultiSourcePackageFeed(repositories, logger: null, telemetryService: null); var loader = new PackageItemLoader(context, packageFeed, "nuget"); var loaded = new List <PackageItemListViewModel>(); foreach (var page in Enumerable.Range(0, 5)) { await loader.LoadNextAsync(null, CancellationToken.None); while (loader.State.LoadingStatus == LoadingStatus.Loading) { await Task.Delay(TimeSpan.FromSeconds(1)); await loader.UpdateStateAsync(progress : null, CancellationToken.None); } var items = loader.GetCurrent(); loaded.AddRange(items); if (loader.State.LoadingStatus != LoadingStatus.Ready) { break; } } // All items should not have a prefix reserved because the feed is multisource foreach (var item in loaded) { Assert.False(item.PrefixReserved); } Assert.NotEmpty(loaded); }
public async Task MultipleSources_Works() { var solutionManager = Mock.Of <IVsSolutionManager>(); var uiContext = Mock.Of <INuGetUIContext>(); Mock.Get(uiContext) .Setup(x => x.SolutionManager) .Returns(solutionManager); var source1 = new Configuration.PackageSource("https://dotnet.myget.org/F/nuget-volatile/api/v3/index.json", "NuGetVolatile"); var source2 = new Configuration.PackageSource("https://api.nuget.org/v3/index.json", "NuGet.org"); var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateSourceRepositoryProvider(new[] { source1, source2 }); var repositories = sourceRepositoryProvider.GetRepositories(); var context = new PackageLoadContext(repositories, false, uiContext); var packageFeed = new MultiSourcePackageFeed(repositories, logger: null); var loader = new PackageItemLoader(context, packageFeed, "nuget"); var loaded = new List <PackageItemListViewModel>(); foreach (var page in Enumerable.Range(0, 5)) { await loader.LoadNextAsync(null, CancellationToken.None); while (loader.State.LoadingStatus == LoadingStatus.Loading) { await Task.Delay(TimeSpan.FromSeconds(1)); await loader.UpdateStateAsync(null, CancellationToken.None); } var items = loader.GetCurrent(); loaded.AddRange(items); if (loader.State.LoadingStatus != LoadingStatus.Ready) { break; } } // All items should not have a prefix reserved because the feed is multisource foreach (var item in loaded) { Assert.False(item.PrefixReserved); } Assert.NotEmpty(loaded); }
public async Task GetTotalCountAsync_Works() { var uiContext = Mock.Of <INuGetUIContext>(); var source1 = new Configuration.PackageSource("https://dotnet.myget.org/F/nuget-volatile/api/v3/index.json", "NuGetVolatile"); var source2 = new Configuration.PackageSource("https://api.nuget.org/v3/index.json", "NuGet.org"); var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateSourceRepositoryProvider(new[] { source1, source2 }); var repositories = sourceRepositoryProvider.GetRepositories(); var context = new PackageLoadContext(repositories, false, uiContext); var packageFeed = new MultiSourcePackageFeed(repositories, logger: null); var loader = new PackageItemLoader(context, packageFeed, "nuget"); var totalCount = await loader.GetTotalCountAsync(100, CancellationToken.None); Assert.NotInRange(totalCount, 0, 99); }
PackageItemLoader CreatePackageLoader() { var context = new ManagePackagesLoadContext( selectedPackageSource.GetSourceRepositories(), true, nugetProjects); var loader = new PackageItemLoader( context, CreatePackageFeed(context), SearchTerms, IncludePrerelease ); currentLoader = loader; return(loader); }
public async Task LoadNextAsync_Works() { var solutionManager = Mock.Of <INuGetSolutionManagerService>(); var uiContext = new Mock <INuGetUIContext>(); uiContext.Setup(x => x.SolutionManagerService) .Returns(solutionManager); uiContext.Setup(x => x.ServiceBroker) .Returns(Mock.Of <IServiceBroker>()); var context = new PackageLoadContext(sourceRepositories: null, isSolution: false, uiContext.Object); var packageFeed = new TestPackageFeed(); var loader = new PackageItemLoader(context, packageFeed, TestSearchTerm, includePrerelease: true); Assert.Equal(LoadingStatus.Unknown, loader.State.LoadingStatus); var initial = loader.GetCurrent(); Assert.Empty(initial); var loaded = new List <PackageItemListViewModel>(); await loader.LoadNextAsync(progress : null, CancellationToken.None); Assert.Equal(LoadingStatus.Loading, loader.State.LoadingStatus); var partial = loader.GetCurrent(); Assert.Empty(partial); await Task.Delay(TimeSpan.FromSeconds(1)); await loader.UpdateStateAsync(progress : null, CancellationToken.None); Assert.NotEqual(LoadingStatus.Loading, loader.State.LoadingStatus); loaded.AddRange(loader.GetCurrent()); Assert.Equal(LoadingStatus.Ready, loader.State.LoadingStatus); await loader.LoadNextAsync(progress : null, CancellationToken.None); Assert.Equal(LoadingStatus.NoMoreItems, loader.State.LoadingStatus); loaded.AddRange(loader.GetCurrent()); Assert.NotEmpty(loaded); }
public async Task LoadNextAsync_Works() { var solutionManager = Mock.Of <IVsSolutionManager>(); var uiContext = Mock.Of <INuGetUIContext>(); Mock.Get(uiContext) .Setup(x => x.SolutionManager) .Returns(solutionManager); var context = new PackageLoadContext(null, false, uiContext); var packageFeed = new TestPackageFeed(); var loader = new PackageItemLoader(context, packageFeed, TestSearchTerm, true); Assert.Equal(LoadingStatus.Unknown, loader.State.LoadingStatus); var initial = loader.GetCurrent(); Assert.Empty(initial); var loaded = new List <PackageItemListViewModel>(); await loader.LoadNextAsync(null, CancellationToken.None); Assert.Equal(LoadingStatus.Loading, loader.State.LoadingStatus); var partial = loader.GetCurrent(); Assert.Empty(partial); await Task.Delay(TimeSpan.FromSeconds(1)); await loader.UpdateStateAsync(null, CancellationToken.None); Assert.NotEqual(LoadingStatus.Loading, loader.State.LoadingStatus); loaded.AddRange(loader.GetCurrent()); Assert.Equal(LoadingStatus.Ready, loader.State.LoadingStatus); await loader.LoadNextAsync(null, CancellationToken.None); Assert.Equal(LoadingStatus.NoMoreItems, loader.State.LoadingStatus); loaded.AddRange(loader.GetCurrent()); Assert.NotEmpty(loaded); }
void OnPackagesRead(Task task, PackageItemLoader loader) { IsReadingPackages = false; IsLoadingNextPage = false; if (task.IsFaulted) { SaveError(task.Exception); } else if (task.IsCanceled || !IsCurrentQuery(loader)) { // Ignore. return; } else { SaveAnyWarnings(); UpdatePackagesForSelectedPage(loader); } base.OnPropertyChanged(null); }
public async Task PackageReader_NotNull() { // Prepare var solutionManager = Mock.Of <INuGetSolutionManagerService>(); var uiContext = new Mock <INuGetUIContext>(); uiContext.Setup(x => x.SolutionManagerService) .Returns(solutionManager); uiContext.Setup(x => x.ServiceBroker) .Returns(Mock.Of <IServiceBroker>()); using (var localFeedDir = TestDirectory.Create()) // local feed { // create test package var pkgId = new PackageIdentity("nuget.lpsm.test", new NuGetVersion(0, 0, 1)); var pkg = new SimpleTestPackageContext(pkgId.Id, pkgId.Version.ToNormalizedString()); await SimpleTestPackageUtility.CreatePackagesAsync(localFeedDir.Path, pkg); // local test source var localUri = new Uri(localFeedDir.Path, UriKind.Absolute); var localSource = new PackageSource(localUri.ToString(), "LocalSource"); var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateSourceRepositoryProvider(new[] { localSource }); var repositories = sourceRepositoryProvider.GetRepositories(); var context = new PackageLoadContext(repositories, isSolution: false, uiContext.Object); var packageFeed = new MultiSourcePackageFeed(repositories, logger: null, telemetryService: null); var loader = new PackageItemLoader(context, packageFeed, "nuget"); // Act await loader.LoadNextAsync(progress : null, CancellationToken.None); var results = loader.GetCurrent(); // Assert Assert.Single(results); Assert.NotNull(results.First().PackageReader); } }
public async Task GetTotalCountAsync_Works() { var solutionManager = Mock.Of <INuGetSolutionManagerService>(); var uiContext = Mock.Of <INuGetUIContext>(); Mock.Get(uiContext) .Setup(x => x.SolutionManagerService) .Returns(solutionManager); var source1 = new PackageSource("https://pkgs.dev.azure.com/dnceng/public/_packaging/nuget-build/nuget/v3/index.json", "NuGetBuild"); var source2 = new PackageSource("https://api.nuget.org/v3/index.json", "NuGet.org"); var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateSourceRepositoryProvider(new[] { source1, source2 }); var repositories = sourceRepositoryProvider.GetRepositories(); var context = new PackageLoadContext(repositories, false, uiContext); var packageFeed = new MultiSourcePackageFeed(repositories, logger: null, telemetryService: null); var loader = new PackageItemLoader(context, packageFeed, "nuget"); var totalCount = await loader.GetTotalCountAsync(100, CancellationToken.None); Assert.NotInRange(totalCount, 0, 99); }
public async Task MultipleSourcesPrefixReserved_Works() { var solutionManager = Mock.Of <INuGetSolutionManagerService>(); var uiContext = new Mock <INuGetUIContext>(); var searchService = new Mock <INuGetSearchService>(MockBehavior.Strict); var packageSearchMetadata = new PackageSearchMetadataBuilder.ClonedPackageSearchMetadata() { Identity = new PackageIdentity("NuGet.org", new NuGetVersion("1.0")), PrefixReserved = true }; var packageSearchMetadataContextInfo = new List <PackageSearchMetadataContextInfo>() { PackageSearchMetadataContextInfo.Create(packageSearchMetadata) }; var searchResult = new SearchResultContextInfo(packageSearchMetadataContextInfo, new Dictionary <string, LoadingStatus> { { "Completed", LoadingStatus.Ready } }, false); searchService.Setup(x => x.SearchAsync( It.IsAny <IReadOnlyCollection <IProjectContextInfo> >(), It.IsAny <IReadOnlyCollection <PackageSourceContextInfo> >(), It.IsAny <IReadOnlyCollection <string> >(), It.IsAny <string>(), It.IsAny <SearchFilter>(), It.IsAny <NuGet.VisualStudio.Internal.Contracts.ItemFilter>(), It.IsAny <bool>(), It.IsAny <CancellationToken>())) .Returns(new ValueTask <SearchResultContextInfo>(searchResult)); searchService.Setup(x => x.RefreshSearchAsync(It.IsAny <CancellationToken>())) .Returns(new ValueTask <SearchResultContextInfo>(searchResult)); uiContext.Setup(x => x.SolutionManagerService) .Returns(solutionManager); uiContext.Setup(x => x.ServiceBroker) .Returns(Mock.Of <IServiceBroker>()); var source1 = new PackageSourceContextInfo("https://pkgs.dev.azure.com/dnceng/public/_packaging/nuget-build/nuget/v3/index.json", "NuGetBuild"); var source2 = new PackageSourceContextInfo("https://api.nuget.org/v3/index.json", "NuGet.org"); var context = new PackageLoadContext(false, uiContext.Object); var loader = await PackageItemLoader.CreateAsync( Mock.Of <IServiceBroker>(), context, new List <PackageSourceContextInfo> { source1, source2 }, NuGet.VisualStudio.Internal.Contracts.ItemFilter.All, searchService.Object, TestSearchTerm); await loader.LoadNextAsync(null, CancellationToken.None); var items = loader.GetCurrent(); Assert.NotEmpty(items); // All items should not have a prefix reserved because the feed is multisource foreach (var item in items) { Assert.False(item.PrefixReserved); } }
public async Task PackageReader_NotNull() { // Prepare var solutionManager = Mock.Of <INuGetSolutionManagerService>(); var uiContext = new Mock <INuGetUIContext>(); uiContext.Setup(x => x.SolutionManagerService) .Returns(solutionManager); var searchService = new Mock <INuGetSearchService>(MockBehavior.Strict); var packageSearchMetadata = new PackageSearchMetadataBuilder.ClonedPackageSearchMetadata() { Identity = new PackageIdentity("NuGet.org", new NuGetVersion("1.0")), PrefixReserved = true }; var packageSearchMetadataContextInfo = new List <PackageSearchMetadataContextInfo>() { PackageSearchMetadataContextInfo.Create(packageSearchMetadata) }; var searchResult = new SearchResultContextInfo(packageSearchMetadataContextInfo, new Dictionary <string, LoadingStatus> { { "Search", LoadingStatus.Loading } }, false); searchService.Setup(x => x.SearchAsync( It.IsAny <IReadOnlyCollection <IProjectContextInfo> >(), It.IsAny <IReadOnlyCollection <PackageSourceContextInfo> >(), It.IsAny <IReadOnlyCollection <string> >(), It.IsAny <string>(), It.IsAny <SearchFilter>(), It.IsAny <NuGet.VisualStudio.Internal.Contracts.ItemFilter>(), It.IsAny <bool>(), It.IsAny <CancellationToken>())) .Returns(new ValueTask <SearchResultContextInfo>(searchResult)); uiContext.Setup(x => x.ServiceBroker) .Returns(Mock.Of <IServiceBroker>()); using (var localFeedDir = TestDirectory.Create()) // local feed { // create test package var pkgId = new PackageIdentity("nuget.lpsm.test", new NuGetVersion(0, 0, 1)); var pkg = new SimpleTestPackageContext(pkgId.Id, pkgId.Version.ToNormalizedString()); await SimpleTestPackageUtility.CreatePackagesAsync(localFeedDir.Path, pkg); // local test source var localUri = new Uri(localFeedDir.Path, UriKind.Absolute); var localSource = new PackageSource(localUri.ToString(), "LocalSource"); var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateSourceRepositoryProvider(new[] { localSource }); var repositories = sourceRepositoryProvider.GetRepositories(); var context = new PackageLoadContext(isSolution: false, uiContext.Object); var packageFeed = new MultiSourcePackageFeed(repositories, logger: null, telemetryService: null); var loader = await PackageItemLoader.CreateAsync( Mock.Of <IServiceBroker>(), context, new List <PackageSourceContextInfo> { PackageSourceContextInfo.Create(localSource) }, NuGet.VisualStudio.Internal.Contracts.ItemFilter.All, searchService.Object, TestSearchTerm); // Act await loader.LoadNextAsync(progress : null, CancellationToken.None); var results = loader.GetCurrent(); // Assert Assert.Single(results); Assert.NotNull(results.First().PackageReader); } }
public async Task EmitsSearchTelemetryEvents() { // Arrange var solutionManager = Mock.Of <IVsSolutionManager>(); var uiContext = Mock.Of <INuGetUIContext>(); Mock.Get(uiContext) .Setup(x => x.SolutionManager) .Returns(solutionManager); var telemetryService = new Mock <INuGetTelemetryService>(); var eventsQueue = new ConcurrentQueue <TelemetryEvent>(); telemetryService .Setup(x => x.EmitTelemetryEvent(It.IsAny <TelemetryEvent>())) .Callback <TelemetryEvent>(e => eventsQueue.Enqueue(e)); // Mock all the remote calls our test will try to make. var source = NuGetConstants.V3FeedUrl; var query = "https://api-v2v3search-0.nuget.org/query"; var responses = new Dictionary <string, string> { { source, ProtocolUtility.GetResource("NuGet.PackageManagement.UI.Test.compiler.resources.index.json", typeof(PackageItemLoaderTests)) }, { query + "?q=nuget&skip=0&take=26&prerelease=true&semVerLevel=2.0.0", ProtocolUtility.GetResource("NuGet.PackageManagement.UI.Test.compiler.resources.nugetSearchPage1.json", typeof(PackageItemLoaderTests)) }, { query + "?q=nuget&skip=25&take=26&prerelease=true&semVerLevel=2.0.0", ProtocolUtility.GetResource("NuGet.PackageManagement.UI.Test.compiler.resources.nugetSearchPage2.json", typeof(PackageItemLoaderTests)) }, }; using (var httpSource = new TestHttpSource(new PackageSource(source), responses)) { var injectedHttpSources = new Dictionary <string, HttpSource>(); injectedHttpSources.Add(source, httpSource); var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateSourceRepositoryProvider(new[] { new PackageSource(source) }, new Lazy <INuGetResourceProvider>[] { new Lazy <INuGetResourceProvider>(() => new TestHttpSourceResourceProvider(injectedHttpSources)) }); var repositories = sourceRepositoryProvider.GetRepositories(); var context = new PackageLoadContext(repositories, false, uiContext); var packageFeed = new MultiSourcePackageFeed(repositories, logger: null, telemetryService: telemetryService.Object); // Act var loader = new PackageItemLoader(context, packageFeed, searchText: "nuget", includePrerelease: true); await loader.LoadNextAsync(null, CancellationToken.None); await loader.LoadNextAsync(null, CancellationToken.None); // Assert var events = eventsQueue.ToArray(); Assert.True(4 == events.Length, string.Join(Environment.NewLine, events.Select(e => e.Name))); var search = Assert.Single(events, e => e.Name == "Search"); Assert.Equal(true, search["IncludePrerelease"]); Assert.Equal("nuget", search.GetPiiData().First(p => p.Key == "Query").Value); var operationId = Assert.IsType <string>(search["OperationId"]); var parsedOperationId = Guid.ParseExact(operationId, "D"); var sources = Assert.Single(events, e => e.Name == "SearchPackageSourceSummary"); Assert.Equal(1, sources["NumHTTPv3Feeds"]); Assert.Equal("YesV3", sources["NuGetOrg"]); Assert.Equal(operationId, sources["ParentId"]); var page0 = Assert.Single(events, e => e.Name == "SearchPage" && e["PageIndex"] is int && (int)e["PageIndex"] == 0); Assert.Equal("Ready", page0["LoadingStatus"]); Assert.Equal(operationId, page0["ParentId"]); Assert.IsType <int>(page0["ResultCount"]); Assert.IsType <double>(page0["Duration"]); Assert.IsType <double>(page0["ResultsAggregationDuration"]); Assert.IsType <string>(page0["IndividualSourceDurations"]); Assert.Equal(1, ((JArray)JsonConvert.DeserializeObject((string)page0["IndividualSourceDurations"])).Values <double>().Count()); var page1 = Assert.Single(events, e => e.Name == "SearchPage" && e["PageIndex"] is int && (int)e["PageIndex"] == 1); Assert.Equal("Ready", page1["LoadingStatus"]); Assert.Equal(operationId, page1["ParentId"]); Assert.IsType <int>(page1["ResultCount"]); Assert.IsType <double>(page1["Duration"]); Assert.IsType <double>(page1["ResultsAggregationDuration"]); Assert.IsType <string>(page1["IndividualSourceDurations"]); Assert.Equal(1, ((JArray)JsonConvert.DeserializeObject((string)page1["IndividualSourceDurations"])).Values <double>().Count()); Assert.Equal(parsedOperationId, loader.State.OperationId); } }
void UpdatePackagesForSelectedPage(PackageItemLoader loader) { HasNextPage = loader.State.LoadingStatus == LoadingStatus.Ready; UpdatePackageViewModels(loader.GetCurrent()); }
bool IsCurrentQuery(PackageItemLoader loader) { return(currentLoader == loader); }
public async Task EmitsSearchTelemetryEvents() { // Arrange var solutionManager = Mock.Of <IVsSolutionManager>(); var uiContext = Mock.Of <INuGetUIContext>(); Mock.Get(uiContext) .Setup(x => x.SolutionManager) .Returns(solutionManager); var telemetryService = new Mock <INuGetTelemetryService>(); var eventsQueue = new ConcurrentQueue <TelemetryEvent>(); telemetryService .Setup(x => x.EmitTelemetryEvent(It.IsAny <TelemetryEvent>())) .Callback <TelemetryEvent>(e => eventsQueue.Enqueue(e)); var source = new Configuration.PackageSource("https://api.nuget.org/v3/index.json", "NuGet.org"); var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateSourceRepositoryProvider(new[] { source }); var repositories = sourceRepositoryProvider.GetRepositories(); var context = new PackageLoadContext(repositories, false, uiContext); var packageFeed = new MultiSourcePackageFeed(repositories, logger: null, telemetryService: telemetryService.Object); // Act var loader = new PackageItemLoader(context, packageFeed, searchText: "nuget", includePrerelease: true); await loader.LoadNextAsync(null, CancellationToken.None); await loader.LoadNextAsync(null, CancellationToken.None); // Assert var events = eventsQueue.ToArray(); Assert.Equal(4, events.Length); var search = events[0]; Assert.Equal("Search", search.Name); Assert.Equal(true, search["IncludePrerelease"]); Assert.Equal("nuget", search.GetPiiData().First(p => p.Key == "Query").Value); var operationId = Assert.IsType <string>(search["OperationId"]); var parsedOperationId = Guid.ParseExact(operationId, "D"); var sources = events[1]; Assert.Equal("SearchPackageSourceSummary", sources.Name); Assert.Equal(1, sources["NumHTTPv3Feeds"]); Assert.Equal("YesV3", sources["NuGetOrg"]); Assert.Equal(operationId, sources["ParentId"]); var page0 = events[2]; Assert.Equal("SearchPage", page0.Name); Assert.Equal("Ready", page0["LoadingStatus"]); Assert.Equal(0, page0["PageIndex"]); Assert.Equal(operationId, page0["ParentId"]); Assert.IsType <int>(page0["ResultCount"]); Assert.IsType <double>(page0["Duration"]); Assert.IsType <double>(page0["ResultsAggregationDuration"]); Assert.IsType <string>(page0["IndividualSourceDurations"]); Assert.Equal(1, ((JArray)JsonConvert.DeserializeObject((string)page0["IndividualSourceDurations"])).Values <double>().Count()); var page1 = events[3]; Assert.Equal("SearchPage", page1.Name); Assert.Equal("Ready", page1["LoadingStatus"]); Assert.Equal(1, page1["PageIndex"]); Assert.Equal(operationId, page1["ParentId"]); Assert.IsType <int>(page1["ResultCount"]); Assert.IsType <double>(page1["Duration"]); Assert.IsType <double>(page1["ResultsAggregationDuration"]); Assert.IsType <string>(page1["IndividualSourceDurations"]); Assert.Equal(1, ((JArray)JsonConvert.DeserializeObject((string)page1["IndividualSourceDurations"])).Values <double>().Count()); Assert.Equal(parsedOperationId, loader.State.OperationId); }
public Task CallBaseLoadPackagesAsyncTask(PackageItemLoader loader, CancellationToken token) { return(base.LoadPackagesAsync(loader, token)); }
public async Task PackagePrefixReservation_FromMultiSource() { var solutionManager = Mock.Of <INuGetSolutionManagerService>(); var uiContext = new Mock <INuGetUIContext>(); var searchService = Mock.Of <INuGetSearchService>(); var packageFileService = Mock.Of <INuGetPackageFileService>(); uiContext.Setup(x => x.SolutionManagerService) .Returns(solutionManager); uiContext.Setup(x => x.ServiceBroker) .Returns(Mock.Of <IServiceBroker>()); // Arrange var responses = new Dictionary <string, string> { { "https://api-v3search-0.nuget.org/query?q=EntityFramework&skip=0&take=26&prerelease=false&semVerLevel=2.0.0", ProtocolUtility.GetResource("NuGet.PackageManagement.UI.Test.compiler.resources.EntityFrameworkSearch.json", GetType()) }, { "http://testsource.com/v3/index.json", JsonData.IndexWithoutFlatContainer }, { "http://othersource.com/v3/index.json", JsonData.IndexWithoutFlatContainer } }; var repo = StaticHttpHandler.CreateSource("http://testsource.com/v3/index.json", Repository.Provider.GetCoreV3(), responses); var repo1 = StaticHttpHandler.CreateSource("http://othersource.com/v3/index.json", Repository.Provider.GetCoreV3(), responses); var context = new PackageLoadContext(isSolution: false, uiContext.Object); var loader = await PackageItemLoader.CreateAsync( Mock.Of <IServiceBroker>(), context, new List <PackageSourceContextInfo> { PackageSourceContextInfo.Create(repo.PackageSource), PackageSourceContextInfo.Create(repo1.PackageSource) }, NuGet.VisualStudio.Internal.Contracts.ItemFilter.All, searchService, packageFileService, "EntityFramework", includePrerelease : false); var packageSearchMetadata = new PackageSearchMetadataBuilder.ClonedPackageSearchMetadata() { Identity = new PackageIdentity("NuGet.org", new NuGetVersion("1.0")), PrefixReserved = true }; var packageSearchMetadataContextInfo = new List <PackageSearchMetadataContextInfo>() { PackageSearchMetadataContextInfo.Create(packageSearchMetadata) }; var searchResult = new SearchResultContextInfo( packageSearchMetadataContextInfo, new Dictionary <string, LoadingStatus> { { "Completed", LoadingStatus.Ready } }, hasMoreItems: false); await loader.UpdateStateAndReportAsync(searchResult, progress : null, CancellationToken.None); var items = loader.GetCurrent(); // Resource only has one item var item = items.First(); // Assert that a multisource always has prefixreserved set to false Assert.False(item.PrefixReserved); }
public Task CallBaseLoadPackagesAsyncTask (PackageItemLoader loader, CancellationToken token) { return base.LoadPackagesAsync (loader, token); }