private static void CreateServiceCollection(SpecFlowContext scenarioContext) { scenarioContext.Set(true, ContainerBindingPhaseKey); var serviceCollection = new ServiceCollection(); scenarioContext.Set(serviceCollection, ServiceCollectionKey); }
private static void AddCosmosDbContainerForCleanup( SpecFlowContext context, Container container, Database?database = null) { if (!context.ContainsKey(CosmosDbContainersToDelete)) { context.Set(new List <Container>(), CosmosDbContainersToDelete); } if (database is not null) { if (!context.ContainsKey(CosmosDbDatabasesToDelete)) { context.Set(new List <Database>(), CosmosDbDatabasesToDelete); } List <Database> databasesToDelete = context.Get <List <Database> >(CosmosDbDatabasesToDelete); databasesToDelete.Add(database); } List <Container> containers = context.Get <List <Container> >(CosmosDbContainersToDelete); containers.Add(container); }
protected static void SetUpTestSession(SpecFlowContext context) { var scope = Container.BeginLifetimeScope(builder => builder.RegisterInstance <IMessageSession>(MessageSession)); context.Set(scope, "container_scope"); var testSession = scope.Resolve <TestSession>(); context.Set(testSession); Console.WriteLine($"Created test session: Ukprn: {testSession.Ukprn}, Job Id: {testSession.JobId}"); }
private static void CompleteContainerSetup(SpecFlowContext context) { context.Set(false, ContainerBindingPhaseKey); ServiceCollection serviceCollection = context.Get <ServiceCollection>(ServiceCollectionKey); IServiceProvider service = serviceCollection.BuildServiceProvider(); context.Set(service, ServiceProviderKey); }
private static IWebDriver CreateSeleniumDriver(this SpecFlowContext specFlowContext, IConfiguration configuration) { System.Enum.TryParse(configuration[Constants.EnvironmentVariableKeys.Browser], true, out BrowserTypes browser); switch (browser) { case BrowserTypes.Edge: EdgeOptions egdeOptions = new EdgeOptions { PageLoadStrategy = PageLoadStrategy.Normal, UseChromium = true }; EdgeDriverService edgeDriverService = EdgeDriverService.CreateChromiumService(configuration[Constants.EnvironmentVariableKeys.EdgeWebDriver]); specFlowContext.Set((IWebDriver) new EdgeDriver(edgeDriverService, egdeOptions)); break; case BrowserTypes.Firefox: specFlowContext.Set((IWebDriver) new FirefoxDriver()); break; case BrowserTypes.InternetExplorer: InternetExplorerOptions internetExplorerOptions = new InternetExplorerOptions() { BrowserVersion = configuration[Constants.EnvironmentVariableKeys.InternetExplorerVersion], IgnoreZoomLevel = true }; specFlowContext.Set((IWebDriver) new InternetExplorerDriver(internetExplorerOptions)); break; case BrowserTypes.Safari: SafariDriverService safariDriverService = SafariDriverService.CreateDefaultService(); SafariOptions safariOptions = new SafariOptions(); safariOptions.PageLoadStrategy = PageLoadStrategy.Normal; specFlowContext.Set((IWebDriver) new SafariDriver(safariDriverService)); break; default: { ChromeDriverService chromeDriverService = ChromeDriverService.CreateDefaultService(); chromeDriverService.SuppressInitialDiagnosticInformation = true; specFlowContext.Set((IWebDriver) new ChromeDriver(chromeDriverService)); } break; } return(specFlowContext.Get <IWebDriver>()); }
public static void SetDefaultCollectionProcessorFactory( this SpecFlowContext context, CollectionProcessorFactory factory) { AddDefaultCollectionProcessorFactories(context); context.Set(factory, "__defaultCollectionProcessorFactory__"); }
private static void AddDefaultComparerMappings(this SpecFlowContext context) { const string defaultKey = "__defaultComparersAdded__"; if (context.GetInheritedOrDefault(defaultKey, false)) { return; } context.Set(true, defaultKey); var stringLookup = new Dictionary <string, ComparerMapping>(StringComparer.OrdinalIgnoreCase); var typeLookup = new Dictionary <Type, ComparerMapping>(); SetComparerStringMappingLookup(context, stringLookup); SetComparerTypeMappingLookup(context, typeLookup); Add(new DoubleComparer(context), typeof(double), "Double"); Add(new FloatComparer(context), typeof(float), "Float", "Single"); void Add(IComparer comparer, Type type, params string[] keys) { foreach (string key in keys) { AddComparerMapping(context, new ComparerMapping(key, type, comparer)); } } }
/// <summary> /// Retrieves the current functions controller from the supplied context. /// </summary> /// <param name="context">The SpecFlow context to retrieve from.</param> /// <returns>The FunctionsController.</returns> /// <remarks> /// If the controller hasn't already been added to the context, this method will create /// and add a new instance. /// </remarks> public static FunctionsController GetFunctionsController(SpecFlowContext context) { if (!context.TryGetValue(out ILogger logger)) { logger = Log.CreateLogger <FunctionsController>(); context.Set(logger); } if (!context.TryGetValue(out FunctionsController controller)) { controller = new FunctionsController(logger); context.Set(controller); } return(controller); }
private static void AddDefaultCollectionProcessorFactories(this SpecFlowContext context) { const string defaultKey = "__defaultCollectionProcessorFactoriesAdded__"; if (context.ContainsKey(defaultKey) && context.GetEx <bool>(defaultKey)) { return; } context.Set(true, defaultKey); var lookup = new Dictionary <string, CollectionProcessorFactory>(StringComparer.OrdinalIgnoreCase); var listProcessor = new ListProcessorFactory(context); AddToLookup(new ArrayProcessorFactory(context)); AddToLookup(new EnumerableProcessorFactory(context)); AddToLookup(new ICollectionProcessorFactory(context)); AddToLookup(new IListProcessorFactory(context)); AddToLookup(new IReadOnlyCollectionProcessorFactory(context)); AddToLookup(new IReadOnlyListProcessorFactory(context)); AddToLookup(listProcessor); SetCollectionProcessorFactoryLookup(context, lookup); SetDefaultCollectionProcessorFactory(context, listProcessor); void AddToLookup(CollectionProcessorFactory factory) => factory.CollectionKindNames.ForEach(n => lookup.Add(n, factory)); }
public static T Obtain <T>(this SpecFlowContext context, Func <T> factory, string key = null) { T instance; if (!TryGetInstance(context, key, out instance)) { instance = factory(); if (key == null) { context.Set(instance); } else { context.Set(instance, key); } } return(instance); }
///// <summary> ///// Gets a value from the context using a specified key. Adds and returns a specified default value if the ///// key was not found. ///// </summary> ///// <typeparam name="T">The type of the value to return.</typeparam> ///// <param name="context">The context.</param> ///// <param name="defaultValue">The value to return if the value was not found.</param> ///// <returns>The value associated with the default key or the default value if not found.</returns> //public static T GetOrDefault<T>(this SpecFlowContext context, T defaultValue) // => GetOrDefault(context, typeof(T).FullName, defaultValue); /// <summary>Updates the context value associated with a specified key.</summary> /// <typeparam name="T">The type of the value to update.</typeparam> /// <param name="context">The context.</param> /// <param name="updater">The function to use to update the value.</param> /// <returns>The updated value.</returns> public static T Update <T>(this SpecFlowContext context, string key, Func <T, T> updater) { key = NormalizeKey <T>(context, key); T currentValue = GetEx <T>(context, key); T newValue = updater(currentValue); context.Set(newValue, key); return(newValue); }
private static void RethrowTeardownExceptions(SpecFlowContext context, string key) { context.Set(false, TeardownBindingPhaseKey); if (context.TryGetValue(key, out List <Exception> elist)) { throw new AggregateException(elist); } }
/// <summary> /// Gets the current instance of the manager from the given context. /// </summary> /// <param name="context">The <see cref="SpecFlowContext"/> for the manager.</param> /// <returns> /// The instance of the <see cref="OpenApiWebHostManager"/> for the current feature/scenario. /// </returns> public static OpenApiWebHostManager GetInstance(SpecFlowContext context) { if (!context.TryGetValue(ContextKey, out OpenApiWebHostManager manager)) { manager = new OpenApiWebHostManager(); context.Set(manager, ContextKey); } return(manager); }
/// <summary> /// Retrieves the current functions controller from the supplied context. /// </summary> /// <param name="context">The SpecFlow context to retrieve from.</param> /// <returns>The FunctionsController.</returns> /// <remarks> /// If the controller hasn't already been added to the context, this method will create /// and add a new instance. /// </remarks> public static FunctionsController GetFunctionsController(SpecFlowContext context) { if (!context.TryGetValue(out FunctionsController controller)) { controller = new FunctionsController(); context.Set(controller); } return(controller); }
/// <summary> /// Retrieves the <see cref="FunctionConfiguration"/> from the context. /// </summary> /// <param name="context">The context in which the configuration is stored.</param> /// <returns>The <see cref="FunctionConfiguration"/>.</returns> /// <remarks> /// If a <see cref="FunctionConfiguration"/> hasn't already been added to the context, /// this method will create and add a new instance. /// </remarks> public static FunctionConfiguration GetFunctionConfiguration(SpecFlowContext context) { if (!context.TryGetValue(out FunctionConfiguration value)) { value = new FunctionConfiguration(); context.Set(value); } return(value); }
/// <summary>Updates the context value associated with a specified key.</summary> /// <typeparam name="T">The type of the value to update.</typeparam> /// <param name="context">The context.</param> /// <param name="key">The key.</param> /// <param name="updater">The function to use to update the value.</param> /// <param name="defaultValue">The value to use if the specified key is not found.</param> /// <returns>The updated value.</returns> public static T Update <T>(this SpecFlowContext context, string key, Func <T, T> updater, T defaultValue) { key = NormalizeKey <T>(context, key); if (!context.ContainsKey(key)) { context.Set(defaultValue, key); } return(Update(context, key, updater)); }
///// <summary>Updates the context value associated with a specified key.</summary> ///// <typeparam name="T">The type of the value to update.</typeparam> ///// <param name="context">The context.</param> ///// <param name="key">The key.</param> ///// <param name="updater">The action to use to update the value.</param> ///// <param name="defaultValue">The value to use if the specified key is not found.</param> ///// <returns>The updated value.</returns> //public static void Update<T>(this SpecFlowContext context, string key, Action<T> updater, T defaultValue) //{ // key = NormalizeKey<T>(context, key); // if (!context.ContainsKey(key)) // context.Set(defaultValue, key); // Update(context, key, updater); //} ///// <summary>Updates the context value associated with a specified key.</summary> ///// <typeparam name="T">The type of the value to update.</typeparam> ///// <param name="context">The context.</param> ///// <param name="key">The key.</param> ///// <param name="updater">The function to use to update the value.</param> ///// <param name="defaultValueFactory">Factory to use to get a default value if the specified key is not found.</param> ///// <returns>The updated value.</returns> //public static T Update<T>(this SpecFlowContext context, string key, Func<T, T> updater, Func<T> defaultValueFactory) //{ // key = NormalizeKey<T>(context, key); // if (!context.ContainsKey(key)) // context.Set(defaultValueFactory(), key); // return Update(context, key, updater); //} /// <summary>Updates the context value associated with a specified key.</summary> /// <typeparam name="T">The type of the value to update.</typeparam> /// <param name="context">The context.</param> /// <param name="key">The key.</param> /// <param name="updater">The action to use to update the value.</param> /// <param name="defaultValueFactory">Factory to use to get a default value if the specified key is not found.</param> /// <returns>The updated value.</returns> public static void Update <T>(this SpecFlowContext context, string key, Action <T> updater, Func <T> defaultValueFactory) { key = NormalizeKey <T>(context, key); if (!context.ContainsKey(key)) { context.Set(defaultValueFactory(), key); } Update(context, key, updater); }
///// <summary> ///// Gets a value from the context or parent context(s) using a default key. Returns a boolean indicating ///// whether or not the value was found. ///// </summary> ///// <typeparam name="T">The type of the value to return.</typeparam> ///// <param name="context">The context.</param> ///// <param name="result">The value if found.</param> ///// <returns>A boolean indicating if the value was found.</returns> //public static bool TryGetInherited<T>(this SpecFlowContext context, out T result) // => TryGetInherited<T>(context, typeof(T).FullName, out result); /// <summary> /// Gets a value from the context or parent context(s) using a specified key. Adds and returns a specified /// default value if the key was not found. /// </summary> /// <typeparam name="T">The type of the value to return.</typeparam> /// <param name="context">The context.</param> /// <param name="key">The key.</param> /// <param name="defaultValue">The value to return if the key was not found.</param> /// <returns>The value associated with the specified key or the default value if not found.</returns> public static T GetInheritedOrDefault <T>(this SpecFlowContext context, string key, T defaultValue) { try { return(context.GetInherited <T>(key)); } catch { context.Set(defaultValue, key); return(defaultValue); } }
public static T LazyLoad <T>(this SpecFlowContext specFlowContext, Func <T> creation) where T : class { T item; if (!specFlowContext.TryGetValue(out item)) { item = creation(); specFlowContext.Set(item); } return(item); }
public static async Task ExecuteAndStoreExceptionAsync(SpecFlowContext context, Func <Task> target) { ClearLastException(context); try { await target().ConfigureAwait(false); } catch (Exception ex) { context.Set(ex, LastExceptionContextKey); } }
///// <summary> ///// Gets a value from the context or parent context(s) using a specified key. Adds and returns a specified ///// default value if the key was not found. ///// </summary> ///// <typeparam name="T">The type of the value to return.</typeparam> ///// <param name="context">The context.</param> ///// <param name="defaultValue">The value to return if the value was not found.</param> ///// <returns>The value associated with the default key or the default value if not found.</returns> //public static T GetInheritedOrDefault<T>(this SpecFlowContext context, T defaultValue) // => GetInheritedOrDefault(context, typeof(T).FullName, defaultValue); /// <summary> /// Gets a value from the context using a specified key. Adds and returns a specified default value if the /// key was not found. /// </summary> /// <typeparam name="T">The type of the value to return.</typeparam> /// <param name="context">The context.</param> /// <param name="key">The key.</param> /// <param name="defaultValue">The value to return if the key was not found.</param> /// <returns>The value associated with the specified key or the default value if not found.</returns> public static T GetOrDefault <T>(this SpecFlowContext context, string key, T defaultValue) { T value; if (context.TryGetValue(key, out value)) { return(value); } value = defaultValue; context.Set(value, key); return(value); }
private static void AddDefaultValueProcessors(this SpecFlowContext context) { const string defaultKey = "__defaultValueProcessorsAdded__"; if (context.ContainsKey(defaultKey) && context.GetEx <bool>(defaultKey)) { return; } context.Set(true, defaultKey); var typeLookup = new Dictionary <Type, IValueProcessor>(); var lookup = new Dictionary <string, IValueProcessor>(StringComparer.OrdinalIgnoreCase); var order = new List <IValueProcessor>(); // Auto determine. Add(new BoolProcessor(context)); Add(new IntProcessor(context)); Add(new LongProcessor(context)); Add(new ULongProcessor(context)); Add(new DoubleProcessor(context)); Add(new DurationProcessor(context)); Add(new DateTimeProcessor(context)); Add(new DateTimeOffsetProcessor(context)); Add(new StringProcessor(context)); Add(new ObjectProcessor(context)); // Need to specify type to use. Add(new ByteProcessor(context)); Add(new CharProcessor(context)); Add(new SByteProcessor(context)); Add(new UIntProcessor(context)); Add(new ShortProcessor(context)); Add(new UShortProcessor(context)); Add(new FloatProcessor(context)); Add(new DecimalProcessor(context)); Add(new TimeSpanProcessor(context)); SetValueProcessorLookup(context, lookup); SetValueProcessorLookup(context, typeLookup); SetValueProcessorOrder(context, order); void Add(IValueProcessor processor) { typeLookup.Add(processor.DataType, processor); processor.DataTypeNames.ForEach(n => lookup.Add(n, processor)); order.Add(processor); } }
public static void SetFeatureContext(this SpecFlowContext context, FeatureContext value) => context.Set(value, "__featureContext__");
public static void SetDoubleEpsilon(this SpecFlowContext context, double value) => context.Set(value, "doubleEpsilon");
private static void SetComparerTypeMappingLookup( this SpecFlowContext context, Dictionary <Type, ComparerMapping> value) => context.Set(value, "__comparerTypeMappingLookup__");
public static void ProcessId(this SpecFlowContext context, int processId) { context.Set(processId, "ProcessId"); }
public static void Process(this SpecFlowContext context, CalculatorProcess process) { context.Set(process, "Process"); }
private static void Set <T>(SpecFlowContext context, T value, string key) { context.Set(value, key); }
public static void SetFloatEpsilon(this SpecFlowContext context, float value) => context.Set(value, "floatEpsilon");
public static void SetClipLength(this SpecFlowContext context, int value) => context.Set(value, "__clipLength__");