예제 #1
0
        /// <summary>
        /// Gets the metadata associated with a data item.
        /// </summary>
        /// <param name="dataItem">The data item.</param>
        /// <returns>The associated metadata.</returns>
        public static PropertyBag GetMetadata(IDataItem dataItem)
        {
            PropertyBag map = new PropertyBag();

            dataItem.PopulateMetadata(map);
            return(map);
        }
예제 #2
0
            public void Run()
            {
                if (executor.progressMonitor.IsCanceled)
                {
                    outcome = TestOutcome.Canceled;
                    return;
                }

                TestOutcome instanceOutcome;

                try
                {
                    PatternTestInstanceActions decoratedTestInstanceActions = testState.TestActions.TestInstanceActions.Copy();

                    instanceOutcome = primaryContext.Sandbox.Run(TestLog.Writer,
                                                                 new DecorateTestInstanceAction(testState, decoratedTestInstanceActions).Run, "Decorate Child Test");

                    if (instanceOutcome.Status == TestStatus.Passed)
                    {
                        bool invisibleTestInstance = true;

                        PatternTestStep testStep;
                        if (reusePrimaryTestStep)
                        {
                            testStep = testState.PrimaryTestStep;
                            invisibleTestInstance = false;

                            PropertyBag map = DataItemUtils.GetMetadata(bindingItem);
                            foreach (KeyValuePair <string, string> entry in map.Pairs)
                            {
                                primaryContext.AddMetadata(entry.Key, entry.Value);
                            }
                        }
                        else
                        {
                            testStep = new PatternTestStep(testState.Test, testState.PrimaryTestStep,
                                                           testState.Test.Name, testState.Test.CodeElement, false);
                            testStep.Kind = testState.Test.Kind;

                            testStep.IsDynamic = bindingItem.IsDynamic;
                            bindingItem.PopulateMetadata(testStep.Metadata);
                        }

                        var bodyAction        = new RunTestInstanceAction(executor, testCommand);
                        var testInstanceState = new PatternTestInstanceState(testStep, decoratedTestInstanceActions, testState, bindingItem, bodyAction.Run);
                        bodyAction.TestInstanceState = testInstanceState;

                        instanceOutcome = instanceOutcome.CombineWith(primaryContext.Sandbox.Run(
                                                                          TestLog.Writer, new BeforeTestInstanceAction(testInstanceState).Run, "Before Test Instance"));

                        if (instanceOutcome.Status == TestStatus.Passed)
                        {
                            executor.progressMonitor.SetStatus(testStep.Name);

                            TestContext context = reusePrimaryTestStep
                                ? primaryContext
                                : TestContext.PrepareContext(testCommand.StartStep(testStep), primaryContext.Sandbox.CreateChild());
                            testState.SetInContext(context);
                            testInstanceState.SetInContext(context);
                            invisibleTestInstance = false;

                            using (context.Enter())
                            {
                                if (RunTestInstanceBodyAction.CanOptimizeCallChainAndInvokeBodyActionDirectly(testInstanceState))
                                {
                                    bodyAction.SkipProtect = true;
                                    instanceOutcome        = instanceOutcome.CombineWith(bodyAction.Run());
                                }
                                else
                                {
                                    var         runTestInstanceBodyAction = new RunTestInstanceBodyAction(testInstanceState);
                                    TestOutcome sandboxOutcome            = context.Sandbox.Run(TestLog.Writer, runTestInstanceBodyAction.Run, "Body");

                                    instanceOutcome = instanceOutcome.CombineWith(runTestInstanceBodyAction.Outcome.CombineWith(sandboxOutcome));
                                }
                            }

                            if (!reusePrimaryTestStep)
                            {
                                context.FinishStep(instanceOutcome);
                            }

                            executor.progressMonitor.SetStatus("");
                        }

                        instanceOutcome = instanceOutcome.CombineWith(primaryContext.Sandbox.Run(
                                                                          TestLog.Writer, new AfterTestInstanceAction(testInstanceState).Run, "After Test Instance"));

                        if (invisibleTestInstance)
                        {
                            instanceOutcome = PublishOutcomeFromInvisibleTest(testCommand, testStep, instanceOutcome).Outcome;
                        }
                    }
                }
                catch (Exception ex)
                {
                    string message = String.Format("An exception occurred while preparing an instance of test '{0}'.", testState.Test.FullName);

                    if (reusePrimaryTestStep)
                    {
                        TestLog.Failures.WriteException(ex, message);
                        instanceOutcome = TestOutcome.Error;
                    }
                    else
                    {
                        instanceOutcome = ReportTestError(testCommand, testState.PrimaryTestStep, ex, message).Outcome;
                    }
                }

                outcome = instanceOutcome;
            }
예제 #3
0
 /// <summary>
 /// Gets the metadata associated with a data item.
 /// </summary>
 /// <param name="dataItem">The data item.</param>
 /// <returns>The associated metadata.</returns>
 public static PropertyBag GetMetadata(IDataItem dataItem)
 {
     PropertyBag map = new PropertyBag();
     dataItem.PopulateMetadata(map);
     return map;
 }
예제 #4
0
 protected override void PopulateMetadataImpl(PropertyBag map)
 {
     item.PopulateMetadata(map);
 }