Пример #1
0
        public static RegistrationStorageFactories CreateRegistrationStorageFactories(IDictionary <string, string> arguments, bool verbose)
        {
            CatalogStorageFactory legacyStorageFactory;
            var semVer2StorageFactory = CreateSemVer2StorageFactory(arguments, verbose);

            var storageFactory           = CreateStorageFactory(arguments, verbose);
            var compressedStorageFactory = CreateCompressedStorageFactory(arguments, verbose);

            if (compressedStorageFactory != null)
            {
                var secondaryStorageBaseUrlRewriter = new SecondaryStorageBaseUrlRewriter(new List <KeyValuePair <string, string> >
                {
                    // always rewrite storage root url in seconary
                    new KeyValuePair <string, string>(storageFactory.BaseAddress.ToString(), compressedStorageFactory.BaseAddress.ToString())
                });

                var aggregateStorageFactory = new CatalogAggregateStorageFactory(
                    storageFactory,
                    new[] { compressedStorageFactory },
                    secondaryStorageBaseUrlRewriter.Rewrite,
                    verbose);

                legacyStorageFactory = aggregateStorageFactory;
            }
            else
            {
                legacyStorageFactory = storageFactory;
            }

            return(new RegistrationStorageFactories(legacyStorageFactory, semVer2StorageFactory));
        }
        public async Task CorrectlyReplacesRegistrationBaseUrlsInSecondaryStorage()
        {
            // Arrange
            var storageToReplay = Registrations.CreateTestRegistrations();
            var storage1 = new MemoryStorage(storageToReplay.BaseAddress);
            var storage2 = new MemoryStorage(new Uri("http://tempuri.org/secondone"));
            var storage3 = new MemoryStorage(new Uri("http://tempuri.org/thirdone"));

            var secondaryStorageBaseUrlRewriter = new SecondaryStorageBaseUrlRewriter(new List<KeyValuePair<string, string>>
            {
                new KeyValuePair<string, string>(storage1.BaseAddress.ToString(), storage2.BaseAddress.ToString() ),
                new KeyValuePair<string, string>(storage1.BaseAddress.ToString(), storage3.BaseAddress.ToString() )
            });

            var aggregateStorageFactory = CreateWithInterceptor(secondaryStorageBaseUrlRewriter.Rewrite, storage1, storage2, storage3);
            var aggregateStorage = aggregateStorageFactory.Create();

            var storage1BaseAddress = storage1.BaseAddress.ToString();
            var storage2BaseAddress = storage2.BaseAddress.ToString();
            var storage3BaseAddress = storage3.BaseAddress.ToString();

            // Act
            foreach (var content in storageToReplay.Content)
            {
                await aggregateStorage.Save(content.Key, content.Value, CancellationToken.None);
            }

            // Assert
            Assert.Equal(storageToReplay.Content.Count, storage1.Content.Count);
            Assert.Equal(storageToReplay.Content.Count, storage2.Content.Count);
            Assert.Equal(storageToReplay.Content.Count, storage3.Content.Count);

            foreach (var content in storage1.Content)
            {
                AssertContentDoesNotContain(content.Value, storage1BaseAddress);
                AssertContentDoesNotContain(content.Value, storage2BaseAddress);
                AssertContentDoesNotContain(content.Value, storage3BaseAddress);
            }

            foreach (var content in storage2.Content)
            {
                AssertContentDoesNotContain(content.Value, storage1BaseAddress);
                AssertContentDoesNotContain(content.Value, storage2BaseAddress);
                AssertContentDoesNotContain(content.Value, storage3BaseAddress);
            }

            foreach (var content in storage3.Content)
            {
                AssertContentDoesNotContain(content.Value, storage1BaseAddress);
                AssertContentDoesNotContain(content.Value, storage2BaseAddress);
                AssertContentDoesNotContain(content.Value, storage3BaseAddress);
            }
        }