Beispiel #1
0
 public StepTestRunner(
     IStepContext stepContext,
     Func <IStepContext, Task> body,
     ITest test,
     IMessageBus messageBus,
     Type scenarioClass,
     object[] constructorArguments,
     MethodInfo scenarioMethod,
     object[] scenarioMethodArguments,
     string skipReason,
     IReadOnlyList <BeforeAfterTestAttribute> beforeAfterAttributes,
     ExceptionAggregator aggregator,
     CancellationTokenSource cancellationTokenSource)
     : base(
         test,
         messageBus,
         scenarioClass,
         constructorArguments,
         scenarioMethod,
         scenarioMethodArguments,
         skipReason,
         beforeAfterAttributes,
         aggregator,
         cancellationTokenSource)
 {
     this.stepContext = stepContext;
     this.body        = body;
 }
        /// <summary>
        /// Immediately registers the <see cref="IDisposable"/> object for disposal
        /// after all steps in the current scenario have been executed.
        /// </summary>
        /// <typeparam name="T">The type of the object.</typeparam>
        /// <param name="obj">The object to be disposed.</param>
        /// <param name="stepContext">The execution context for the current step.</param>
        /// <returns>The object.</returns>
        public static T Using <T>(this T obj, IStepContext stepContext) where T : IDisposable
        {
            Guard.AgainstNullArgument("stepContext", stepContext);

            stepContext.Using(obj);
            return(obj);
        }
#pragma warning disable IDE0060 // Remove unused parameter 'text' if it is not part of a shipped public API
        public void UsingMetadata(string text, IStepContext stepContext, IStep step, IScenario scenario)
#pragma warning restore IDE0060 // Remove unused parameter 'text' if it is not part of a shipped public API
        {
            "When I execute a step".x(context => stepContext = context)
            .Teardown(context => context.AssertSame(stepContext));

            "Then the step context contains metadata about the step".x(() =>
            {
                step = stepContext.Step.AssertNotNull();
                var stepDisplayName = step.DisplayName;
                stepDisplayName.AssertEqual($"Xwellbehaved.MetadataFeature.UsingMetadata(text: \"abc\") [01] ({StepType.Scenario}): When I execute a step");
            });

            "And the step contains metadata about the scenario".x(() =>
            {
                scenario = step.Scenario.AssertNotNull();
                var scenarioDisplayName = scenario.DisplayName;
                scenarioDisplayName.AssertEqual("Xwellbehaved.MetadataFeature.UsingMetadata(text: \"abc\")");
            });

            "And the step contains metadata about the scenario outline".x(() =>
            {
                var scenarioScenarioOutline = scenario.ScenarioOutline;
                scenarioScenarioOutline.AssertNotNull();
                scenarioScenarioOutline.DisplayName.AssertEqual("Xwellbehaved.MetadataFeature.UsingMetadata");
            });
        }
        public void Execute(IStepContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException($"{nameof(context)}");
            }

            var ctx = context.Parent;

            while (ctx.ProcessingStep.GetType().FullName != typeof(ExecutiveOffice.EDT.FileOps.Steps.From.From).FullName)
            {
                if (ctx.Parent == null)
                {
                    return;                     // throw new ArgumentOutOfRangeException($"Missing step {nameof(From.From)}");
                }
                ctx = ctx.Parent;
            }

            IChannel channel = ChannelFactory.Create(ctx.FromSettings, ctx.WorkingDirectory);

            try
            {
                channel.Delete(ctx.Files);

                context.WorkingDirectory.DeleteWithContentIfExists();
            }catch (Exception ex)
            {
                throw new ApplicationException("Exception occured during TearDown Delete", ex);
            }
        }
