コード例 #1
0
        public void LocalAndHttpSources_WithHTTPSv3Feeds_FeedCountsAreCorrect()
        {
            var sources = new List <PackageSource>()
            {
                new PackageSource(@"\\share\packages"),
                new PackageSource("https://nugettest.org/v3/index.JSON"),
                new PackageSource("http://tempuri.local/index.json"),
                new PackageSource("https://nuget.org/v3/index.JSON")
            };

            TelemetryEvent summary = SourceTelemetry.GetRestoreSourceSummaryEvent(Parent, sources, ProtocolDiagnosticTotals);
            Dictionary <string, string> summaryStrings = GetValuesAsStrings(summary);
            Dictionary <string, int?>   summaryInts    = GetValuesAsInts(summary);

            summaryStrings[ParentId].Should().Be(Parent.ToString());

            int?numLocalFeeds   = summaryInts[NumLocalFeeds];
            int?numHTTPv2Feeds  = summaryInts[NumHTTPv2Feeds];
            int?numHTTPv3Feeds  = summaryInts[NumHTTPv3Feeds];
            int?numHTTPSv2Feeds = summaryInts[NumHTTPSv2Feeds];
            int?numHTTPSv3Feeds = summaryInts[NumHTTPSv3Feeds];

            numLocalFeeds.Should().Be(1);
            numHTTPv2Feeds.Should().Be(0);
            numHTTPv3Feeds.Should().Be(3);
            numHTTPSv2Feeds.Should().Be(0);
            numHTTPSv3Feeds.Should().Be(2);

            int?totalFeeds = numLocalFeeds + numHTTPv2Feeds + numHTTPv3Feeds;

            totalFeeds.Should().Be(sources.Count);
        }
コード例 #2
0
        public async Task<SearchResult<IPackageSearchMetadata>> SearchAsync(string searchText, SearchFilter filter, CancellationToken cancellationToken)
        {
            var searchOperationId = Guid.NewGuid();
            if (_telemetryService != null)
            {
                _telemetryService.EmitTelemetryEvent(new SearchTelemetryEvent(
                    searchOperationId,
                    searchText,
                    filter.IncludePrerelease));

                _telemetryService.EmitTelemetryEvent(SourceTelemetry.GetSearchSourceSummaryEvent(
                    searchOperationId,
                    _sourceRepositories.Select(x => x.PackageSource)));
            }

            var searchTasks = TaskCombinators.ObserveErrorsAsync(
                _sourceRepositories,
                r => r.PackageSource.Name,
                (r, t) => r.SearchAsync(searchText, filter, PageSize, t),
                LogError,
                cancellationToken);

            return await WaitForCompletionOrBailOutAsync(
                searchText,
                searchTasks,
                new TelemetryState(searchOperationId, pageIndex: 0),
                cancellationToken);
        }
コード例 #3
0
        public void LocalAndHttpSources_WithHTTPSv2Feeds_FeedCountsAreCorrect()
        {
            var sources = new List <PackageSource>()
            {
                new PackageSource(@"\\share\packages"),
                new PackageSource("http://nugettest.org/v3/index.JSON"),
                new PackageSource("http://www.nuget.org/api/v2/curated-feeds/microsoftdotnet"), //v2
                new PackageSource("http://tempuri.local/index.json"),
                new PackageSource("http://nuget.org/v3/index.JSON"),
                new PackageSource("https://www.NuGet.org/api/v2/") //v2 and HTTPS
            };

            var summary        = SourceTelemetry.GetRestoreSourceSummaryEvent(Parent, sources, ProtocolDiagnosticTotals);
            var summaryStrings = GetValuesAsStrings(summary);
            var summaryInts    = GetValuesAsInts(summary);
            var summaryBools   = GetValuesAsBools(summary);

            summaryStrings[ParentId].Should().Be(Parent.ToString());

            int?numLocalFeeds   = summaryInts[NumLocalFeeds];
            int?numHTTPv2Feeds  = summaryInts[NumHTTPv2Feeds];
            int?numHTTPv3Feeds  = summaryInts[NumHTTPv3Feeds];
            int?numHTTPSv2Feeds = summaryInts[NumHTTPSv2Feeds];
            int?numHTTPSv3Feeds = summaryInts[NumHTTPSv3Feeds];

            numLocalFeeds.Should().Be(1);
            numHTTPv2Feeds.Should().Be(2);
            numHTTPv3Feeds.Should().Be(3);
            numHTTPSv2Feeds.Should().Be(1);
            numHTTPSv3Feeds.Should().Be(0);

            int?totalFeeds = numLocalFeeds + numHTTPv2Feeds + numHTTPv3Feeds;

            totalFeeds.Should().Be(sources.Count);
        }
