private void VerifyRegistrationPage(
            MemoryStorage registrationStorage,
            RegistrationPage page,
            Uri pageUri,
            string packageId,
            ExpectedPage expectedPage,
            string commitId,
            string commitTimeStamp)
        {
            var packageIndexUri = GetRegistrationPackageIndexUri(registrationStorage.BaseAddress);

            Assert.Equal(pageUri.AbsoluteUri, page.IdKeyword);
            Assert.Equal(CatalogConstants.CatalogCatalogPage, page.TypeKeyword);
            Assert.Equal(commitId, page.CommitId);
            Assert.Equal(commitTimeStamp, page.CommitTimeStamp);
            Assert.Equal(expectedPage.LowerVersion, page.Lower);
            Assert.Equal(expectedPage.UpperVersion, page.Upper);
            Assert.Equal(page.Count, page.Items.Length);
            Assert.Equal(packageIndexUri.AbsoluteUri, page.Parent);

            for (var i = 0; i < page.Count; ++i)
            {
                var item           = page.Items[i];
                var packageDetails = expectedPage.Details[i];

                VerifyRegistrationPackage(registrationStorage, item, packageDetails, commitId, commitTimeStamp);
            }
        }
        private void VerifyRegistrationPageReference(
            MemoryStorage registrationStorage,
            RegistrationPage page,
            string packageId,
            ExpectedPage expectedPage,
            string commitId,
            string commitTimeStamp)
        {
            var pageUri = GetRegistrationPageReferenceUri(packageId, expectedPage);

            Assert.Equal(pageUri.AbsoluteUri, page.IdKeyword);
            Assert.Equal(CatalogConstants.CatalogCatalogPage, page.TypeKeyword);
            Assert.Equal(commitId, page.CommitId);
            Assert.Equal(commitTimeStamp, page.CommitTimeStamp);
            Assert.Equal(expectedPage.LowerVersion, page.Lower);
            Assert.Equal(expectedPage.UpperVersion, page.Upper);

            Assert.Null(page.Items);
            Assert.Null(page.Parent);

            var independentPage = GetStorageContent <RegistrationIndependentPage>(registrationStorage, pageUri);

            VerifyRegistrationPage(
                registrationStorage,
                independentPage,
                pageUri,
                packageId,
                expectedPage,
                commitId,
                commitTimeStamp);

            JObject expectedContext = GetExpectedIndexOrPageContext();

            Assert.Equal(expectedContext.ToString(), independentPage.ContextKeyword.ToString());
        }
Esempio n. 3
0
 private static void ShouldBeExpected(IPage <int> page, ExpectedPage <int> expectedPage)
 {
     page.Should().BeEquivalentTo(expectedPage.Items);
     page.TotalItems.Should().Be(expectedPage.TotalItems);
     page.CurrentPage.Should().Be(expectedPage.CurrentPage);
     page.PageSize.Should().Be(expectedPage.PageSize);
     page.TotalPages.Should().Be(expectedPage.TotalPages);
     page.Pages.Should().BeEquivalentTo(expectedPage.Pages);
 }
Esempio n. 4
0
        public void Should_initialize_empty_page_if_there_is_no_items_and_page_index_is_greater_than_zero()
        {
            var expectedPage = new ExpectedPage <int>
            {
                Items       = Array.Empty <int>(),
                PageSize    = 4,
                Pages       = Array.Empty <long>(),
                CurrentPage = 4,
                TotalPages  = 0,
                TotalItems  = 0
            };

            var page = new Page <int>(Array.Empty <int>(), 4, 4, 0);

            ShouldBeExpected(page, expectedPage);
        }
Esempio n. 5
0
        public void Should_initialize_last_page()
        {
            var expectedPage = new ExpectedPage <int>
            {
                Items       = new[] { 1, 2 },
                PageSize    = 4,
                Pages       = new[] { 0L, 1L, 2L },
                CurrentPage = 2,
                TotalPages  = 3,
                TotalItems  = 11
            };

            var page = new Page <int>(new[] { 1, 2 }, 4, 2, 11);

            ShouldBeExpected(page, expectedPage);
        }
Esempio n. 6
0
        public void Should_initialize_intermediate_page()
        {
            var expectedPage = new ExpectedPage <int>
            {
                Items       = new[] { 1, 2, 3 },
                PageSize    = 3,
                Pages       = new[] { 0L, 1L, 2L },
                CurrentPage = 1,
                TotalPages  = 3,
                TotalItems  = 8
            };

            var page = new Page <int>(new[] { 1, 2, 3 }, 3, 1, 8);

            ShouldBeExpected(page, expectedPage);
        }
Esempio n. 7
0
        public void Should_initialize_page_for_no_data()
        {
            var expectedPage = new ExpectedPage <int>
            {
                Items       = Array.Empty <int>(),
                PageSize    = 10,
                Pages       = Array.Empty <long>(),
                CurrentPage = 0,
                TotalPages  = 0,
                TotalItems  = 0
            };

            var page = new Page <int>(Array.Empty <int>(), 10, 0, 0);

            ShouldBeExpected(page, expectedPage);
        }
