public async Task DoesNotFetchLeavesForDeleteEntries()
            {
                var items = new[]
                {
                    new CatalogCommitItem(
                        uri: new Uri("https://example/0"),
                        commitId: null,
                        commitTimeStamp: new DateTime(2018, 1, 1),
                        types: null,
                        typeUris: new List <Uri> {
                        Schema.DataTypes.PackageDetails
                    },
                        packageIdentity: new PackageIdentity("NuGet.Versioning", NuGetVersion.Parse("1.0.0"))),
                    new CatalogCommitItem(
                        uri: new Uri("https://example/1"),
                        commitId: null,
                        commitTimeStamp: new DateTime(2018, 1, 2),
                        types: null,
                        typeUris: new List <Uri> {
                        Schema.DataTypes.PackageDelete
                    },
                        packageIdentity: new PackageIdentity("NuGet.Frameworks", NuGetVersion.Parse("2.0.0"))),
                };

                await Target.OnProcessBatchAsync(items);

                CatalogClient.Verify(x => x.GetPackageDetailsLeafAsync("https://example/0"), Times.Once);
                CatalogClient.Verify(x => x.GetPackageDetailsLeafAsync(It.IsAny <string>()), Times.Exactly(1));
                CatalogClient.Verify(x => x.GetPackageDeleteLeafAsync(It.IsAny <string>()), Times.Never);

                RegistrationUpdater.Verify(
                    x => x.UpdateAsync(
                        "NuGet.Versioning",
                        It.Is <IReadOnlyList <CatalogCommitItem> >(
                            y => y.Count == 1),
                        It.Is <IReadOnlyDictionary <CatalogCommitItem, PackageDetailsCatalogLeaf> >(
                            y => y.Count == 1)),
                    Times.Once);
                RegistrationUpdater.Verify(
                    x => x.UpdateAsync(
                        "NuGet.Frameworks",
                        It.Is <IReadOnlyList <CatalogCommitItem> >(
                            y => y.Count == 1),
                        It.Is <IReadOnlyDictionary <CatalogCommitItem, PackageDetailsCatalogLeaf> >(
                            y => y.Count == 0)),
                    Times.Once);
            }
        public IntegrationTests(ITestOutputHelper output)
        {
            Options = new Mock <IOptionsSnapshot <Catalog2RegistrationConfiguration> >();
            Config  = new Catalog2RegistrationConfiguration
            {
                LegacyBaseUrl                  = "https://example/v3/reg",
                LegacyStorageContainer         = "v3-reg",
                GzippedBaseUrl                 = "https://example/v3/reg-gz",
                GzippedStorageContainer        = "v3-reg-gz",
                SemVer2BaseUrl                 = "https://example/v3/reg-gz-semver2",
                SemVer2StorageContainer        = "v3-reg-gz-semver2",
                FlatContainerBaseUrl           = "https://example/v3/flatcontainer",
                GalleryBaseUrl                 = "https://example-gallery",
                MaxConcurrentHivesPerId        = 1,
                MaxConcurrentIds               = 1,
                MaxConcurrentOperationsPerHive = 1,
                MaxConcurrentStorageOperations = 1,
                EnsureSingleSnapshot           = false,
            };
            Options.Setup(x => x.Value).Returns(() => Config);

            CloudBlobClient        = new InMemoryCloudBlobClient();
            RegistrationUrlBuilder = new RegistrationUrlBuilder(Options.Object);
            EntityBuilder          = new EntityBuilder(RegistrationUrlBuilder, Options.Object);
            Throttle    = NullThrottle.Instance;
            HiveStorage = new HiveStorage(
                CloudBlobClient,
                RegistrationUrlBuilder,
                EntityBuilder,
                Throttle,
                Options.Object,
                output.GetLogger <HiveStorage>());
            HiveMerger  = new HiveMerger(Options.Object, output.GetLogger <HiveMerger>());
            HiveUpdater = new HiveUpdater(
                HiveStorage,
                HiveMerger,
                EntityBuilder,
                Options.Object,
                output.GetLogger <HiveUpdater>());
            RegistrationUpdater = new RegistrationUpdater(
                HiveUpdater,
                Options.Object,
                output.GetLogger <RegistrationUpdater>());
        }
Exemple #3
0
            public Facts(ITestOutputHelper output)
            {
                HiveUpdater = new Mock <IHiveUpdater>();
                Options     = new Mock <IOptionsSnapshot <Catalog2RegistrationConfiguration> >();
                Logger      = output.GetLogger <RegistrationUpdater>();

                Config = new Catalog2RegistrationConfiguration();
                Config.MaxConcurrentHivesPerId = 1;
                Id          = "NuGet.Versioning";
                Entries     = new List <CatalogCommitItem>();
                EntryToLeaf = new Dictionary <CatalogCommitItem, PackageDetailsCatalogLeaf>();

                Options.Setup(x => x.Value).Returns(() => Config);

                Target = new RegistrationUpdater(
                    HiveUpdater.Object,
                    Options.Object,
                    Logger);
            }
            public async Task RejectsMultipleLeavesForTheSamePackageAtTheSameTime()
            {
                var items = new[]
                {
                    new CatalogCommitItem(
                        uri: new Uri("https://example/0"),
                        commitId: null,
                        commitTimeStamp: new DateTime(2018, 1, 1),
                        types: null,
                        typeUris: new List <Uri> {
                        Schema.DataTypes.PackageDetails
                    },
                        packageIdentity: new PackageIdentity("NuGet.Versioning", NuGetVersion.Parse("1.0.0"))),
                    new CatalogCommitItem(
                        uri: new Uri("https://example/1"),
                        commitId: null,
                        commitTimeStamp: new DateTime(2018, 1, 1),
                        types: null,
                        typeUris: new List <Uri> {
                        Schema.DataTypes.PackageDetails
                    },
                        packageIdentity: new PackageIdentity("NuGet.Versioning", NuGetVersion.Parse("1.0.0"))),
                };

                var ex = await Assert.ThrowsAsync <InvalidOperationException>(
                    () => Target.OnProcessBatchAsync(items));

                Assert.Equal(
                    "There are multiple catalog leaves for a single package at one time.",
                    ex.Message);
                RegistrationUpdater.Verify(
                    x => x.UpdateAsync(
                        It.IsAny <string>(),
                        It.IsAny <IReadOnlyList <CatalogCommitItem> >(),
                        It.IsAny <IReadOnlyDictionary <CatalogCommitItem, PackageDetailsCatalogLeaf> >()),
                    Times.Never);
            }