コード例 #4
0
        public void GivenEmptySourcesVerifyEventNameForRestore()
        {
            var sources = new List <PackageSource>();
            var summary = SourceTelemetry.GetRestoreSourceSummaryEvent(Parent, sources);

            summary.Name.Should().Be("RestorePackageSourceSummary");
        }
コード例 #5
0
        public void GivenEmptySourcesVerifyEventNameForSearch()
        {
            var sources = new List <PackageSource>();
            var summary = SourceTelemetry.GetSearchSourceSummaryEvent(Parent, sources, ProtocolDiagnosticTotals);

            summary.Name.Should().Be("SearchPackageSourceSummary");
        }
コード例 #6
0
        public void GivenVsPackagesSourceVerifySummary(bool trailingSlash)
        {
            // Specify both so this test works on 32-bit and 64-bit processes.
            var suffix  = trailingSlash ? @"\" : string.Empty;
            var sources = new List <PackageSource>()
            {
                new PackageSource(@"C:\Program Files (x86)\Microsoft SDKs\NuGetPackages" + suffix),
                new PackageSource(@"C:\Program Files\Microsoft SDKs\NuGetPackages" + suffix)
            };

            var summary        = SourceTelemetry.GetRestoreSourceSummaryEvent(Parent, sources, ProtocolDiagnosticTotals);
            var summaryStrings = GetValuesAsStrings(summary);
            var summaryInts    = GetValuesAsInts(summary);
            var summaryBools   = GetValuesAsBools(summary);

            summaryInts[NumLocalFeeds].Should().Be(2);
            summaryInts[NumHTTPv2Feeds].Should().Be(0);
            summaryInts[NumHTTPv3Feeds].Should().Be(0);
            summaryInts[NumHTTPSv2Feeds].Should().Be(0);
            summaryInts[NumHTTPSv3Feeds].Should().Be(0);
            summaryStrings[ParentId].Should().Be(Parent.ToString());
            summaryStrings[NuGetOrg].Should().Be(NotPresent);
            summaryBools[VsOfflinePackages].Should().Be(true);
            summaryBools[DotnetCuratedFeed].Should().Be(false);
        }
コード例 #7
0
        public void VerifyProtocolDiagnosticTotals()
        {
            var sources   = new List <PackageSource>();
            var telemetry = SourceTelemetry.GetRestoreSourceSummaryEvent(Parent, sources, ProtocolDiagnosticTotals);

            telemetry[ProtocolRequests].Should().Be(1);
            telemetry[ProtocolBytes].Should().Be(2L);
            telemetry[ProtocolDuration].Should().Be(3.0);
        }
コード例 #8
0
        public void SourceTelemetry_GivenEmptySourcesVerifyZeroCounts()
        {
            var sources        = new List <PackageSource>();
            var summary        = SourceTelemetry.GetSourceSummaryEvent(Parent, sources);
            var summaryStrings = GetValuesAsStrings(summary);
            var summaryInts    = GetValuesAsInts(summary);

            summaryInts["NumLocalFeeds"].Should().Be(0);
            summaryInts["NumHTTPv2Feeds"].Should().Be(0);
            summaryInts["NumHTTPv3Feeds"].Should().Be(0);
            summaryStrings["ParentId"].Should().Be(Parent.ToString());
            summaryStrings["NuGetOrg"].Should().Be("NotPresent");
        }