Beispiel #5
0
 public StepContext(IStepContext previousStepContext) : this(previousStepContext.ProcessingStep, previousStepContext.Guid, previousStepContext.WorkingDirectory)
 {
     if (previousStepContext == null)
     {
         throw new ArgumentNullException($"{previousStepContext}");
     }
     _previousFiles = previousStepContext.Files.ToList();
 }
        /// <summary>
        /// Immediately registers the <see cref="IDisposable"/> object for disposal
        /// after all steps in the current scenario have been executed.
        /// </summary>
        /// <typeparam name="T">The type of the object.</typeparam>
        /// <param name="disposable">The object to be disposed.</param>
        /// <param name="stepContext">The execution context for the current step.</param>
        /// <returns>The object.</returns>
        public static T Using <T>(this T disposable, IStepContext stepContext)
            where T : IDisposable
        {
            Guard.AgainstNullArgument(nameof(stepContext), stepContext);

            stepContext.Using(disposable);
            return(disposable);
        }
Beispiel #7
0
        public void Execute(IStepContext context)
        {
            context.WorkingDirectory.Create();

            IChannel channel = ChannelFactory.Create(_settings, context.WorkingDirectory);

            var processedFiles = channel.Copy();

            context.Attach(processedFiles);
        }
Beispiel #8
0
 public StepInvoker(
     IStepContext stepContext,
     Func <IStepContext, Task> body,
     ExceptionAggregator aggregator,
     CancellationTokenSource cancellationTokenSource)
 {
     this.stepContext             = stepContext;
     this.body                    = body;
     this.aggregator              = aggregator ?? throw new ArgumentNullException(nameof(aggregator));
     this.cancellationTokenSource = cancellationTokenSource ?? throw new ArgumentNullException(nameof(cancellationTokenSource));
 }
Beispiel #9
0
        public void Execute(IStepContext context)
        {
            var compressor = new Processors.Compression.ZipFactory(_settings).Get();

            foreach (var file in context.Parent.Files)
            {
                var uncompressedFiles = compressor.Decompress(file, context.WorkingDirectory);

                context.Attach(uncompressedFiles);
            }
        }
 public IStepContext Execute(Unity.OperationContext operationContext, IStepContext previousStepContext)
 {
     if ((this.Skip != null) && this.Skip(operationContext))
     {
         return(null);
     }
     this.OperationContext    = operationContext;
     this.PreviousStepContext = previousStepContext;
     this.OperationContext    = null;
     this.PreviousStepContext = null;
     return(this.Execute());
 }
        public AggregationRoot(string identifier)
        {
            _guid = Guid.NewGuid();

            _identifier = string.IsNullOrEmpty(identifier) ? throw new ArgumentNullException($"{identifier}") : identifier;

            AttachWorkingDirectory();

            _emptyStepContext = new StepContext(new Init(), _guid, _workingDirectory);

            _contexts.Push(_emptyStepContext);
        }
Beispiel #12
0
        public void Execute()
        {
            OperationContext operationContext    = new OperationContext();
            IStepContext     previousStepContext = null;

            using (List <Step> .Enumerator enumerator = this.steps.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    previousStepContext = enumerator.Current.Execute(operationContext, previousStepContext);
                }
            }
        }
Beispiel #13
0
        public StepInvoker(
            IStepContext stepContext,
            Func <IStepContext, Task> body,
            ExceptionAggregator aggregator,
            CancellationTokenSource cancellationTokenSource)
        {
            Guard.AgainstNullArgument(nameof(aggregator), aggregator);
            Guard.AgainstNullArgument(nameof(cancellationTokenSource), cancellationTokenSource);

            this.stepContext             = stepContext;
            this.body                    = body;
            this.aggregator              = aggregator;
            this.cancellationTokenSource = cancellationTokenSource;
        }
        public void UsingMetadata(string text, IStepContext stepContext, IStep step, IScenario scenario)
        {
            "When I execute a step"
            .x(c => stepContext = c)
            .Teardown(c => Assert.Same(stepContext, c));

            "Then the step context contains metadata about the step"
            .x(() => Assert.Equal("Xbehave.Test.MetadataFeature.UsingMetadata(text: \"abc\") [01] When I execute a step", (step = stepContext.Step)?.DisplayName));

            "And the step contains metadata about the scenario"
            .x(() => Assert.Equal("Xbehave.Test.MetadataFeature.UsingMetadata(text: \"abc\")", (scenario = step.Scenario)?.DisplayName));

            "And the step contains metadata about the scenario outline"
            .x(() => Assert.Equal("Xbehave.Test.MetadataFeature.UsingMetadata", scenario.ScenarioOutline?.DisplayName));
        }
