Example #1
0
        /// <summary>
        /// Adds asynchronous step with name specified by <paramref name="name"/> parameter and action specified by <paramref name="step"/> parameter to the scenario.
        /// </summary>
        /// <typeparam name="TContext">Scenario context, if specified.</typeparam>
        /// <param name="builder">Builder.</param>
        /// <param name="name">Step name to be rendered.</param>
        /// <param name="step">Step action</param>
        /// <returns>Builder.</returns>
        public static IScenarioRunner <TContext> AddAsyncStep <TContext>(this IScenarioBuilder <TContext> builder, string name, Func <TContext, Task> step)
        {
            var integration = builder.Integrate();

            integration.Core.AddSteps(new[] { CompactStepCompiler.ToAsynchronousStep(name, step) });
            return(integration);
        }
Example #2
0
        /// <summary>
        /// Adds asynchronous steps specified by <paramref name="steps"/> to the scenario, where steps names are inferred directly from provided action names.<br/>
        /// Example usage:
        /// <code>
        /// AddAsyncSteps(
        ///         Given_numbers_5_and_8,
        ///         When_I_add_them,
        ///         I_should_receive_number_13)
        /// </code>
        /// Expected step signature: <code>Task Given_numbers_5_and_8() { /* ... */ }</code>
        /// </summary>
        /// <param name="builder">Builder.</param>
        /// <param name="steps">Steps to add, like: <c>AddAsyncSteps(Given_numbers_5_and_8, When_I_add_them, I_should_receive_number_13)</c></param>
        public static IScenarioRunner <NoContext> AddAsyncSteps(this IScenarioBuilder <NoContext> builder, params Func <Task>[] steps)
        {
            var integration = builder.Integrate();

            integration.Core.AddSteps(steps.Select(BasicStepCompiler.ToAsynchronousStep));
            return(integration);
        }
Example #3
0
        public MainViewModel(AppSettings appSettings, DatabaseSettings dbSettings, IScenarioBuilder scenarioBuilder, IRepository <Scenario> repository, IScenarioExecutor scenarioExecutor, IScenarioFileManager scenarioFileManager)
        {
            Settings             = appSettings;
            DbSettings           = dbSettings;
            _scenarioBuilder     = scenarioBuilder;
            _repository          = repository;
            _scenarioExecutor    = scenarioExecutor;
            _scenarioFileManager = scenarioFileManager;

            _aggregateScenarios = new ObservableCollection <Scenario>();
            _aggregateScenarios.CollectionChanged +=
                (sender, args) =>
            {
                CreateAggregateScenarioCommand.RaiseCanExecuteChanged();
                ClearAggregateScenariosCommand.RaiseCanExecuteChanged();
            };

            ExecuteScenarioCommand         = new RelayCommand <Scenario>(ExecuteScenario);
            DeleteScenarioCommand          = new RelayCommand <Scenario>(DeleteScenario);
            StartCommand                   = new RelayCommand(Start);
            StopCommand                    = new RelayCommand(Stop);
            EditScenarioCommand            = new RelayCommand <Scenario>(EditScenario);
            ExportScenarioCommand          = new RelayCommand <Scenario>(ExportScenario);
            CreateAggregateScenarioCommand = new RelayCommand(CreateAggregateScenario, AnyAggregateScenarios);
            AddAggregateScenarioCommand    = new RelayCommand(AddAggregateScenario, IsAggregateScenario);
            ClearAggregateScenariosCommand = new RelayCommand(ClearAggregateScenarios, AnyAggregateScenarios);

            DbSettings.DbFilePathChanged += DbSettings_DbFilePathChanged;
            LoadScenarios();
            IsRecording = false;
        }