コード例 #9
0
        public void SourceTelemetry_VerifySubDomainNuGetOrgIsNotCounted()
        {
            var sources = new List <PackageSource>()
            {
                new PackageSource("https://www.NuGet.org.myget.org/www.nuget.org/v2/"),
                new PackageSource("https://api.nuget.org.myget.org/api.nuget.org/index.json")
            };

            var summary        = SourceTelemetry.GetSourceSummaryEvent(Parent, sources);
            var summaryStrings = GetValuesAsStrings(summary);
            var summaryInts    = GetValuesAsInts(summary);

            summaryStrings["NuGetOrg"].Should().Be("NotPresent");
        }
コード例 #10
0
        public void SourceTelemetry_GivenOnlyNuGetV2andV3VerifySummary()
        {
            var sources = new List <PackageSource>()
            {
                new PackageSource("https://www.NuGet.org/api/v2/"),
                new PackageSource("https://api.nuget.org/v3/index.json")
            };

            var summary        = SourceTelemetry.GetSourceSummaryEvent(Parent, sources);
            var summaryStrings = GetValuesAsStrings(summary);
            var summaryInts    = GetValuesAsInts(summary);

            summaryInts["NumHTTPv2Feeds"].Should().Be(1);
            summaryInts["NumHTTPv3Feeds"].Should().Be(1);
            summaryStrings["NuGetOrg"].Should().Be("YesV3");
        }
コード例 #11
0
        public void SourceTelemetry_VerifyV2Feed()
        {
            var sources = new List <PackageSource>()
            {
                new PackageSource("http://tempuri.local/packages/")
            };

            var summary        = SourceTelemetry.GetSourceSummaryEvent(Parent, sources);
            var summaryStrings = GetValuesAsStrings(summary);
            var summaryInts    = GetValuesAsInts(summary);

            summaryStrings["NuGetOrg"].Should().Be("NotPresent");
            summaryInts["NumLocalFeeds"].Should().Be(0);
            summaryInts["NumHTTPv2Feeds"].Should().Be(1);
            summaryInts["NumHTTPv3Feeds"].Should().Be(0);
        }
コード例 #12
0
        public void GivenEmptySourcesVerifyZeroCounts()
        {
            var sources        = new List <PackageSource>();
            var summary        = SourceTelemetry.GetRestoreSourceSummaryEvent(Parent, sources, ProtocolDiagnosticTotals);
            var summaryStrings = GetValuesAsStrings(summary);
            var summaryInts    = GetValuesAsInts(summary);
            var summaryBools   = GetValuesAsBools(summary);

            summaryInts[NumLocalFeeds].Should().Be(0);
            summaryInts[NumHTTPv2Feeds].Should().Be(0);
            summaryInts[NumHTTPv3Feeds].Should().Be(0);
            summaryStrings[ParentId].Should().Be(Parent.ToString());
            summaryStrings[NuGetOrg].Should().Be(NotPresent);
            summaryBools[VsOfflinePackages].Should().Be(false);
            summaryBools[DotnetCuratedFeed].Should().Be(false);
        }
コード例 #13
0
        public void SourceTelemetry_GivenAnInvalidSourceVerifyNoFailures()
        {
            var sources = new List <PackageSource>()
            {
                new PackageSource("file:/bad!|source"),
                new PackageSource("https:/bad"),
            };

            var summary        = SourceTelemetry.GetSourceSummaryEvent(Parent, sources);
            var summaryStrings = GetValuesAsStrings(summary);
            var summaryInts    = GetValuesAsInts(summary);

            summaryStrings["NuGetOrg"].Should().Be("NotPresent");
            summaryInts["NumLocalFeeds"].Should().Be(2);
            summaryInts["NumHTTPv2Feeds"].Should().Be(0);
            summaryInts["NumHTTPv3Feeds"].Should().Be(0);
        }
コード例 #14
0
        public void SourceTelemetry_GivenOnlyNuGetV3VerifySummary()
        {
            var sources = new List <PackageSource>()
            {
                new PackageSource("https://api.nuget.org/v3/index.JSON")
            };

            var summary        = SourceTelemetry.GetSourceSummaryEvent(Parent, sources);
            var summaryStrings = GetValuesAsStrings(summary);
            var summaryInts    = GetValuesAsInts(summary);

            summaryInts["NumLocalFeeds"].Should().Be(0);
            summaryInts["NumHTTPv2Feeds"].Should().Be(0);
            summaryInts["NumHTTPv3Feeds"].Should().Be(1);
            summaryStrings["ParentId"].Should().Be(Parent.ToString());
            summaryStrings["NuGetOrg"].Should().Be("YesV3");
        }