Beispiel #15
0
        public void Execute(IStepContext context)
        {
            DirectoryInfo flushDirectory = context.WorkingDirectory.CreateSubdirectory("Flush");

            context.Attach(context.PreviousFiles);

            //TODO: fix To channel + channel factory to be able to accept IEnumerable<FileInfo> instead of DirectoryInfo
            foreach (var file in context.PreviousFiles)
            {
                file.CopyTo(Path.Combine(flushDirectory.FullName, file.Name));
            }

            IChannel channel = ChannelFactory.Create(_settings, flushDirectory);

            channel.Copy();
        }
        public void Test_DeserializeReplayStep_WithoutObservation()
        {
            // Arrange
            string expectedEventId     = "my_experiment-t1-n10-f2-a4-0-0";
            string expectedContext     = PrepareJson("{ \"GUser\":{\"f_int\":0,\"f_float\":0.5,\"f_str_0\":\"value_0\",\"f_str_1\":\"value_1\"}, \"_multi\": [ { \"TAction\":{\"a_f_0\":\"value_0\",\"a_f_1\":\"value_1\"}},{ \"TAction\":{\"a_f_0\":\"value_1\",\"a_f_1\":\"value_2\"}},{ \"TAction\":{\"a_f_0\":\"value_2\",\"a_f_1\":\"value_3\"}},{ \"TAction\":{\"a_f_0\":\"value_3\",\"a_f_1\":\"value_4\"}}] }");
            string expectedObservation = null;

            const string dsJsonWithObservation = "{\"_label_cost\":-0,\"_label_probability\":0.25,\"_label_Action\":1,\"_labelIndex\":0,\"Version\":\"1\",\"EventId\":\"my_experiment-t1-n10-f2-a4-0-0\",\"a\":[1,2,3,4],\"c\":{ \"GUser\":{\"f_int\":0,\"f_float\":0.5,\"f_str_0\":\"value_0\",\"f_str_1\":\"value_1\"}, \"_multi\": [ { \"TAction\":{\"a_f_0\":\"value_0\",\"a_f_1\":\"value_1\"}},{ \"TAction\":{\"a_f_0\":\"value_1\",\"a_f_1\":\"value_2\"}},{ \"TAction\":{\"a_f_0\":\"value_2\",\"a_f_1\":\"value_3\"}},{ \"TAction\":{\"a_f_0\":\"value_3\",\"a_f_1\":\"value_4\"}}] },\"p\":[0.250000,0.250000,0.250000,0.250000],\"VWState\":{\"m\":\"N/A\"}}";

            // Act
            IStepContext <string> stepContext = ReplayStepProvider.DeserializeReplayStep(dsJsonWithObservation);
            string actualObservation          = stepContext.GetOutcome(0, new ActionProbability[0]);

            Assert.AreEqual(expectedEventId, stepContext.EventId, $"{nameof(stepContext.EventId)} is not properly deserialized.");
            Assert.AreEqual(expectedContext, stepContext.DecisionContext, $"{nameof(stepContext.DecisionContext)} is not properly deserialized.");
            Assert.AreEqual(expectedObservation, actualObservation, $"Observation is not properly deserialized.");
        }
        public void UsingMetadata(
            string text, IStepContext stepContext, IStep step, IScenario scenario, IXunitTestCase scenarioOutline)
        {
            "When I execute a step"
            .f(c => stepContext = c);

            "Then the step context contains metadata about the step"
            .f(() => (step = stepContext.Step.Should().NotBeNull().And.Subject.As <IStep>())
               .DisplayName.Should().Be("Xbehave.Test.Acceptance.MetadataFeature.UsingMetadata(text: \"abc\") [01] When I execute a step"));

            "And the step contains metadata about the scenario"
            .f(() => (scenario = step.Scenario.Should().NotBeNull().And.Subject.As <IScenario>())
               .DisplayName.Should().Be("Xbehave.Test.Acceptance.MetadataFeature.UsingMetadata(text: \"abc\")"));

            "And the step contains metadata about the scenario outline"
            .f(() => scenario.ScenarioOutline.Should().NotBeNull().And.Subject.As <IXunitTestCase>()
               .DisplayName.Should().Be("Xbehave.Test.Acceptance.MetadataFeature.UsingMetadata"));
        }
        public void UsingMetadata(
            string text, IStepContext stepContext, IStep step, IScenario scenario, IXunitTestCase scenarioOutline)
        {
            "When I execute a step"
                .f(c => stepContext = c);

            "Then the step context contains metadata about the step"
                .f(() => (step = stepContext.Step.Should().NotBeNull().And.Subject.As<IStep>())
                    .DisplayName.Should().Be("Xbehave.Test.Acceptance.MetadataFeature.UsingMetadata(text: \"abc\") [01] When I execute a step"));

            "And the step contains metadata about the scenario"
                .f(() => (scenario = step.Scenario.Should().NotBeNull().And.Subject.As<IScenario>())
                    .DisplayName.Should().Be("Xbehave.Test.Acceptance.MetadataFeature.UsingMetadata(text: \"abc\")"));

            "And the step contains metadata about the scenario outline"
                .f(() => scenario.ScenarioOutline.Should().NotBeNull().And.Subject.As<IXunitTestCase>()
                    .DisplayName.Should().Be("Xbehave.Test.Acceptance.MetadataFeature.UsingMetadata"));
        }
        /// <summary>
        /// Immediately registers the <see cref="IDisposable"/> object for disposal after all
        /// steps in the current scenario have been executed.
        /// </summary>
        /// <typeparam name="T">The <see cref="IDisposable"/> object.</typeparam>
        /// <param name="disposable">The object to be disposed.</param>
        /// <param name="stepContext">The execution context for the current step.</param>
        /// <returns>The object.</returns>
        public static T Using <T>(this T disposable, IStepContext stepContext)
            where T : IDisposable
        {
            //Guard.AgainstNullArgument(nameof(stepContext), stepContext);
            //stepContext.Using(disposable);

#if DEBUG
            //// TODO: TBD: not sure just what exactly is going on with this...
            //Validation.Requires.NotNull(stepContext, nameof(stepContext)).Using(disposable);

            stepContext.RequiresNotNull(nameof(stepContext)).Using(disposable);
#else
            // Which, we "do", in DEBUG mode.
#pragma warning disable CA1062 // ...validate parameter 'name' is non-null before using it...
            stepContext.Using(disposable);
#pragma warning restore CA1062 // ...validate parameter 'name' is non-null before using it...
#endif

            return(disposable);
        }
        public StepInvoker(
            IStepContext stepContext
            , Func <IStepContext, Task> body
            , ExceptionAggregator aggregator
            , CancellationTokenSource cancellationTokenSource)
        {
            //Guard.AgainstNullArgument(nameof(aggregator), aggregator);
            //Guard.AgainstNullArgument(nameof(cancellationTokenSource), cancellationTokenSource);

#if DEBUG
            aggregator.RequiresNotNull(nameof(aggregator));
            cancellationTokenSource.RequiresNotNull(nameof(cancellationTokenSource));
#endif

            // TODO: TBD: #3 MWP 2020-07-01 03:15:09 PM / should we validate the other bits?
            this._stepContext             = stepContext;
            this._body                    = body;
            this._aggregator              = aggregator;
            this._cancellationTokenSource = cancellationTokenSource;
        }
