Ejemplo n.º 1
0
        private static async Task CoreCleanupAsync(IServiceProvider sp, ITenant rootTenant)
        {
            TenantTrackingTenantProviderDecorator tenantTrackingProvider = sp.GetRequiredService <TenantTrackingTenantProviderDecorator>();
            List <ITenant> tenants = tenantTrackingProvider.CreatedTenants;

            tenants.Add(tenantTrackingProvider.Root);
            ITenantCloudBlobContainerFactory blobContainerFactory = sp.GetRequiredService <ITenantCloudBlobContainerFactory>();

            CloudBlobContainer rootContainer = await blobContainerFactory.GetBlobContainerForTenantAsync(
                rootTenant, TenantProviderBlobStore.ContainerDefinition).ConfigureAwait(false);

            IEnumerable <CloudBlobContainer> blobContainers =
                tenants.Select(tenant =>
            {
                // It would be easier just to ask blobContainerFactory.GetBlobContainerForTenantAsync to give
                // us the container, but that will attempt to create it if it doesn't exist, and in tests
                // where we happen already to have deleted it, that quick recreation test will then fail
                // because Azure doesn't like it if you do taht.
                string tenantedContainerName = $"{tenant.Id.ToLowerInvariant()}-{TenantProviderBlobStore.ContainerDefinition.ContainerName}";
                string containerName         = AzureStorageNameHelper.HashAndEncodeBlobContainerName(tenantedContainerName);
                return(rootContainer.ServiceClient.GetContainerReference(containerName));
            });

            foreach (CloudBlobContainer container in blobContainers.Distinct(x => x.Name))
            {
                await container.DeleteIfExistsAsync().ConfigureAwait(false);
            }
        }
        public void ThenTheTenantedCloudTableShouldBeNamedUsingAHashOfTheTenantIdAndTheNameSpecifiedInTheTableDefinition()
        {
            string expectedNamePlain = string.Concat(RootTenant.RootTenantId, "-", this.TableStorageTableDefinition.TableName);
            string expectedName      = AzureStorageNameHelper.HashAndEncodeTableName(expectedNamePlain);

            Assert.AreEqual(expectedName, this.CloudTable.Name);
        }
        public void ThenTheTenantedCloudTableShouldBeNamedUsingAHashOfTheNameSpecifiedInTheBlobConfiguration()
        {
            TableStorageConfiguration tableStorageConfiguration = this.tenancyBindings.RootTenant.GetTableStorageConfiguration(this.TableStorageTableDefinition);

            string expectedNamePlain = tableStorageConfiguration.TableName !;
            string expectedName      = AzureStorageNameHelper.HashAndEncodeTableName(expectedNamePlain);

            Assert.AreEqual(expectedName, this.CloudTable.Name);
        }
Ejemplo n.º 4
0
        public void ThenTheTenantedCloudBlobContainerShouldBeNamedUsingAHashOfTheTenantIdAndTheNameSpecifiedInTheBlobConfiguration()
        {
            ITenantProvider          tenantProvider           = this.serviceProvider.GetRequiredService <ITenantProvider>();
            BlobStorageConfiguration blobStorageConfiguration = tenantProvider.Root.GetBlobStorageConfiguration(this.blobStorageContainerDefinition);

            string expectedNamePlain = string.Concat(RootTenant.RootTenantId, "-", blobStorageConfiguration.Container);
            string expectedName      = AzureStorageNameHelper.HashAndEncodeBlobContainerName(expectedNamePlain);

            Assert.AreEqual(expectedName, this.Container.Name);
        }