Example #4
0
        /// <summary>
        /// Adds asynchronous steps specified by <paramref name="steps"/> parameter to the scenario.<br/>
        /// The step name is determined from lambda parameter name reflecting action type keyword, corresponding action name and passed list of parameters to called method.<br/>
        /// If scenario is defined with context, the context instance is provided with lambda parameter.<br/>
        /// Example usage:
        /// <code>
        /// AddAsyncSteps(
        ///         _ => Given_numbers(5, 8),
        ///         _ => When_I_add_them(),
        ///         _ => I_should_receive_number(13))
        /// </code>
        /// Expected step signature: <code>Task Given_numbers(params int[] numbers) { /* ... */ }</code>
        /// </summary>
        /// <param name="builder">Builder.</param>
        /// <param name="steps">Steps to add, like: <c>AddAsyncSteps(_ => Given_numbers(5, 8), _ => When_I_add_them(), _ => I_should_receive_number(13))</c></param>
        public static IScenarioRunner <TContext> AddAsyncSteps <TContext>(this IScenarioBuilder <TContext> builder, params Expression <Func <TContext, Task> >[] steps)
        {
            var integration = builder.Integrate();
            var compiler    = new ExtendedStepCompiler <TContext>(integration.Core.Configuration);

            integration.Core.AddSteps(steps.Select(compiler.ToStep));
            return(integration);
        }
Example #5
0
        public void AddScenario(IScenarioBuilder scenarioBuilder)
        {
            if (scenarios.Any(s => s.Title.Equals(scenarioBuilder.Title)))
                throw new GherkinSemanticErrorException(
                    string.Format("Feature file already contains a scenario with name '{0}'", scenarioBuilder.Title),
                    scenarioBuilder.Position);

            scenarios.Add(scenarioBuilder);
        }
Example #6
0
        protected TScenario BuildTestScenario()
        {
            IScenarioBuilder <TScenario> builder = _builderFactory();

            builder = _configurators.Aggregate(builder, (current, configurator) => configurator.Configure(current));

            TScenario context = builder.Build();

            return(context);
        }
        public IScenarioBuilder <TScenario> Configure(IScenarioBuilder <TScenario> builder)
        {
            var endpointBuilder = builder as IEndpointScenarioBuilder <TScenario>;

            if (endpointBuilder != null)
            {
                endpointBuilder.ConfigureEndpointFactory(_configureAction);
            }

            return(builder);
        }
        public IScenarioBuilder <IBusTestScenario> Configure(IScenarioBuilder <IBusTestScenario> builder)
        {
            var busBuilder = builder as IBusScenarioBuilder;

            if (busBuilder != null)
            {
                busBuilder.ConfigureBus(_configureAction);
            }

            return(builder);
        }
Example #9
0
        public void AddScenario(IScenarioBuilder scenarioBuilder)
        {
            if (scenarios.Any(s => s.Title.Equals(scenarioBuilder.Title)))
            {
                throw new GherkinSemanticErrorException(
                          string.Format("Feature file already contains a scenario with name '{0}'", scenarioBuilder.Title),
                          scenarioBuilder.Position);
            }

            scenarios.Add(scenarioBuilder);
        }
Example #10
0
 public ContextSpecBuilder(IContextBuilder contextBuilder, IScenarioBuilder scenarioBuilder)
 {
     _contextBuilder = contextBuilder;
     _scenarioBuilder = scenarioBuilder;
 }