Beispiel #21
0
 public StepContext(IStepContext parentStepContext, IStep processingStep) : this(processingStep, parentStepContext.Guid, parentStepContext.WorkingDirectory, parentStepContext.FromSettings)
 {
     _parent = parentStepContext ?? throw new ArgumentNullException($"{parentStepContext}");
 }
 /// <summary>
 /// Immediately registers the <see cref="IDisposable"/> object for disposal
 /// after all steps in the current scenario have been executed.
 /// </summary>
 /// <typeparam name="T">The type of the object.</typeparam>
 /// <param name="disposable">The object to be disposed.</param>
 /// <param name="stepContext">The execution context for the current step.</param>
 /// <returns>The object.</returns>
 public static T Using <T>(this T disposable, IStepContext stepContext)
     where T : IDisposable
 {
     _ = (stepContext?.Using(disposable));
     return(disposable);
 }
        private void Step <TOutcome>(RunContext runContext, IOutcomeReporter <TOutcome> outcomeReporter, IStepContext <TOutcome> step)
        {
            string   eventId = step.EventId;
            TOutcome outcome = default(TOutcome);

            if (loopKind == LoopKind.Slates)
            {
                if (!liveModel.TryRequestMultiSlotDecision(eventId, step.SlatesContext, runContext.MultiSlotResponseContainer, runContext.ApiStatusContainer))
                {
                    this.SafeRaiseError(runContext.ApiStatusContainer);
                }

                int[]   actions = runContext.MultiSlotResponseContainer.Select(slot => slot.ActionId).ToArray();
                float[] probs   = runContext.MultiSlotResponseContainer.Select(slot => slot.Probability).ToArray();
                outcome = step.GetSlatesOutcome(actions, probs);
                if (outcome == null)
                {
                    return;
                }
            }
            else if (loopKind == LoopKind.CA)
            {
                if (!liveModel.TryRequestContinuousAction(eventId, step.ContinuousActionContext, runContext.ContinuousActionContainer, runContext.ApiStatusContainer))
                {
                    this.SafeRaiseError(runContext.ApiStatusContainer);
                }
                float action   = runContext.ContinuousActionContainer.ChosenAction;
                float pdfValue = runContext.ContinuousActionContainer.ChosenActionPdfValue;
                outcome = step.GetContinuousActionOutcome(action, pdfValue);
                if (outcome == null)
                {
                    return;
                }
            }
            else if (loopKind == LoopKind.CCB)
            {
                if (!liveModel.TryRequestDecision(step.DecisionContext, runContext.DecisionResponseContainer, runContext.ApiStatusContainer))
                {
                    this.SafeRaiseError(runContext.ApiStatusContainer);
                }
                // TODO: Populate actionProbs. Currently GetOutcome() just returns a fixed outcome value, so the values of actionProbs don't matter.
                ActionProbability[] actionProbs = new ActionProbability[runContext.DecisionResponseContainer.Count];
                foreach (var slot in runContext.DecisionResponseContainer)
                {
                    outcome = step.GetOutcome(slot.ActionId, actionProbs);
                    if (!outcomeReporter.TryQueueOutcomeEvent(runContext, slot.SlotId, outcome))
                    {
                        this.SafeRaiseError(runContext.ApiStatusContainer);
                    }
                }
                return;
            }
            else if (loopKind == LoopKind.CCBv2)
            {
                if (!liveModel.TryRequestMultiSlotDecisionDetailed(eventId, step.DecisionContext, runContext.MultiSlotResponseDetailedContainer, runContext.ApiStatusContainer))
                {
                    this.SafeRaiseError(runContext.ApiStatusContainer);
                }
                foreach (var slot in runContext.MultiSlotResponseDetailedContainer)
                {
                    outcome = step.GetOutcome(slot.ChosenAction, slot);
                    if (!outcomeReporter.TryQueueOutcomeEvent(runContext, eventId, slot.SlotId, outcome))
                    {
                        this.SafeRaiseError(runContext.ApiStatusContainer);
                    }
                }
                return;
            }
            else
            {
                if (!liveModel.TryChooseRank(eventId, step.DecisionContext, runContext.ResponseContainer, runContext.ApiStatusContainer))
                {
                    this.SafeRaiseError(runContext.ApiStatusContainer);
                }

                long actionIndex = -1;
                if (!runContext.ResponseContainer.TryGetChosenAction(out actionIndex, runContext.ApiStatusContainer))
                {
                    this.SafeRaiseError(runContext.ApiStatusContainer);
                }

                outcome = step.GetOutcome(actionIndex, runContext.ResponseContainer.AsEnumerable());
                if (outcome == null)
                {
                    return;
                }
            }

            if (!outcomeReporter.TryQueueOutcomeEvent(runContext, eventId, outcome))
            {
                this.SafeRaiseError(runContext.ApiStatusContainer);
            }
        }
        private void Step <TOutcome>(RunContext runContext, IOutcomeReporter <TOutcome> outcomeReporter, IStepContext <TOutcome> step)
        {
            string eventId = step.EventId;

            if (!liveModel.TryChooseRank(eventId, step.DecisionContext, runContext.ResponseContainer, runContext.ApiStatusContainer))
            {
                this.SafeRaiseError(runContext.ApiStatusContainer);
            }

            long actionIndex = -1;

            if (!runContext.ResponseContainer.TryGetChosenAction(out actionIndex, runContext.ApiStatusContainer))
            {
                this.SafeRaiseError(runContext.ApiStatusContainer);
            }

            TOutcome outcome = step.GetOutcome(actionIndex, runContext.ResponseContainer.AsEnumerable());

            if (outcome == null)
            {
                return;
            }

            if (!outcomeReporter.TryQueueOutcomeEvent(runContext, eventId, outcome))
            {
                this.SafeRaiseError(runContext.ApiStatusContainer);
            }
        }