コード例 #15
0
        public void SourceTelemetry_LocalFeedsVerifyCount()
        {
            var sources = new List <PackageSource>()
            {
                new PackageSource("packages"),
                new PackageSource(UriUtility.CreateSourceUri(Path.Combine(Path.GetTempPath(), "packages"), UriKind.Absolute).AbsoluteUri),
                new PackageSource(@"\\share\packages"),
            };

            var summary        = SourceTelemetry.GetSourceSummaryEvent(Parent, sources);
            var summaryStrings = GetValuesAsStrings(summary);
            var summaryInts    = GetValuesAsInts(summary);

            summaryStrings["NuGetOrg"].Should().Be("NotPresent");
            summaryInts["NumLocalFeeds"].Should().Be(3);
            summaryInts["NumHTTPv2Feeds"].Should().Be(0);
            summaryInts["NumHTTPv3Feeds"].Should().Be(0);
        }
コード例 #16
0
        public void SourceTelemetry_GivenDisabledFeedsVerifyCount()
        {
            var sources = new List <PackageSource>()
            {
                new PackageSource("https://www.NuGet.org/api/v2/", "n1", isEnabled: false),
                new PackageSource("https://api.nuget.org/v3/index.json", "n2", isEnabled: false),
                new PackageSource("packages")
            };

            var summary        = SourceTelemetry.GetSourceSummaryEvent(Parent, sources);
            var summaryStrings = GetValuesAsStrings(summary);
            var summaryInts    = GetValuesAsInts(summary);

            summaryInts["NumLocalFeeds"].Should().Be(1);
            summaryInts["NumHTTPv2Feeds"].Should().Be(0);
            summaryInts["NumHTTPv3Feeds"].Should().Be(0);
            summaryStrings["NuGetOrg"].Should().Be("NotPresent");
        }
コード例 #17
0
        public async Task <SearchResult <IPackageSearchMetadata> > SearchAsync(string searchText, SearchFilter filter, CancellationToken cancellationToken)
        {
            var searchOperationId = Guid.NewGuid();

            if (_telemetryService != null)
            {
                _telemetryService.EmitTelemetryEvent(new SearchTelemetryEvent(
                                                         searchOperationId,
                                                         searchText,
                                                         filter.IncludePrerelease));
            }

            SearchResult <IPackageSearchMetadata> result;

            using (var packageSourceTelemetry = new PackageSourceTelemetry(_sourceRepositories, searchOperationId, PackageSourceTelemetry.TelemetryAction.Search))
            {
                var searchTasks = TaskCombinators.ObserveErrorsAsync(
                    _sourceRepositories,
                    r => r.PackageSource.Name,
                    (r, t) => r.SearchAsync(searchText, filter, PageSize, t),
                    LogError,
                    cancellationToken);

                result = await WaitForCompletionOrBailOutAsync(
                    searchText,
                    searchTasks,
                    new TelemetryState(searchOperationId, pageIndex : 0),
                    cancellationToken);

                if (_telemetryService != null)
                {
                    await packageSourceTelemetry.SendTelemetryAsync();

                    var protocolDiagnosticTotals = packageSourceTelemetry.GetTotals();
                    _telemetryService.EmitTelemetryEvent(SourceTelemetry.GetSearchSourceSummaryEvent(
                                                             searchOperationId,
                                                             _sourceRepositories.Select(x => x.PackageSource),
                                                             protocolDiagnosticTotals));
                }
            }

            return(result);
        }
