public void WhenIRemoveTheCosmosConfigurationFromTheTenant()
        {
            IServiceProvider          serviceProvider = ContainerBindings.GetServiceProvider(this.scenarioContext);
            ITenantProvider           tenantProvider  = serviceProvider.GetRequiredService <ITenantProvider>();
            CosmosContainerDefinition definition      = this.containerDefinition;

            tenantProvider.Root.UpdateProperties(
                propertiesToRemove: definition.RemoveCosmosConfiguration());
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TenantedCosmosContentStoreFactory"/> class.
 /// </summary>
 /// <param name="tenantProvider">The <see cref="ITenantProvider"/> that will be used to retrieve Tenant info.</param>
 /// <param name="containerFactory">The <see cref="ITenantCosmosContainerFactory"/> that will be used to create
 /// underlying <see cref="Container"/> instances for the content stores.</param>
 /// <param name="containerDefinition">The <see cref="CosmosContainerDefinition"/> to use when creating tenanted
 /// <see cref="Container"/> instances.</param>
 public TenantedCosmosContentStoreFactory(
     ITenantProvider tenantProvider,
     ITenantCosmosContainerFactory containerFactory,
     CosmosContainerDefinition containerDefinition)
 {
     this.tenantProvider      = tenantProvider;
     this.containerFactory    = containerFactory;
     this.containerDefinition = containerDefinition;
 }
Example #3
0
        public static Task ClearDownTransientTenantContentStore(FeatureContext context)
        {
            return(context.RunAndStoreExceptionsAsync(async() =>
            {
                ITenant currentTenant = context.GetTransientTenant();

                if (currentTenant != null)
                {
                    IServiceProvider serviceProvider = ContainerBindings.GetServiceProvider(context);
                    ITenantCosmosContainerFactory containerFactory = serviceProvider.GetRequiredService <ITenantCosmosContainerFactory>();
                    CosmosContainerDefinition containerDefinition = serviceProvider.GetRequiredService <CosmosContainerDefinition>();
                    Container container = await containerFactory.GetContainerForTenantAsync(currentTenant, containerDefinition).ConfigureAwait(false);
                    await container.DeleteContainerAsync().ConfigureAwait(false);
                }
            }));
        }
        public LegacyCosmosContainerSteps(
            ScenarioContext featureContext,
            TenancyContainerScenarioBindings tenancyBindings,
            LegacyTenancyCosmosContainerBindings cosmosBindings)
        {
            this.scenarioContext = featureContext;
            this.tenancyBindings = tenancyBindings;
            this.cosmosBindings  = cosmosBindings;

            string containerBase = Guid.NewGuid().ToString();

            this.containerDefinition = new CosmosContainerDefinition(
                "endjinspecssharedthroughput",
                $"{containerBase}tenancyspecs",
                "/partitionKey",
                databaseThroughput: 400);
        }
Example #5
0
        public void ThenTheTenantCalledShouldContainCosmosConfigurationForACosmosContainerDefinitionWithDatabaseNameAndContainerName(
            string tenantName,
            string databaseName,
            string containerName)
        {
            InMemoryTenantProvider tenantProvider =
                ContainerBindings.GetServiceProvider(this.scenarioContext).GetRequiredService <InMemoryTenantProvider>();

            ITenant tenant = tenantProvider.GetTenantByName(tenantName)
                             ?? throw new TenantNotFoundException($"Could not find tenant with name '{tenantName}'");

            var containerDefinition = new CosmosContainerDefinition(databaseName, containerName, null);

            CosmosConfiguration tenantConfigItem = tenant.GetCosmosConfiguration(containerDefinition);

            // GetCosmosStorageConfiguration would have thrown an exception if the config didn't exist, but we'll do a
            // not null assertion anyway...
            Assert.IsNotNull(tenantConfigItem);
        }
Example #6
0
        /// <summary>
        /// Adds Cosmos-based implementation of <see cref="ITenantedContentStoreFactory"/> to the service container.
        /// </summary>
        /// <param name="services">
        /// The collection.
        /// </param>
        /// <param name="configuration">The configuration from which to initialize the factory.</param>
        /// <returns>
        /// The configured <see cref="IServiceCollection"/>.
        /// </returns>
        public static IServiceCollection AddTenantedAzureCosmosContentStore(
            this IServiceCollection services,
            IConfiguration configuration)
        {
            if (configuration is null)
            {
                throw new System.ArgumentNullException(nameof(configuration));
            }

            if (services.Any(s => s.ServiceType is ITenantedContentStoreFactory))
            {
                return(services);
            }

            var containerDefinition = new CosmosContainerDefinition("content", "content", Content.PartitionKeyPath);

            services.AddSingleton(containerDefinition);

            services.AddTenantCosmosContainerFactory(configuration);

            services.AddSingleton <ITenantedContentStoreFactory, TenantedCosmosContentStoreFactory>();

            return(services);
        }
Example #7
0
        public void ThenTheTenantCalledShouldNotContainCosmosConfigurationForACosmosContainerDefinitionWithDatabaseNameAndContainerName(
            string tenantName,
            string databaseName,
            string containerName)
        {
            InMemoryTenantProvider tenantProvider =
                ContainerBindings.GetServiceProvider(this.scenarioContext).GetRequiredService <InMemoryTenantProvider>();

            ITenant enrolledTenant = tenantProvider.GetTenantByName(tenantName)
                                     ?? throw new TenantNotFoundException($"Could not find tenant with name '{tenantName}'");

            var containerDefinition = new CosmosContainerDefinition(databaseName, containerName, null);

            try
            {
                // This should throw. If it doesn't, then the config exists and the test fails.
                enrolledTenant.GetCosmosConfiguration(containerDefinition);
                Assert.Fail($"Did not expect to find Cosmos configuration in tenant '{tenantName}' for container definition with database name '{databaseName}' and container name '{containerName}', but it was present.");
            }
            catch (ArgumentException)
            {
                // This is what's expected - all is well.
            }
        }