Example #11
0
 /// <summary>
 /// Adds steps specified by <paramref name="steps"/> parameter.<br/>
 /// The steps would be executed in specified order.<br/>
 /// If given step throws, other are not executed.<br/>
 /// Step name is determined from lambda parameter name reflecting action type keyword, corresponding action name and passed list of parameters to called method.<br/>
 /// If scenario is executed with context, the context instance is provided with lambda parameter.
 /// Please note that rules for placing parameter values in step name are as follows, where first matching rule would be used:
 /// <list type="bullet">
 /// <item><description>it will replace first occurrence of variable name written in capital letters (<c>void Price_is_AMOUNT_dollars(int amount)</c> => <c>Price is "27" dollars</c>)</description></item>
 /// <item><description>it will placed after first occurrence of variable name (<c>void Product_is_in_stock(string product)</c> => <c>Product "desk" is in stock</c>)</description></item>
 /// <item><description>it will placed at the end of step name (<c>void Product_is_in_stock(string productId)</c> => <c>Product is in stock [productId: "ABC123"]</c>)</description></item>
 /// </list>
 /// <para>
 /// Example usage for scenarios with no context:
 /// <code>
 /// builder.AddSteps(
 ///     _ => Given_product_is_available_in_product_storage("wooden desk"),
 ///     _ => When_customer_buys_product("wooden desk"),
 ///     _ => Then_invoice_should_contain_product_with_price_of_AMOUNT_pounds("wooden desk", 62));
 /// </code>
 /// Expected step signature:
 /// <code>
 /// void Given_product_is_available_in_product_storage(string product) { /* ... */ }
 /// </code>
 /// </para>
 /// <para>
 /// Example usage for scenarios with context:
 /// <code>
 /// builder.WithContext&lt;SpeditionContext&gt;().AddSteps(
 ///     _ => _.Given_there_is_an_active_customer_with_id("ABC-123"),
 ///     _ => _.Given_the_customer_has_product_in_basket("wooden shelf"),
 ///     _ => _.When_the_customer_payment_finalizes(),
 ///     _ => _.Then_product_should_be_dispatched_to_the_customer("wooden shelf"));
 /// </code>
 /// Expected step signature:
 /// <code>
 /// class SpeditionContext
 /// {
 ///     void Given_product_is_available_in_product_storage(string product) { /* ... */ }
 /// }
 /// </code>
 /// </para>
 /// </summary>
 /// <param name="builder">Scenario builder.</param>
 /// <param name="steps">Steps to add.</param>
 /// <returns><paramref name="builder"/> instance.</returns>
 public static IScenarioBuilder <TContext> AddSteps <TContext>(this IScenarioBuilder <TContext> builder, params Expression <Action <TContext> >[] steps)
 {
     AsExtended(builder).AddSteps(steps);
     return(builder);
 }
Example #12
0
 private static ExtendedScenarioBuilder <TContext> AsExtended <TContext>(this IScenarioBuilder <TContext> runner)
 {
     return(runner.Integrate().Enrich(ExtendedScenarioBuilder <TContext> .Create));
 }
Example #13
0
 public Calculator(IEquipmentProvider equipmentProvider, IScenarioBuilder scenarioBuilder, IReportsExporter reportsExporter)
 {
     EquipmentProvider = equipmentProvider;
     ScenarioBuilder   = scenarioBuilder;
     ReportsExporter   = reportsExporter;
 }
Example #14
0
 /// <summary>
 /// Adds step with name specified by <paramref name="name"/> parameter and action specified by <paramref name="step"/> parameter to the scenario.
 /// </summary>
 /// <typeparam name="TContext">Scenario context, if specified.</typeparam>
 /// <param name="builder">Builder.</param>
 /// <param name="name">Step name to be rendered.</param>
 /// <param name="step">Step action</param>
 /// <returns>Builder.</returns>
 public static IScenarioBuilder <TContext> AddStep <TContext>(this IScenarioBuilder <TContext> builder, string name, Action <TContext> step)
 {
     builder.Integrate().AddSteps(new[] { CompactStepCompiler.ToSynchronousStep(name, step) });
     return(builder);
 }
Example #15
0
 /// <summary>
 /// Adds steps specified by <paramref name="steps"/> parameter.<br/>
 /// The steps would be executed in specified order.<br/>
 /// If given step throws, other are not executed.<br/>
 /// The step name is determined from corresponding action name.<br/>
 /// Example usage:
 /// <code>
 /// builder.AddAsyncSteps(
 ///     Given_the_user_is_about_to_login,
 ///     Given_the_user_entered_valid_login,
 ///     Given_the_user_entered_valid_password,
 ///     When_the_user_clicks_login_button,
 ///     Then_the_login_operation_should_be_successful,
 ///     Then_a_welcome_message_containing_user_name_should_be_returned);
 /// </code>
 /// Expected step signature:
 /// <code>
 /// async Task Given_the_user_is_about_to_login() { /* ... */ }
 /// </code>
 /// </summary>
 /// <param name="builder">Scenario builder.</param>
 /// <param name="steps">Steps to add.</param>
 /// <returns><paramref name="builder"/> instance.</returns>
 public static IScenarioBuilder <NoContext> AddAsyncSteps(this IScenarioBuilder <NoContext> builder, params Func <Task>[] steps)
 {
     builder.Integrate().AddSteps(steps.Select(BasicStepCompiler.ToAsynchronousStep));
     return(builder);
 }
Example #16
0
 public void AddScenario(IScenarioBuilder scenarioBuilder)
 {
     scenarios.Add(scenarioBuilder);
 }