Beispiel #25
0
        private void Step <TOutcome>(RunContext runContext, IOutcomeReporter <TOutcome> outcomeReporter, IStepContext <TOutcome> step)
        {
            string   eventId = step.EventId;
            TOutcome outcome = default(TOutcome);

            if (loopKind == LoopKind.Slates)
            {
                if (!liveModel.TryRequestMultiSlotDecision(eventId, step.SlatesContext, runContext.SlatesContainer, runContext.ApiStatusContainer))
                {
                    this.SafeRaiseError(runContext.ApiStatusContainer);
                }

                int[]   actions = runContext.SlatesContainer.Select(slot => slot.ActionId).ToArray();
                float[] probs   = runContext.SlatesContainer.Select(slot => slot.Probability).ToArray();
                outcome = step.GetSlatesOutcome(actions, probs);
                if (outcome == null)
                {
                    return;
                }
            }
            else if (loopKind == LoopKind.CA)
            {
                if (!liveModel.TryRequestContinuousAction(eventId, step.ContinuousActionContext, runContext.ContinuousActionContainer, runContext.ApiStatusContainer))
                {
                    this.SafeRaiseError(runContext.ApiStatusContainer);
                }
                float action   = runContext.ContinuousActionContainer.ChosenAction;
                float pdfValue = runContext.ContinuousActionContainer.ChosenActionPdfValue;
                outcome = step.GetContinuousActionOutcome(action, pdfValue);
                if (outcome == null)
                {
                    return;
                }
            }
            else
            {
                if (!liveModel.TryChooseRank(eventId, step.DecisionContext, runContext.ResponseContainer, runContext.ApiStatusContainer))
                {
                    this.SafeRaiseError(runContext.ApiStatusContainer);
                }

                long actionIndex = -1;
                if (!runContext.ResponseContainer.TryGetChosenAction(out actionIndex, runContext.ApiStatusContainer))
                {
                    this.SafeRaiseError(runContext.ApiStatusContainer);
                }

                outcome = step.GetOutcome(actionIndex, runContext.ResponseContainer.AsEnumerable());
                if (outcome == null)
                {
                    return;
                }
            }

            if (!outcomeReporter.TryQueueOutcomeEvent(runContext, eventId, outcome))
            {
                this.SafeRaiseError(runContext.ApiStatusContainer);
            }
        }
Beispiel #26
0
 public void Execute(IStepContext context)
 {
 }
Beispiel #27
0
 public void Execute(IStepContext context)
 {
     throw new NotImplementedException();
 }