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);
        }
        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);
        }
        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);
        }
Beispiel #4
0
        public void GivenEmptySourcesVerifyEventNameForRestore()
        {
            var sources = new List <PackageSource>();
            var summary = SourceTelemetry.GetRestoreSourceSummaryEvent(Parent, sources);

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

            summary.Name.Should().Be("SearchPackageSourceSummary");
        }
        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);
        }
        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);
        }
Beispiel #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");
        }
Beispiel #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");
        }
Beispiel #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");
        }
Beispiel #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);
        }
        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);
        }
Beispiel #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);
        }
Beispiel #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");
        }
Beispiel #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);
        }
Beispiel #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");
        }
Beispiel #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);
        }
Beispiel #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);
        }
        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);
        }
        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);
        }
Beispiel #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);
        }
        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);
        }
        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);
        }
Beispiel #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);
        }
        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);
        }