Exemplo n.º 1
0
 private static void PopulateDownloadCount <T>(
     T document,
     long totalDownloadCount) where T : KeyedDocument, SearchDocument.IDownloadCount
 {
     document.TotalDownloadCount = totalDownloadCount;
     document.DownloadScore      = DocumentUtilities.GetDownloadScore(totalDownloadCount);
 }
Exemplo n.º 2
0
            public void EncodesSearchDocumentKey(string id, string expected)
            {
                foreach (var searchFilters in Enum.GetValues(typeof(SearchFilters)).Cast <SearchFilters>())
                {
                    var actual = DocumentUtilities.GetSearchDocumentKey(id, searchFilters);

                    Assert.Equal(expected + "-" + searchFilters, actual);
                }
            }
Exemplo n.º 3
0
            public void IsCompatibleWithHttpServerUtilityUrlTokenEncode()
            {
                var random = new Random(0);

                for (var i = 0; i < 1_000_000; i++)
                {
                    var bytes = new byte[random.Next(0, 8) + 1];
                    random.NextBytes(bytes);
                    var expected = HttpServerUtility.UrlTokenEncode(bytes);
                    var actual   = DocumentUtilities.Base64UrlEncode(bytes);
                    Assert.Equal(expected, actual);
                }
            }
Exemplo n.º 4
0
        private void PopulateUpdateLatest(
            SearchDocument.UpdateLatest document,
            string packageId,
            SearchFilters searchFilters,
            bool lastUpdatedFromCatalog,
            DateTimeOffset?lastCommitTimestamp,
            string lastCommitId,
            string[] versions,
            bool isLatestStable,
            bool isLatest,
            string fullVersion,
            string[] owners,
            string[] packageTypes)
        {
            PopulateVersions(
                document,
                packageId,
                searchFilters,
                lastUpdatedFromCatalog,
                lastCommitTimestamp,
                lastCommitId,
                versions,
                isLatestStable,
                isLatest);
            document.SearchFilters = DocumentUtilities.GetSearchFilterString(searchFilters);
            document.FullVersion   = fullVersion;

            // If the package has explicit types, we will set them here.
            // Otherwise, we will treat the package as a "Depedency" type and fill in the explicit type.
            if (packageTypes != null && packageTypes.Length > 0)
            {
                document.PackageTypes           = packageTypes;
                document.FilterablePackageTypes = packageTypes.Select(pt => pt.ToLowerInvariant()).ToArray();
            }
            else
            {
                document.PackageTypes           = ImpliedDependency;
                document.FilterablePackageTypes = FilterableImpliedDependency;
            }

            PopulateOwners(
                document,
                owners);
        }
Exemplo n.º 5
0
            public void EncodesHijackDocumentKey(string id, string version, string expected)
            {
                var actual = DocumentUtilities.GetHijackDocumentKey(id, version);

                Assert.Equal(expected, actual);
            }
Exemplo n.º 6
0
 private static void PopulateKey(KeyedDocument document, string packageId, string normalizedVersion)
 {
     document.Key = DocumentUtilities.GetHijackDocumentKey(packageId, normalizedVersion);
 }
Exemplo n.º 7
0
 private static void PopulateKey(KeyedDocument document, string packageId, SearchFilters searchFilters)
 {
     document.Key = DocumentUtilities.GetSearchDocumentKey(packageId, searchFilters);
 }