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>());
        }
            public Facts(ITestOutputHelper output)
            {
                CloudBlobClient = new Mock <ICloudBlobClient>();
                EntityBuilder   = new Mock <IEntityBuilder>();
                Throttle        = new Mock <IThrottle>();
                Options         = new Mock <IOptionsSnapshot <Catalog2RegistrationConfiguration> >();
                Logger          = output.GetLogger <HiveStorage>();

                Config = new Catalog2RegistrationConfiguration
                {
                    LegacyBaseUrl           = "https://example/reg/",
                    LegacyStorageContainer  = "reg",
                    GzippedBaseUrl          = "https://example/reg-gz/",
                    GzippedStorageContainer = "reg-gz",
                    SemVer2BaseUrl          = "https://example/reg-gz-semver2/",
                    SemVer2StorageContainer = "reg-gz-semver2",
                    EnsureSingleSnapshot    = false,
                };
                LegacyContainer  = new Mock <ICloudBlobContainer>();
                GzippedContainer = new Mock <ICloudBlobContainer>();
                SemVer2Container = new Mock <ICloudBlobContainer>();
                LegacyBlob       = new Mock <ISimpleCloudBlob>();
                GzippedBlob      = new Mock <ISimpleCloudBlob>();
                SemVer2Blob      = new Mock <ISimpleCloudBlob>();
                LegacyStream     = new MemoryStream();
                GzippedStream    = new MemoryStream();
                SemVer2Stream    = new MemoryStream();
                LegacySegment    = new Mock <ISimpleBlobResultSegment>();
                Hive             = HiveType.Legacy;
                ReplicaHives     = new List <HiveType>();
                Id    = "NuGet.Versioning";
                Index = new RegistrationIndex();
                Page  = new RegistrationPage();
                Leaf  = new RegistrationLeaf();

                Options.Setup(x => x.Value).Returns(() => Config);
                CloudBlobClient.Setup(x => x.GetContainerReference(Config.LegacyStorageContainer)).Returns(() => LegacyContainer.Object);
                CloudBlobClient.Setup(x => x.GetContainerReference(Config.GzippedStorageContainer)).Returns(() => GzippedContainer.Object);
                CloudBlobClient.Setup(x => x.GetContainerReference(Config.SemVer2StorageContainer)).Returns(() => SemVer2Container.Object);
                LegacyContainer.Setup(x => x.GetBlobReference(It.IsAny <string>())).Returns(() => LegacyBlob.Object);
                GzippedContainer.Setup(x => x.GetBlobReference(It.IsAny <string>())).Returns(() => GzippedBlob.Object);
                SemVer2Container.Setup(x => x.GetBlobReference(It.IsAny <string>())).Returns(() => SemVer2Blob.Object);
                LegacyBlob.Setup(x => x.Properties).Returns(new BlobProperties());
                LegacyBlob.Setup(x => x.OpenReadAsync(It.IsAny <AccessCondition>())).ReturnsAsync(() => LegacyStream);
                LegacyBlob.Setup(x => x.Uri).Returns(new Uri("https://example/reg/something.json"));
                LegacyBlob
                .Setup(x => x.UploadFromStreamAsync(It.IsAny <Stream>(), It.IsAny <AccessCondition>()))
                .Returns(Task.CompletedTask)
                .Callback <Stream, AccessCondition>((s, _) => s.CopyTo(LegacyStream));
                LegacyBlob.Setup(x => x.ExistsAsync()).ReturnsAsync(true);
                LegacyContainer
                .Setup(x => x.ListBlobsSegmentedAsync(
                           It.IsAny <string>(),
                           It.IsAny <bool>(),
                           It.IsAny <BlobListingDetails>(),
                           It.IsAny <int?>(),
                           It.IsAny <BlobContinuationToken>(),
                           It.IsAny <BlobRequestOptions>(),
                           It.IsAny <OperationContext>(),
                           It.IsAny <CancellationToken>()))
                .Returns(() => Task.FromResult(LegacySegment.Object));
                LegacySegment.Setup(x => x.Results).Returns(new List <ISimpleCloudBlob>());
                GzippedBlob.Setup(x => x.Properties).Returns(new BlobProperties());
                GzippedBlob.Setup(x => x.OpenReadAsync(It.IsAny <AccessCondition>())).ReturnsAsync(() => GzippedStream);
                GzippedBlob.Setup(x => x.Uri).Returns(new Uri("https://example/reg-gz/something.json"));
                GzippedBlob
                .Setup(x => x.UploadFromStreamAsync(It.IsAny <Stream>(), It.IsAny <AccessCondition>()))
                .Returns(Task.CompletedTask)
                .Callback <Stream, AccessCondition>((s, _) => s.CopyTo(GzippedStream));
                GzippedBlob.Setup(x => x.ExistsAsync()).ReturnsAsync(true);
                SemVer2Blob.Setup(x => x.Properties).Returns(new BlobProperties());
                SemVer2Blob.Setup(x => x.OpenReadAsync(It.IsAny <AccessCondition>())).ReturnsAsync(() => SemVer2Stream);
                SemVer2Blob.Setup(x => x.Uri).Returns(new Uri("https://example/reg-gz-semver2/something.json"));
                SemVer2Blob
                .Setup(x => x.UploadFromStreamAsync(It.IsAny <Stream>(), It.IsAny <AccessCondition>()))
                .Returns(Task.CompletedTask)
                .Callback <Stream, AccessCondition>((s, _) => s.CopyTo(SemVer2Stream));
                SemVer2Blob.Setup(x => x.ExistsAsync()).ReturnsAsync(true);

                SerializeToStream(LegacyStream, new Dictionary <string, string> {
                    { "@id", LegacyBlob.Object.Uri.AbsoluteUri }
                });
                SerializeToStream(GzippedStream, new Dictionary <string, string> {
                    { "@id", GzippedBlob.Object.Uri.AbsoluteUri }
                });
                SerializeToStream(SemVer2Stream, new Dictionary <string, string> {
                    { "@id", SemVer2Blob.Object.Uri.AbsoluteUri }
                });

                Target = new HiveStorage(
                    CloudBlobClient.Object,
                    new RegistrationUrlBuilder(Options.Object),
                    EntityBuilder.Object,
                    Throttle.Object,
                    Options.Object,
                    Logger);
            }