コード例 #18
0
        public void GivenNuGetCuratedFeedVerifySummary(string source)
        {
            var sources = new List <PackageSource>()
            {
                new PackageSource(source)
            };

            var summary        = SourceTelemetry.GetRestoreSourceSummaryEvent(Parent, sources);
            var summaryStrings = GetValuesAsStrings(summary);
            var summaryInts    = GetValuesAsInts(summary);
            var summaryBools   = GetValuesAsBools(summary);

            summaryInts[NumLocalFeeds].Should().Be(0);
            summaryInts[NumHTTPv2Feeds].Should().Be(1);
            summaryInts[NumHTTPv3Feeds].Should().Be(0);
            summaryStrings[ParentId].Should().Be(Parent.ToString());
            summaryStrings[NuGetOrg].Should().Be(NotPresent);
            summaryBools[VsOfflinePackages].Should().Be(false);
            summaryBools[DotnetCuratedFeed].Should().Be(true);
        }
コード例 #19
0
        public void VerifyV3Feed()
        {
            var sources = new List <PackageSource>()
            {
                new PackageSource("http://tempuri.local/index.json")
            };

            var summary        = SourceTelemetry.GetRestoreSourceSummaryEvent(Parent, sources, ProtocolDiagnosticTotals);
            var summaryStrings = GetValuesAsStrings(summary);
            var summaryInts    = GetValuesAsInts(summary);
            var summaryBools   = GetValuesAsBools(summary);

            summaryInts[NumLocalFeeds].Should().Be(0);
            summaryInts[NumHTTPv2Feeds].Should().Be(0);
            summaryInts[NumHTTPv3Feeds].Should().Be(1);
            summaryStrings[ParentId].Should().Be(Parent.ToString());
            summaryStrings[NuGetOrg].Should().Be(NotPresent);
            summaryBools[VsOfflinePackages].Should().Be(false);
            summaryBools[DotnetCuratedFeed].Should().Be(false);
        }
コード例 #20
0
        public void GivenOnlyNuGetV3VerifySummary()
        {
            var sources = new List <PackageSource>()
            {
                new PackageSource("https://api.nuget.org/v3/index.JSON")
            };

            var summary        = SourceTelemetry.GetRestoreSourceSummaryEvent(Parent, sources, ProtocolDiagnosticTotals);
            var summaryStrings = GetValuesAsStrings(summary);
            var summaryInts    = GetValuesAsInts(summary);
            var summaryBools   = GetValuesAsBools(summary);

            summaryInts[NumLocalFeeds].Should().Be(0);
            summaryInts[NumHTTPv2Feeds].Should().Be(0);
            summaryInts[NumHTTPv3Feeds].Should().Be(1);
            summaryStrings[ParentId].Should().Be(Parent.ToString());
            summaryStrings[NuGetOrg].Should().Be(YesV3);
            summaryBools[VsOfflinePackages].Should().Be(false);
            summaryBools[DotnetCuratedFeed].Should().Be(false);
        }
コード例 #21
0
        public void GivenOnlyNuGetV2VerifySummary()
        {
            var sources = new List <PackageSource>()
            {
                new PackageSource("https://www.NuGet.org/api/v2/")
            };

            var summary        = SourceTelemetry.GetRestoreSourceSummaryEvent(Parent, sources);
            var summaryStrings = GetValuesAsStrings(summary);
            var summaryInts    = GetValuesAsInts(summary);
            var summaryBools   = GetValuesAsBools(summary);

            summaryInts[NumLocalFeeds].Should().Be(0);
            summaryInts[NumHTTPv2Feeds].Should().Be(1);
            summaryInts[NumHTTPv3Feeds].Should().Be(0);
            summaryStrings[ParentId].Should().Be(Parent.ToString());
            summaryStrings[NuGetOrg].Should().Be(YesV2);
            summaryBools[VsOfflinePackages].Should().Be(false);
            summaryBools[DotnetCuratedFeed].Should().Be(false);
        }
