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 ThenTheTenantedCloudBlobContainerShouldBeNamedUsingAHashOfTheTenantIdAndTheNameSpecifiedInTheBlobContainerDefinition() { string expectedNamePlain = string.Concat(RootTenant.RootTenantId, "-", this.blobStorageContainerDefinition.ContainerName); string expectedName = AzureStorageNameHelper.HashAndEncodeBlobContainerName(expectedNamePlain); Assert.AreEqual(expectedName, this.Container.Name); }
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); }