Esempio n. 8
0
        public void Should_initialize_empty_page_if_page_index_is_bigger_than_pages_available()
        {
            var expectedPage = new ExpectedPage <int>
            {
                Items       = Array.Empty <int>(),
                PageSize    = 4,
                Pages       = new [] { 0L, 1L, 2L },
                CurrentPage = 4,
                TotalPages  = 3,
                TotalItems  = 12
            };

            var page = new Page <int>(Array.Empty <int>(), 4, 4, 12);

            ShouldBeExpected(page, expectedPage);
        }
        public PaginatedResultTests()
        {
            _response = new RestResponse <List <object> >();

            _response.Headers.Add(new Parameter
            {
                Name  = "X-Page",
                Value = ExpectedPage.ToString()
            });

            _response.Headers.Add(new Parameter
            {
                Name  = "X-Prev-Page",
                Value = ExpectedPrevPage.ToString()
            });

            _response.Headers.Add(new Parameter
            {
                Name  = "X-Next-Page",
                Value = ExpectedNextPage.ToString()
            });

            _response.Headers.Add(new Parameter
            {
                Name  = "X-Per-Page",
                Value = ExpectedPerPage.ToString()
            });

            _response.Headers.Add(new Parameter
            {
                Name  = "X-Total-Pages",
                Value = ExpectedTotalPages.ToString()
            });

            _response.Headers.Add(new Parameter
            {
                Name  = "X-Total",
                Value = ExpectedTotal.ToString()
            });
        }
 private Uri GetRegistrationPageReferenceUri(string packageId, ExpectedPage expectedPage)
 {
     return(new Uri($"{_storageFactory.BaseAddress.AbsoluteUri}{packageId}/page"
                    + $"/{expectedPage.LowerVersion}/{expectedPage.UpperVersion}.json"));
 }
 private Uri GetRegistrationPageUri(string packageId, ExpectedPage expectedPage)
 {
     return(new Uri(GetRegistrationPackageIndexUri(_storageFactory.BaseAddress, packageId),
                    $"#page/{expectedPage.LowerVersion}/{expectedPage.UpperVersion}"));
 }
Esempio n. 12
0
        private void Verify(MemoryStorage storage, ExpectedPage expectedPage)
        {
            var firstPackageDetails  = expectedPage.Details.First();
            var registrationIndexUri = GetRegistrationPackageIndexUri(storage.BaseAddress, firstPackageDetails.Id.ToLowerInvariant());
            var registrationIndex    = GetStorageContent <RegistrationIndex>(storage, registrationIndexUri);

            var commitId        = registrationIndex.CommitId;
            var commitTimeStamp = registrationIndex.CommitTimeStamp;

            Assert.Equal(1, registrationIndex.Count);

            var registrationPage = registrationIndex.Items.Single();

            Assert.Equal(CatalogConstants.CatalogCatalogPage, registrationPage.TypeKeyword);
            Assert.Equal(commitId, registrationPage.CommitId);
            Assert.Equal(commitTimeStamp, registrationPage.CommitTimeStamp);
            Assert.Equal(expectedPage.Details.Count, registrationPage.Count);
            Assert.Equal(registrationIndexUri.AbsoluteUri, registrationPage.Parent);
            Assert.Equal(expectedPage.LowerVersion, registrationPage.Lower);
            Assert.Equal(expectedPage.UpperVersion, registrationPage.Upper);

            Assert.Equal(expectedPage.Details.Count, registrationPage.Count);
            Assert.Equal(registrationPage.Count, registrationPage.Items.Length);

            for (var i = 0; i < registrationPage.Count; ++i)
            {
                var catalogPackageDetails         = expectedPage.Details[i];
                var packageId                     = catalogPackageDetails.Id.ToLowerInvariant();
                var packageVersion                = catalogPackageDetails.Version.ToLowerInvariant();
                var registrationPackageVersionUri = GetRegistrationPackageVersionUri(storage.BaseAddress, packageId, packageVersion);
                var packageContentUri             = GetPackageContentUri(storage.BaseAddress, packageId, packageVersion);

                var registrationPackage = registrationPage.Items[i];

                Assert.Equal(registrationPackageVersionUri.AbsoluteUri, registrationPackage.IdKeyword);
                Assert.Equal(CatalogConstants.Package, registrationPackage.TypeKeyword);
                Assert.Equal(commitId, registrationPackage.CommitId);
                Assert.Equal(commitTimeStamp, registrationPackage.CommitTimeStamp);
                Assert.Equal(packageContentUri.AbsoluteUri, registrationPackage.PackageContent);
                Assert.Equal(registrationIndexUri.AbsoluteUri, registrationPackage.Registration);

                var registrationCatalogEntry = registrationPackage.CatalogEntry;

                Assert.Equal(catalogPackageDetails.IdKeyword, registrationCatalogEntry.IdKeyword);
                Assert.Equal(CatalogConstants.PackageDetails, registrationCatalogEntry.TypeKeyword);
                Assert.Equal(catalogPackageDetails.Id, registrationCatalogEntry.Id);
                Assert.Equal(catalogPackageDetails.Version, registrationCatalogEntry.Version);
                Assert.Equal(catalogPackageDetails.Authors, registrationCatalogEntry.Authors);
                Assert.Equal(catalogPackageDetails.Description, registrationCatalogEntry.Description);
                Assert.Equal(catalogPackageDetails.Listed, registrationCatalogEntry.Listed);

                Assert.Equal(packageContentUri.AbsoluteUri, registrationCatalogEntry.PackageContent);
                Assert.Equal(GetRegistrationDateTime(catalogPackageDetails.Published), registrationCatalogEntry.Published);
                Assert.Equal(catalogPackageDetails.RequireLicenseAcceptance, registrationCatalogEntry.RequireLicenseAcceptance);

                var registrationPackageDetails = GetStorageContent <RegistrationIndependentPackage>(storage, new Uri(registrationPackage.IdKeyword));

                Assert.Equal(registrationPackageVersionUri.AbsoluteUri, registrationPackageDetails.IdKeyword);
                Assert.Equal(new[] { CatalogConstants.Package, CatalogConstants.NuGetCatalogSchemaPermalinkUri }, registrationPackageDetails.TypeKeyword);
                Assert.Equal(catalogPackageDetails.IdKeyword, registrationPackageDetails.CatalogEntry);
                Assert.Equal(catalogPackageDetails.Listed, registrationPackageDetails.Listed);
                Assert.Equal(packageContentUri.AbsoluteUri, registrationPackageDetails.PackageContent);
                Assert.Equal(GetRegistrationDateTime(catalogPackageDetails.Published), registrationPackageDetails.Published);
                Assert.Equal(registrationIndexUri.AbsoluteUri, registrationPackageDetails.Registration);
            }
        }
