public static async Task SetupCosmosDbAccountKeys(FeatureContext featureContext) { IServiceProvider serviceProvider = ContainerBindings.GetServiceProvider(featureContext); IConfigurationRoot configRoot = serviceProvider.GetRequiredService <IConfigurationRoot>(); CosmosDbSettings settings = configRoot.Get <CosmosDbSettings>(); if (settings.CosmosDbKeySecretName == null) { throw new NullReferenceException("CosmosDbKeySecretName must be set in config."); } string keyVaultName = configRoot["KeyVaultName"]; string secret = await SecretHelper.GetSecretFromConfigurationOrKeyVaultAsync( configRoot, "kv:" + settings.CosmosDbKeySecretName, keyVaultName, settings.CosmosDbKeySecretName).ConfigureAwait(false); string partitionKeyPath = configRoot["CosmosDbPartitionKeyPath"]; featureContext.Set(partitionKeyPath, CosmosDbContextKeys.PartitionKeyPath); featureContext.Set(settings); featureContext.Set(secret, CosmosDbContextKeys.AccountKey); }
public static async Task SetupCosmosDbDatabaseForFeature(FeatureContext featureContext) { CosmosDbSettings settings = featureContext.Get <CosmosDbSettings>(); if (settings.CosmosDbAccountUri == null) { throw new NullReferenceException("CosmosDbAccountUri must be set in config."); } ICosmosClientBuilderFactory clientBuilderFactory = ContainerBindings.GetServiceProvider(featureContext).GetRequiredService <ICosmosClientBuilderFactory>(); string accountKey = featureContext.Get <string>(CosmosDbContextKeys.AccountKey); CosmosClientBuilder builder; if (clientBuilderFactory is null) { builder = new CosmosClientBuilder(settings.CosmosDbAccountUri, accountKey); } else { builder = clientBuilderFactory.CreateCosmosClientBuilder(settings.CosmosDbAccountUri, accountKey); } builder = builder .WithConnectionModeDirect(); CosmosClient client = builder.Build(); Database database = await client.CreateDatabaseIfNotExistsAsync(settings.CosmosDbDatabaseName, settings.CosmosDbDefaultOfferThroughput).ConfigureAwait(false); featureContext.Set(client, CosmosDbContextKeys.CosmosDbClient); featureContext.Set(database, CosmosDbContextKeys.CosmosDbDatabase); }
public static void RecordFeatureStartTime(FeatureContext context) { var telemetry = context.Get <ILifetimeScope>("container_scope") .Resolve <ITelemetry>(); telemetry.TrackEvent($"Starting Feature: {context.FeatureInfo.Title}"); context.Set(DateTime.Now, "feature_start_time"); context.Set(0, "number_of_scenarios_in_feature"); }
public static void BeforeApiFeature(FeatureContext featureContext) { featureContext.Set(CompositesSpecFlowTestFixture.ServiceProvider); featureContext.Set(new CancellationToken()); Hierarchy hierarchy = LogManager.GetRepository(typeof(CompositesSpecFlowTestFixture).Assembly) as Hierarchy; MemoryAppender memoryAppender = hierarchy.GetAppenders() .SingleOrDefault(a => a.Name == "MemoryAppender") as MemoryAppender; featureContext.Set(memoryAppender); }
public static async Task StartContentManagementFunction(FeatureContext context) { await OpenApiWebHostManager.GetInstance(context).StartFunctionAsync <Startup>(BaseUrl).ConfigureAwait(false); // Create a client for the test var httpClient = new HttpClient(); var client = new ContentClient(httpClient) { BaseUrl = BaseUrl, }; context.Set(httpClient); context.Set(client); }
public static async Task CreateContentTestData(FeatureContext featureContext) { ITenantedContentStoreFactory contentStoreFactory = ContainerBindings.GetServiceProvider(featureContext).GetRequiredService <ITenantedContentStoreFactory>(); IContentStore store = await contentStoreFactory.GetContentStoreForTenantAsync(featureContext.GetCurrentTenantId()).ConfigureAwait(false); for (int i = 0; i < 30; i++) { var content = new Content { Id = Guid.NewGuid().ToString(), Slug = "slug", Tags = new List <string> { "First tag", "Second tag" }, CategoryPaths = new List <string> { "/standard/content;", "/books/hobbit;", "/books/lotr" }, Author = new CmsIdentity(Guid.NewGuid().ToString(), "Bilbo Baggins"), Title = "This is the title", Description = "A description of the content", Culture = CultureInfo.GetCultureInfo("en-GB"), }; Content storedContent = await store.StoreContentAsync(content).ConfigureAwait(false); featureContext.Set(storedContent, "Content" + i); } }
public static void SetUpFeature(FeatureContext context) { SetUpTestSession(context); var dcHelper = Container.Resolve <IDcHelper>(); context.Set(dcHelper); }
public void GivenFormIsFilled() { var title = "iphone 6s"; PageService.Create <NewAdPage>().FillForm(title); context.Set(title, "title"); }
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.Claims.Specs.ServiceManifests.ClaimsServiceManifest.jsonc").ConfigureAwait(false); // Now update the service Id in our 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, 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); featureContext.Set(transientClientTenant); }
public static async Task CreateContentStateTestData(FeatureContext featureContext) { ITenantedContentStoreFactory contentStoreFactory = ContainerBindings.GetServiceProvider(featureContext).GetRequiredService <ITenantedContentStoreFactory>(); IContentStore store = await contentStoreFactory.GetContentStoreForTenantAsync(featureContext.GetCurrentTenantId()).ConfigureAwait(false); for (int i = 0; i < 30; i++) { var state = new ContentState { Id = Guid.NewGuid().ToString(), ContentId = SpecHelpers.ParseSpecValue <string>(featureContext, $"{{Content{i}.Id}}"), Slug = SpecHelpers.ParseSpecValue <string>(featureContext, $"{{Content{i}.Slug}}"), WorkflowId = "workflow1id", ChangedBy = new CmsIdentity(Guid.NewGuid().ToString(), Guid.NewGuid().ToString()), }; if (i < 4) { state.StateName = "draft"; } else if (i < 29) { state.StateName = "published"; } else { state.StateName = "archived"; } ContentState storedContentState = await store.SetContentWorkflowStateAsync(state.Slug, state.ContentId, state.WorkflowId, state.StateName, state.ChangedBy).ConfigureAwait(false); featureContext.Set(storedContentState, $"Content{i}-State"); } }
// 9-3. Create tenant context for session //--------------------------------------- private async Task <SessionContext> GetSessionContext(string scenarioName) { var services = Resolve <TenantServices>(); var tenant = await services.FindTenantByNameAsync(scenarioName); // 10-2. Reset tenant data just once per scenario //----------------------------------------------- if (!_featureContext.ContainsKey(scenarioName)) { _featureContext.Set(true, scenarioName); if (tenant != null) { var dbContext = Resolve <BudgetDbContext>(); dbContext.RemoveRange(await dbContext.BudgetClasses.Where(bc => bc.Tenant_Id == tenant.Id).ToListAsync()); await dbContext.SaveChangesAsync(); await services.RemoveTenantAsync(tenant); } tenant = new Tenant { Name = scenarioName }; var errors = await services.AddTenantAsync(tenant); errors.Should().BeEmpty(); } return(new SessionContext(tenant)); }
public static void BeforeFeature2( TestThreadContext testThreadContext, FeatureContext featureContext) { featureContext.Set(new Stopwatch(), nameof(FeatureStopwatch)); featureContext.Get <Stopwatch>(nameof(FeatureStopwatch)).Start(); }
private void BeforeInvoke(FeatureContext context) { if (context.TryGetValue(out SharedStepsInvocation invocationContext)) { if (invocationContext.Index++ >= invocationContext.Max) { throw new InsufficientExecutionStackException( $"Shared steps execution exceeded maximum depth level of {invocationContext.Max}"); } context.Set(invocationContext); } else { context.Set(new SharedStepsInvocation()); } }
private void AfterInvoke(FeatureContext context) { if (context.TryGetValue(out SharedStepsInvocation invocationContext)) { invocationContext.Index--; context.Set(invocationContext); } }
public void RejectInsertionOrder() { ClickPendingIOStatusLink(); _viewInsertionOrderPage.ClickRejectApprovalButton(); _rejectInsertionOrderApprovalFrame.RejectInsertionOrderApproval(); Assert.AreEqual("The Insertion Order has been rejected by the Agency Approver", _viewInsertionOrderPage.GetMsgText()); FeatureContext.Set(true, ContextStrings.HasIoApproverRejected); }
public static async Task SetupCosmosDbContainerForFeature(FeatureContext featureContext) { string partitionKeyPath = featureContext.Get <string>(CosmosDbContextKeys.PartitionKeyPath); Database database = featureContext.Get <Database>(CosmosDbContextKeys.CosmosDbDatabase); Container container = await database.CreateContainerIfNotExistsAsync("client-" + Guid.NewGuid(), partitionKeyPath).ConfigureAwait(false); featureContext.Set(container, CosmosDbContextKeys.CosmosDbContainer); AddFeatureLevelCosmosDbContainerForCleanup(featureContext, container); }
public static Task StartFunctionWithAdditionalConfigurationAsync(FeatureContext featureContext) { var functionConfiguration = new FunctionConfiguration(); functionConfiguration.EnvironmentVariables.Add("ResponseMessage", "Welcome, {name}"); featureContext.Set(functionConfiguration); return(StartFunctionsAsync(featureContext)); }
public static IWebDriver Driver(this FeatureContext scenarioContext) { if (!scenarioContext.ContainsKey(typeof(IWebDriver).FullName)) { scenarioContext.Set((IWebDriver) new FirefoxDriver()); } return(scenarioContext.Get <IWebDriver>()); }
public static ContainerTestContext GetForFeature(FeatureContext featureContext) { if (!featureContext.TryGetValue(out ContainerTestContext result)) { result = new FeatureContainerTestContext(featureContext); featureContext.Set(result); } return(result); }
public static async Task SetupCosmosContainerForRootTenant(FeatureContext featureContext) { IServiceProvider serviceProvider = ContainerBindings.GetServiceProvider(featureContext); ITenantCosmosContainerFactory factory = serviceProvider.GetRequiredService <ITenantCosmosContainerFactory>(); ITenantProvider tenantProvider = serviceProvider.GetRequiredService <ITenantProvider>(); string containerBase = Guid.NewGuid().ToString(); CosmosConfiguration config = tenantProvider.Root.GetDefaultCosmosConfiguration(); config.DatabaseName = "endjinspecssharedthroughput"; config.DisableTenantIdPrefix = true; tenantProvider.Root.SetDefaultCosmosConfiguration(config); Container contentManagementSpecsContainer = await factory.GetContainerForTenantAsync( tenantProvider.Root, new CosmosContainerDefinition("endjinspecssharedthroughput", $"{containerBase}contentmanagementspecs", Content.PartitionKeyPath, databaseThroughput : 400)).ConfigureAwait(false); featureContext.Set(contentManagementSpecsContainer, ContentManagementSpecsContainer); featureContext.Set <IContentStore>(new CosmosContentStore(contentManagementSpecsContainer), ContentManagementSpecsContentStore); }
public static Task StartFunctionsAsync(FeatureContext featureContext) { var functionsController = new FunctionsController(); featureContext.Set(functionsController); return(functionsController.StartFunctionsInstance( featureContext, null, "Corvus.SpecFlow.Extensions.DemoFunction", 7075, "netcoreapp3.1")); }
public void SetInvocationStack() { var tagPrefix = "maxDepth:"; var depthTag = scenarioContext.ScenarioInfo.Tags.First(tag => tag.StartsWith(tagPrefix)); if (depthTag != null) { featureContext.Set(new SharedStepsInvocation() { Index = 0, Max = int.Parse(depthTag.Replace(tagPrefix, string.Empty)) }); } }
public static void SetUpFeature(FeatureContext featureContext, TestContext testContext) { var featureTitle = featureContext.FeatureInfo.Title; var reportPath = featureTitle.Length > 30 ? featureTitle.Substring(0, 30) : featureTitle; FeatureDto featureDto = new FeatureDto { Title = featureTitle, Description = featureContext.FeatureInfo.Description, Tags = featureContext.FeatureInfo.Tags, ReportPath = testContext.OutputFilePath($"{reportPath}.html"), ReportDirectory = testContext.UniqueOutputDirectory, Scenarios = new Dictionary <string, ScenarioDto>() }; featureContext.Set(featureDto); }
public InsertionOrderStep(IWebDriver driver, FeatureContext featureContext) : base(driver, featureContext) { _manageMultipleInsertionOrderPage = new ManageMultipleInsertionOrderPage(driver, featureContext); _addEditInsertionOrderPage = new AddEditInsertionOrderPage(driver, featureContext); _viewInsertionOrderPage = new ViewInsertionOrderPage(driver, featureContext); _issueInsertionOrderFrame = new IssueInsertionOrderFrame(driver, featureContext); _acceptInsertionOrderFrame = new AcceptInsertionOrderFrame(driver, featureContext); _manageInsertionOrderPage = new ManageInsertionOrderPage(driver, featureContext); _exportInsertionOrderFrame = new ExportInsertionOrderFrame(driver, featureContext); _sendForApprovalFrame = new SendForApprovalFrame(driver, featureContext); _rejectInsertionOrderApprovalFrame = new RejectInsertionOrderApprovalFrame(driver, featureContext); _rejectInsertionOrderFrame = new RejectInsertionOrderFrame(driver, featureContext); _addNonMediaCostItemsFrame = new AddNonMediaCostItemsFrame(driver, featureContext); _addCostItemsFrame = new AddCostItemsFrame(driver, featureContext); _gridInsertionOrderLandingPage = new GridInsertionOrderLandingPage(driver, featureContext); FeatureContext.Set(false, ContextStrings.HasIoApproverRejected); }
public static void SetupCosmosDbRepository(FeatureContext featureContext) { IServiceProvider serviceProvider = ContainerBindings.GetServiceProvider(featureContext); ICosmosContainerSourceWithTenantLegacyTransition factory = serviceProvider.GetRequiredService <ICosmosContainerSourceWithTenantLegacyTransition>(); ICosmosOptionsFactory optionsFactory = serviceProvider.GetRequiredService <ICosmosOptionsFactory>(); ITenantProvider tenantProvider = serviceProvider.GetRequiredService <ITenantProvider>(); IConfiguration configuration = serviceProvider.GetRequiredService <IConfiguration>(); ITenant rootTenant = tenantProvider.Root; LegacyV2CosmosContainerConfiguration cosmosConfig = configuration.GetSection("TestCosmosConfiguration").Get <LegacyV2CosmosContainerConfiguration>() ?? new LegacyV2CosmosContainerConfiguration(); cosmosConfig.DatabaseName = "endjinspecssharedthroughput"; cosmosConfig.DisableTenantIdPrefix = true; tenantProvider.Root.UpdateProperties(data => data.Append(new KeyValuePair <string, object>( $"StorageConfiguration__{TenantedCosmosWorkflowStoreServiceCollectionExtensions.WorkflowStoreLogicalDatabaseName}__{TenantedCosmosWorkflowStoreServiceCollectionExtensions.WorkflowDefinitionStoreLogicalContainerName}", cosmosConfig))); tenantProvider.Root.UpdateProperties(data => data.Append(new KeyValuePair <string, object>( $"StorageConfiguration__{TenantedCosmosWorkflowStoreServiceCollectionExtensions.WorkflowStoreLogicalDatabaseName}__{TenantedCosmosWorkflowStoreServiceCollectionExtensions.WorkflowInstanceStoreLogicalContainerName}", cosmosConfig))); tenantProvider.Root.UpdateProperties(data => data.Append(new KeyValuePair <string, object>( "StorageConfiguration__workflow__testdocuments", cosmosConfig))); Newtonsoft.Json.JsonSerializerSettings jsonSettings = serviceProvider.GetRequiredService <IJsonSerializerSettingsProvider>().Instance; Container testDocumentsRepository = WorkflowRetryHelper.ExecuteWithStandardTestRetryRulesAsync( async() => await factory.GetContainerForTenantAsync( rootTenant, "StorageConfiguration__workflow__testdocuments", "NotUsed", "workflow", "testdocuments", "/id", cosmosClientOptions: optionsFactory.CreateCosmosClientOptions())).Result; featureContext.Set(testDocumentsRepository, TestDocumentsRepository); }
public static async Task SetupTransientTenant(FeatureContext context) { // This needs to run after the ServiceProvider has been constructed IServiceProvider provider = ContainerBindings.GetServiceProvider(context); ITenantProvider tenantProvider = provider.GetRequiredService <ITenantProvider>(); // In order to ensure the Cosmos aspects of the Tenancy setup are fully configured, we need to resolve // the ITenantCosmosContainerFactory, which triggers setting default config to the root tenant. // HACK: This is a hack until we can come up with a better way of handling deferred initialisation. provider.GetRequiredService <ITenantCosmosContainerFactory>(); ITenant rootTenant = tenantProvider.Root; ITenant transientTenant = await tenantProvider.CreateChildTenantAsync(rootTenant.Id).ConfigureAwait(false); CosmosConfiguration config = rootTenant.GetDefaultCosmosConfiguration() ?? new CosmosConfiguration(); config.DatabaseName = "endjinspecssharedthroughput"; config.DisableTenantIdPrefix = true; transientTenant.SetDefaultCosmosConfiguration(config); await tenantProvider.UpdateTenantAsync(transientTenant).ConfigureAwait(false); context.Set(transientTenant); }
public static void BeforeFeature(FeatureContext ctx) { ctx.Set(_server); //ctx.Set(_client); //ctx.Set(_smtp); }
public static void RethrowFeatureBindingAvailableValidation(FeatureContext featureContext) { featureContext.Set(true, TeardownBindingPhaseKey); }
public static void EntityId <T>(this FeatureContext context, T value) { context.Set(value, nameof(EntityId)); }
private static void SetLoginAttempts(this FeatureContext featureContext, List <DateTime> value) { featureContext.Set(value, LoginAttempts); }