public static async Task ClearDownTransientTenantContentStore(FeatureContext context) { ITenant transientTenant = TransientTenantManager.GetInstance(context).PrimaryTransientClient; IServiceProvider serviceProvider = ContainerBindings.GetServiceProvider(context); if (transientTenant != null && serviceProvider != null) { await context.RunAndStoreExceptionsAsync(async() => { ITenantedWorkflowStoreFactory workflowStoreFactory = serviceProvider.GetRequiredService <ITenantedWorkflowStoreFactory>(); IWorkflowStore workflowStore = await workflowStoreFactory.GetWorkflowStoreForTenantAsync(transientTenant).ConfigureAwait(false); if (workflowStore is CosmosWorkflowStore cosmosWorkflowStore) { await cosmosWorkflowStore.Container.DeleteContainerAsync().ConfigureAwait(false); } }).ConfigureAwait(false); await context.RunAndStoreExceptionsAsync(async() => { ITenantedWorkflowInstanceStoreFactory workflowInstanceStoreFactory = serviceProvider.GetRequiredService <ITenantedWorkflowInstanceStoreFactory>(); var workflowInstanceStore = (CosmosWorkflowInstanceStore)await workflowInstanceStoreFactory.GetWorkflowInstanceStoreForTenantAsync(transientTenant).ConfigureAwait(false); await workflowInstanceStore.Container.DeleteContainerAsync().ConfigureAwait(false); }).ConfigureAwait(false); } }
public static async Task SetupTransientTenant(FeatureContext featureContext) { ITenantProvider tenantProvider = ContainerBindings.GetServiceProvider(featureContext).GetRequiredService <ITenantProvider>(); var transientTenantManager = TransientTenantManager.GetInstance(featureContext); await transientTenantManager.EnsureInitialised().ConfigureAwait(false); // Create a transient service tenant for testing purposes. ITenant transientServiceTenant = await transientTenantManager.CreateTransientServiceTenantFromEmbeddedResourceAsync( typeof(TransientTenantBindings).Assembly, "Marain.UserNotifications.Specs.ServiceManifests.UserNotificationsServiceManifest.jsonc").ConfigureAwait(false); // Now update the service Id in our configuration and in the function configuration UpdateServiceConfigurationWithTransientTenantId(featureContext, transientServiceTenant); // Now we need to construct a transient client tenant for the test, and enroll it in the new // transient service. ITenant transientClientTenant = await transientTenantManager.CreateTransientClientTenantAsync().ConfigureAwait(false); await transientTenantManager.AddEnrollmentAsync( transientClientTenant.Id, transientServiceTenant.Id, GetUserNotificationsConfig(featureContext)).ConfigureAwait(false); // TODO: Temporary hack to work around the fact that the transient tenant manager no longer holds the latest // version of the tenants it's tracking; see https://github.com/marain-dotnet/Marain.TenantManagement/issues/28 transientTenantManager.PrimaryTransientClient = await tenantProvider.GetTenantAsync(transientClientTenant.Id).ConfigureAwait(false); }
public async Task WhenIUseTheOperationsControlClientToCreateAnOperation(Table table) { string idName = table.Rows[0]["IdName"]; Guid id = this.ScenarioContext.Get <Guid>(idName); string resourceLocation = table.Rows[0]["ResourceLocation"]; long expireAfter = long.Parse(table.Rows[0]["ExpireAfter"]); string body = table.Rows[0]["Body"]; IServiceProvider serviceProvider = ContainerBindings.GetServiceProvider(this.FeatureContext); IMarainOperationsControl client = serviceProvider.GetRequiredService <IMarainOperationsControl>(); var transientTenantManager = TransientTenantManager.GetInstance(this.FeatureContext); await Exceptions.ExecuteAndStoreExceptionAsync( this.ScenarioContext, async() => { CreateOperationHeaders result = await client.CreateOperationAsync( transientTenantManager.PrimaryTransientClient.Id, id, resourceLocation, expireAfter, body).ConfigureAwait(false); this.ScenarioContext.Set(result); }).ConfigureAwait(false); }
public OperationsStatusApiAndTasksSteps(FeatureContext featureContext, ScenarioContext scenarioContext) { this.serviceProvider = ContainerBindings.GetServiceProvider(featureContext); this.repository = this.serviceProvider.GetRequiredService <FakeOperationsRepository>(); this.host = this.serviceProvider.GetRequiredService <IOpenApiHost <HttpRequest, IActionResult> >(); this.scenarioContext = scenarioContext; this.transientTenantManager = TransientTenantManager.GetInstance(featureContext); }
public WorkflowSteps( ScenarioContext scenarioContext, FeatureContext featureContext) { this.scenarioContext = scenarioContext; this.featureContext = featureContext; this.serviceProvider = ContainerBindings.GetServiceProvider(featureContext); this.transientTenantManager = TransientTenantManager.GetInstance(featureContext); }
public void ThenTheCreateOperationResponseContainsTheLocationInTheOperationsStatusApiForTheOperationWithTheIdCalled(string operationIdName) { var transientTenantManager = TransientTenantManager.GetInstance(this.FeatureContext); Guid operationId = this.ScenarioContext.Get <Guid>(operationIdName); CreateOperationHeaders response = this.ScenarioContext.Get <CreateOperationHeaders>(); var actualUri = new Uri(response.Location); var expectedUri = new Uri(new Uri(ApiBindings.StatusApiBaseUrl), $"/{transientTenantManager.PrimaryTransientClient.Id}/api/operations/{operationId}"); Assert.AreEqual(expectedUri, actualUri); }
public static async Task TearDownTenants(FeatureContext featureContext) { var tenantManager = TransientTenantManager.GetInstance(featureContext); await featureContext.RunAndStoreExceptionsAsync(async() => { ITenantCloudTableFactory cloudTableFactory = ContainerBindings.GetServiceProvider(featureContext).GetRequiredService <ITenantCloudTableFactory>(); CloudTable testTable = await cloudTableFactory.GetTableForTenantAsync(tenantManager.PrimaryTransientClient, TenantedAzureTableUserNotificationStoreFactory.TableDefinition).ConfigureAwait(false); await testTable.DeleteIfExistsAsync().ConfigureAwait(false); }).ConfigureAwait(false); await featureContext.RunAndStoreExceptionsAsync(() => { return(tenantManager.CleanupAsync()); }).ConfigureAwait(false); }
public static async Task TearDownTenants(FeatureContext featureContext) { var tenantManager = TransientTenantManager.GetInstance(featureContext); await featureContext.RunAndStoreExceptionsAsync(async() => { IBlobContainerSourceWithTenantLegacyTransition cloudBlobContainerFactory = ContainerBindings.GetServiceProvider(featureContext).GetRequiredService <IBlobContainerSourceWithTenantLegacyTransition>(); BlobContainerClient testContainer = await cloudBlobContainerFactory.GetBlobContainerClientFromTenantAsync( tenantManager.PrimaryTransientClient, OperationsRepository.OperationsV2ConfigKey, OperationsRepository.OperationsV3ConfigKey).ConfigureAwait(false); await testContainer.DeleteIfExistsAsync().ConfigureAwait(false); }).ConfigureAwait(false); await featureContext.RunAndStoreExceptionsAsync(() => tenantManager.CleanupAsync()).ConfigureAwait(false); }
public async Task WhenIUseTheOperationsStatusClientToGetTheOperationWithId(Guid id) { IServiceProvider serviceProvider = ContainerBindings.GetServiceProvider(this.FeatureContext); IMarainOperations client = serviceProvider.GetRequiredService <IMarainOperations>(); var transientTenantManager = TransientTenantManager.GetInstance(this.FeatureContext); await Exceptions.ExecuteAndStoreExceptionAsync( this.ScenarioContext, async() => { Client.OperationsStatus.Models.Operation?operation = await client.GetOperationByIdAsync( transientTenantManager.PrimaryTransientClient.Id, id).ConfigureAwait(false); this.ScenarioContext.Set(operation, LastResponseContextKey); }).ConfigureAwait(false); }
public async Task WhenIUseTheOperationsControlClientToCreateAnOperationWithTheIdCalled(string operationIdName) { Guid operationId = this.ScenarioContext.Get <Guid>(operationIdName); IServiceProvider serviceProvider = ContainerBindings.GetServiceProvider(this.FeatureContext); IMarainOperationsControl client = serviceProvider.GetRequiredService <IMarainOperationsControl>(); var transientTenantManager = TransientTenantManager.GetInstance(this.FeatureContext); await Exceptions.ExecuteAndStoreExceptionAsync( this.ScenarioContext, async() => { CreateOperationHeaders result = await client.CreateOperationAsync( transientTenantManager.PrimaryTransientClient.Id, operationId).ConfigureAwait(false); this.ScenarioContext.Set(result); }).ConfigureAwait(false); }
public async Task GivenIUseTheOperationsControlClientToSetTheStatusOfTheOperationWithIdCalledToFailed(string operationIdName) { Guid id = this.ScenarioContext.Get <Guid>(operationIdName); IServiceProvider serviceProvider = ContainerBindings.GetServiceProvider(this.FeatureContext); IMarainOperationsControl client = serviceProvider.GetRequiredService <IMarainOperationsControl>(); var transientTenantManager = TransientTenantManager.GetInstance(this.FeatureContext); await Exceptions.ExecuteAndStoreExceptionAsync( this.ScenarioContext, async() => { ProblemDetails?result = await client.SetOperationFailedAsync( transientTenantManager.PrimaryTransientClient.Id, id).ConfigureAwait(false); this.ScenarioContext.Set(result); }).ConfigureAwait(false); }
public static async Task SetupTenants(FeatureContext featureContext, string manifestName) { var transientTenantManager = TransientTenantManager.GetInstance(featureContext); await transientTenantManager.EnsureInitialised().ConfigureAwait(false); var tenantHelper = TransientTenantManager.GetInstance(featureContext); ITenant transientServiceTenant = await tenantHelper.CreateTransientServiceTenantFromEmbeddedResourceAsync( typeof(OperationsControlApiAndTasksBindings).Assembly, $"Marain.Operations.Specs.Integration.ServiceManifests.{manifestName}.jsonc").ConfigureAwait(false); UpdateServiceConfigurationWithTransientTenantId(featureContext, transientServiceTenant); ITenant transientClientTenant = await transientTenantManager.CreateTransientClientTenantAsync().ConfigureAwait(false); await transientTenantManager.AddEnrollmentAsync( transientClientTenant.Id, transientServiceTenant.Id, GetTestOperationsConfig()).ConfigureAwait(false); }
public static async Task TearDownBlobContainers(FeatureContext context) { ITenant transientTenant = TransientTenantManager.GetInstance(context).PrimaryTransientClient; IServiceProvider serviceProvider = ContainerBindings.GetServiceProvider(context); if (transientTenant != null && serviceProvider != null) { IPermissionsStoreFactory permissionsStoreFactory = serviceProvider.GetRequiredService <IPermissionsStoreFactory>(); await context.RunAndStoreExceptionsAsync(async() => { var claimsStore = (ClaimPermissionsStore)await permissionsStoreFactory.GetClaimPermissionsStoreAsync(transientTenant); await claimsStore.Container.DeleteAsync(); }).ConfigureAwait(false); await context.RunAndStoreExceptionsAsync(async() => { var ruleSetsStore = (ResourceAccessRuleSetStore)await permissionsStoreFactory.GetResourceAccessRuleSetStoreAsync(transientTenant); await ruleSetsStore.Container.DeleteAsync(); }).ConfigureAwait(false); } }
public static async Task SetupTransientTenant(FeatureContext featureContext, IObjectContainer objectContainer) { ITenantProvider tenantProvider = ContainerBindings.GetServiceProvider(featureContext).GetRequiredService <ITenantProvider>(); var transientTenantManager = TransientTenantManager.GetInstance(featureContext); await transientTenantManager.EnsureInitialised().ConfigureAwait(false); // Create a transient service tenant for testing purposes. ITenant transientServiceTenant = await transientTenantManager.CreateTransientServiceTenantFromEmbeddedResourceAsync( typeof(TransientTenantBindings).Assembly, "Marain.Claims.OpenApi.Specs.ServiceManifests.ClaimsServiceManifest.jsonc").ConfigureAwait(false); // TODO: This only works for the direct invocation mode. We have to do different things for the other // modes. Consider creating a separate DI container for the direct mode instance. IConfiguration configuration = ContainerBindings .GetServiceProvider(featureContext) .GetRequiredService <IConfiguration>(); configuration["MarainServiceConfiguration:ServiceTenantId"] = transientServiceTenant.Id; // Now we need to construct a transient client tenant for the test, and enroll it in the new // transient service. ITenant transientClientTenant = await transientTenantManager.CreateTransientClientTenantAsync().ConfigureAwait(false); await transientTenantManager.AddEnrollmentAsync( transientClientTenant.Id, transientServiceTenant.Id, GetClaimsConfig(featureContext)).ConfigureAwait(false); // TODO: Temporary hack to work around the fact that the transient tenant manager no longer holds the latest // version of the tenants it's tracking; see https://github.com/marain-dotnet/Marain.TenantManagement/issues/28 transientTenantManager.PrimaryTransientClient = await tenantProvider.GetTenantAsync(transientClientTenant.Id).ConfigureAwait(false); var testContext = new ClaimsServiceTestTenants( transientServiceTenant.Id, transientClientTenant.Id); objectContainer.RegisterInstanceAs(testContext); }
/// <summary> /// Retrieves the transient tenant created for the current feature from the supplied <see cref="FeatureContext"/>, /// or null if there is none. /// </summary> /// <param name="context">The current <see cref="FeatureContext"/>.</param> /// <returns>The <see cref="ITenant"/>.</returns> public static ITenant GetTransientTenant(this FeatureContext context) { return(TransientTenantManager.GetInstance(context).PrimaryTransientClient); }
public CommonOperationsApiAndTaskSteps(FeatureContext featureContext, ScenarioContext scenarioContext) { this.repository = ContainerBindings.GetServiceProvider(featureContext).GetRequiredService <FakeOperationsRepository>(); this.transientTenantManager = TransientTenantManager.GetInstance(featureContext); this.scenarioContext = scenarioContext; }
public OperationsControlApiAndTasksSteps(FeatureContext featureContext, ScenarioContext scenarioContext) { this.service = ContainerBindings.GetServiceProvider(featureContext).GetRequiredService <OperationsControlOpenApiService>(); this.transientTenantManager = TransientTenantManager.GetInstance(featureContext); this.scenarioContext = scenarioContext; }