コード例 #22
0
        public void VerifySubDomainNuGetOrgIsNotCounted()
        {
            var sources = new List <PackageSource>()
            {
                new PackageSource("https://www.NuGet.org.myget.org/www.nuget.org/v2/"),
                new PackageSource("https://api.nuget.org.myget.org/api.nuget.org/index.json")
            };

            var summary        = SourceTelemetry.GetRestoreSourceSummaryEvent(Parent, sources, ProtocolDiagnosticTotals);
            var summaryStrings = GetValuesAsStrings(summary);
            var summaryInts    = GetValuesAsInts(summary);
            var summaryBools   = GetValuesAsBools(summary);

            summaryInts[NumLocalFeeds].Should().Be(0);
            summaryInts[NumHTTPv2Feeds].Should().Be(1);
            summaryInts[NumHTTPv3Feeds].Should().Be(1);
            summaryStrings[ParentId].Should().Be(Parent.ToString());
            summaryStrings[NuGetOrg].Should().Be(NotPresent);
            summaryBools[VsOfflinePackages].Should().Be(false);
            summaryBools[DotnetCuratedFeed].Should().Be(false);
        }
コード例 #23
0
        public void GivenAnInvalidSourceVerifyNoFailures()
        {
            var sources = new List <PackageSource>()
            {
                new PackageSource("file:/bad!|source"),
                new PackageSource("https:/bad"),
            };

            var summary        = SourceTelemetry.GetRestoreSourceSummaryEvent(Parent, sources, ProtocolDiagnosticTotals);
            var summaryStrings = GetValuesAsStrings(summary);
            var summaryInts    = GetValuesAsInts(summary);
            var summaryBools   = GetValuesAsBools(summary);

            summaryInts[NumLocalFeeds].Should().Be(2);
            summaryInts[NumHTTPv2Feeds].Should().Be(0);
            summaryInts[NumHTTPv3Feeds].Should().Be(0);
            summaryStrings[ParentId].Should().Be(Parent.ToString());
            summaryStrings[NuGetOrg].Should().Be(NotPresent);
            summaryBools[VsOfflinePackages].Should().Be(false);
            summaryBools[DotnetCuratedFeed].Should().Be(false);
        }
コード例 #24
0
        public void GivenDisabledFeedsVerifyCount()
        {
            var sources = new List <PackageSource>()
            {
                new PackageSource("https://www.NuGet.org/api/v2/", "n1", isEnabled: false),
                new PackageSource("https://api.nuget.org/v3/index.json", "n2", isEnabled: false),
                new PackageSource("packages")
            };

            var summary        = SourceTelemetry.GetRestoreSourceSummaryEvent(Parent, sources);
            var summaryStrings = GetValuesAsStrings(summary);
            var summaryInts    = GetValuesAsInts(summary);
            var summaryBools   = GetValuesAsBools(summary);

            summaryInts[NumLocalFeeds].Should().Be(1);
            summaryInts[NumHTTPv2Feeds].Should().Be(0);
            summaryInts[NumHTTPv3Feeds].Should().Be(0);
            summaryStrings[ParentId].Should().Be(Parent.ToString());
            summaryStrings[NuGetOrg].Should().Be(NotPresent);
            summaryBools[VsOfflinePackages].Should().Be(false);
            summaryBools[DotnetCuratedFeed].Should().Be(false);
        }
コード例 #25
0
        public void LocalFeedsVerifyCount()
        {
            var sources = new List <PackageSource>()
            {
                new PackageSource("packages"),
                new PackageSource(UriUtility.CreateSourceUri(Path.Combine(Path.GetTempPath(), "packages"), UriKind.Absolute).AbsoluteUri),
                new PackageSource(@"\\share\packages"),
            };

            var summary        = SourceTelemetry.GetRestoreSourceSummaryEvent(Parent, sources, ProtocolDiagnosticTotals);
            var summaryStrings = GetValuesAsStrings(summary);
            var summaryInts    = GetValuesAsInts(summary);
            var summaryBools   = GetValuesAsBools(summary);

            summaryInts[NumLocalFeeds].Should().Be(3);
            summaryInts[NumHTTPv2Feeds].Should().Be(0);
            summaryInts[NumHTTPv3Feeds].Should().Be(0);
            summaryStrings[ParentId].Should().Be(Parent.ToString());
            summaryStrings[NuGetOrg].Should().Be(NotPresent);
            summaryBools[VsOfflinePackages].Should().Be(false);
            summaryBools[DotnetCuratedFeed].Should().Be(false);
        }