Esempio n. 13
0
        public async Task RunAsync_WhenPackageIdSpansCommitsAndVariesInCasing_BatchesAcrossCommitsByLowerCasePackageId()
        {
            var pageUri        = new Uri(_baseUri, "v3-catalog0/page0.json");
            var indexUri       = new Uri(_baseUri, "v3-catalog0/index.json");
            var contentBaseUri = new Uri(_baseUri, "packages");

            SharedInit(useLegacy: true, useSemVer2: true, baseUri: _baseUri, indexUri: indexUri, contentBaseUri: contentBaseUri);

            var commitId1                  = Guid.NewGuid().ToString();
            var commitId2                  = Guid.NewGuid().ToString();
            var commitTimeStamp1           = DateTimeOffset.UtcNow.AddMinutes(-1);
            var commitTimeStamp2           = commitTimeStamp1.AddMinutes(1);
            var independentPackageDetails1 = new CatalogIndependentPackageDetails(
                id: "ABC",
                version: "1.0.0",
                baseUri: _baseUri.AbsoluteUri,
                commitId: commitId1,
                commitTimeStamp: commitTimeStamp1);
            var independentPackageDetails2 = new CatalogIndependentPackageDetails(
                id: "AbC",
                version: "1.0.1",
                baseUri: _baseUri.AbsoluteUri,
                commitId: commitId1,
                commitTimeStamp: commitTimeStamp1);
            var independentPackageDetails3 = new CatalogIndependentPackageDetails(
                id: "abc",
                version: "1.0.2",
                baseUri: _baseUri.AbsoluteUri,
                commitId: commitId2,
                commitTimeStamp: commitTimeStamp2);
            var packageDetails = new[]
            {
                CatalogPackageDetails.Create(independentPackageDetails1),
                CatalogPackageDetails.Create(independentPackageDetails2),
                CatalogPackageDetails.Create(independentPackageDetails3)
            };

            var independentPage = new CatalogIndependentPage(
                pageUri.AbsoluteUri,
                CatalogConstants.CatalogPage,
                commitId2,
                commitTimeStamp2.ToString(CatalogConstants.CommitTimeStampFormat),
                packageDetails.Length,
                indexUri.AbsoluteUri,
                packageDetails,
                _contextKeyword);

            var index = CatalogIndex.Create(independentPage, _contextKeyword);

            var catalogStorage = new MemoryStorage(_baseUri);

            catalogStorage.Content.TryAdd(indexUri, CreateStringStorageContent(index));
            catalogStorage.Content.TryAdd(pageUri, CreateStringStorageContent(independentPage));
            catalogStorage.Content.TryAdd(
                new Uri(independentPackageDetails1.IdKeyword),
                CreateStringStorageContent(independentPackageDetails1));
            catalogStorage.Content.TryAdd(
                new Uri(independentPackageDetails2.IdKeyword),
                CreateStringStorageContent(independentPackageDetails2));
            catalogStorage.Content.TryAdd(
                new Uri(independentPackageDetails3.IdKeyword),
                CreateStringStorageContent(independentPackageDetails3));

            await _mockServer.AddStorageAsync(catalogStorage);

            await _target.RunAsync(CancellationToken.None);

            var expectedPage = new ExpectedPage(independentPackageDetails1, independentPackageDetails2, independentPackageDetails3);

            Verify(_legacyStorage, expectedPage);
            Verify(_semVer2Storage, expectedPage);
        }