// 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 async Task AfterFeature(FeatureContext featureContext, EnvironmentSettings settings) { if (featureContext.ContainsKey("CleanupData")) { var cleanupData = featureContext["CleanupData"] as CleanupData; if (cleanupData != null) { // remote cosmos rows foreach (var dataItem in cleanupData.Documents) { } // Remove sql rows from both history tables using (var sqlConnection = new SqlConnection(settings.sqlConnectionString)) { await sqlConnection.OpenAsync(); foreach (var sqlRow in cleanupData.Database) { var deleteRecordCommand = new SqlCommand($"DELETE FROM [dbo].[{sqlRow.Item1}] where {sqlRow.Item2} = '{sqlRow.Item3.ToString()}'", sqlConnection); await deleteRecordCommand.ExecuteNonQueryAsync(); var deleteHistoryCommand = new SqlCommand($"DELETE FROM [dbo].[{sqlRow.Item1}-history] where {sqlRow.Item2} = '{sqlRow.Item3.ToString()}'", sqlConnection); await deleteHistoryCommand.ExecuteNonQueryAsync(); } await sqlConnection.CloseAsync(); } } } }
public static IWebDriver Browser(this FeatureContext context) { if (!context.ContainsKey(@"browser")) { throw new ApplicationException("The browser has not been added to the features context"); } return((IWebDriver)context[@"browser"]); }
public static void DontRunIfFailedPreviousScenario(FeatureContext featureContext) { if (featureContext.ContainsKey("FailedTests") && (bool)featureContext["FailedTests"]) { Assert.Fail("Failing as previous examples of this feature have failed"); } }
public static T GetOrAdd <T>(this FeatureContext feature, Func <T> creator, [CallerMemberName] string name = "") where T : class { if (!feature.ContainsKey(name)) { feature[name] = creator(); } return(feature[name] as T); }
public static void SetApplication <T>(this FeatureContext featureContext, T application) { if (featureContext.ContainsKey(ApplicationKey)) { throw new ApplicationException("Application has already been set for this scenario"); } featureContext.Add(ApplicationKey, application); }
public static void SetBrowser(this FeatureContext featureContext, IWebDriver browser) { if (featureContext.ContainsKey(BrowserKey)) { throw new ApplicationException("Browser has already been set for this scenario"); } featureContext.Add(BrowserKey, browser); }
public static IWebDriver Driver(this FeatureContext scenarioContext) { if (!scenarioContext.ContainsKey(typeof(IWebDriver).FullName)) { scenarioContext.Set((IWebDriver) new FirefoxDriver()); } return(scenarioContext.Get <IWebDriver>()); }
public void BeforeScenario(FeatureContext feature, ScenarioContext scenario) { Console.WriteLine($"Starting scenario: {scenario.ScenarioInfo.Title}"); if (!feature.ContainsKey(App)) { LaunchBrowserAndNavigateToSupportPage(feature); } }
public static void StartScenarioContainerSetup( FeatureContext featureContext, ScenarioContext scenarioContext) { if (featureContext.ContainsKey(ContainerBindingPhaseKey)) { throw new InvalidOperationException("You cannot use both @perFeatureContainer and @perScenarioContainer in combination"); } CreateServiceCollection(scenarioContext); }
private void DeleteRowFromSql(string table, string primaryKey, string id) { if (_featureContext.ContainsKey("CleanupData")) { var cleanupData = _featureContext["CleanupData"] as CleanupData; if (cleanupData != null) { cleanupData.Database.Add(new Tuple <string, string, string>(table, primaryKey, id)); } } else { _featureContext.Add("CleanupData", new CleanupData()); } }
public bool Checkloggedinas(string Role) { if (_featureContext.ContainsKey("token")) { if (_featureContext.ContainsValue(Role)) { return(true); } else { return(false); } } else { return(false); } }
public void GivenIHaveCreatedAUser(UserType userType) { LoginUser featureLoginUser; if (!FeatureContext.ContainsKey("LoginUser")) { featureLoginUser = UserFactory.Create(userType); var registerPage = HomePage .TopNavMenu .ClickRegister(); registerPage.RegisterUser(featureLoginUser); FeatureContext["LoginUser"] = featureLoginUser; } else { featureLoginUser = (LoginUser)FeatureContext["LoginUser"]; } TestContext.LoginUser = featureLoginUser; }
public void IntialiseEnvironementVariables() { string value; string name; _scenarioContext.SetEnv(new EnvironmentSettings()); if (_featureContext.ContainsKey(constants.featureFailAll) && (bool)_featureContext[constants.featureFailAll] == true) { throw new Exception("Feature run aborted due to earlier failure"); } PropertyInfo[] properties = typeof(EnvironmentSettings).GetProperties(); foreach (PropertyInfo property in properties) { name = property.Name; value = string.Empty; try { if (property.PropertyType == typeof(Boolean)) { value = ((bool)property.GetValue(_scenarioContext.GetEnv())).ToString(); } else { value = (string)property.GetValue(_scenarioContext.GetEnv()); if (name.ToLower().Contains("key") || name.ToLower().Contains("password") || name.Contains("pwd") || name.Contains("secret")) { value = mask.Substring(0, value.Length); } } } catch { } Console.WriteLine($"Env: {property.Name} = {value}"); } }