예제 #1
0
 /// <inheritdoc />
 protected override void DecorateContainingScope(IPatternScope containingScope, IMethodInfo methodInfo)
 {
     Type formattableType = methodInfo.Parameters[0].Resolve(true).ParameterType;
     var extensionPoints = (IExtensionPoints)RuntimeAccessor.ServiceLocator.ResolveByComponentId("Gallio.ExtensionPoints");
     CustomTestEnvironment.SetUpThreadChain.Before(() => extensionPoints.CustomFormatters.Register(formattableType, x => (string)methodInfo.Resolve(true).Invoke(this, new[] { x })));
     CustomTestEnvironment.TeardownThreadChain.After(() => extensionPoints.CustomFormatters.Unregister(formattableType));
 }
 /// <inheritdoc />
 protected override void DecorateAssemblyTest(IPatternScope assemblyScope, IAssemblyInfo assembly)
 {
     assemblyScope.TestBuilder.TestActions.InitializeTestChain.After(state =>
     {
         TestAssemblyExecutionParameters.DegreeOfParallelism = degreeOfParallelism;
     });
 }
 /// <inheritdoc />
 protected override void DecorateAssemblyTest(IPatternScope assemblyScope, IAssemblyInfo assembly)
 {
     assemblyScope.TestBuilder.TestActions.InitializeTestChain.After(state =>
     {
         TestAssemblyExecutionParameters.DefaultTestCaseTimeout = Timeout;
     });
 }
예제 #4
0
        /// <inheritdoc />
        protected override void DecorateTest(IPatternScope scope, ICodeElementInfo codeElement)
        {
            scope.TestBuilder.TestInstanceActions.RunTestInstanceBodyChain.Around(delegate(PatternTestInstanceState state, Func<PatternTestInstanceState, TestOutcome> inner)
            {
                TestOutcome outcome = TestOutcome.Passed;
                int passedCount = 0;

                for (int i = 0; i < numRepetitions; i++)
                {
                    string name = String.Format("Repetition #{0}", i + 1);
                    TestContext context = TestStep.RunStep(name, delegate
                    {
                        TestOutcome innerOutcome = inner(state);
                        if (innerOutcome.Status != TestStatus.Passed)
                            throw new SilentTestException(innerOutcome);
                    }, null, false, codeElement);

                    outcome = outcome.CombineWith(context.Outcome);
                    if (context.Outcome.Status == TestStatus.Passed)
                        passedCount += 1;
                }

                TestLog.WriteLine(String.Format("{0} of {1} repetitions passed.",
                    passedCount, numRepetitions));

                return outcome;
            });
        }
        /// <inheritdoc />
        protected override void Validate(IPatternScope containingScope, ITypeInfo type)
        {
            base.Validate(containingScope, type);

            if (type.IsAbstract && type.IsSealed)
                ThrowUsageErrorException("This attribute cannot be used on a static class.");
        }
        /// <inheritdoc />
        protected override void Validate(IPatternScope containingScope, IMethodInfo method)
        {
            base.Validate(containingScope, method);

            if (method.Parameters.Count != 0)
                ThrowUsageErrorException("A fixture set-up method must not have any parameters.");
        }
 protected override void DecorateTest(IPatternScope scope, ICodeElementInfo codeElement)
 {
     scope.TestBuilder.TestInstanceActions.DecorateChildTestChain.After(
         delegate(PatternTestInstanceState state, PatternTestActions actions)
         {
             AddDecorator(actions.TestInstanceActions.ExecuteTestInstanceChain);
         });
 }
예제 #8
0
 protected override void PopulateDataSource(IPatternScope scope, DataSource dataSource, ICodeElementInfo codeElement)
 {
     for (int i = 1; i <= count; i++)
     {
         var row = new object[] { i, "Hello from #" + i };
         dataSource.AddDataSet(new ItemSequenceDataSet(new IDataItem[] { new ListDataItem<object>(row, GetMetadata(), false) }, row.Length));
     }
 }
예제 #9
0
        /// <inheritdoc />
        public override void Process(IPatternScope scope, ICodeElementInfo codeElement)
        {
            //TODO: Review: Issue 762: Shouldn't the base method be invoked here?
            //base.Process(scope, codeElement);
            Validate(scope, codeElement);

            scope.TestComponentBuilder.Name = name;
        }
 /// <inheritdoc />
 protected override void DecorateContainingScope(IPatternScope containingScope, IMethodInfo method)
 {
     containingScope.TestBuilder.TestInstanceActions.InitializeTestInstanceChain.After(
         delegate(PatternTestInstanceState testInstanceState)
         {
             testInstanceState.InvokeFixtureMethod(method, EmptyArray<KeyValuePair<ISlotInfo, object>>.Instance);
         });
 }
 /// <inheritdoc />
 public override void Consume(IPatternScope containingScope, ICodeElementInfo codeElement, bool skipChildren)
 {
     //TODO: Review: Issue 762: Shouldn't the base method be invoked here?
     //base.Consume(containingScope, codeElement, skipChildren);
     var method = codeElement as IMethodInfo;
     Validate(containingScope, method);
     containingScope.TestComponentBuilder.AddDeferredAction(codeElement, Order, () => DecorateContainingScope(containingScope, method));
 }
예제 #12
0
 /// <inheritdoc />
 protected override void PopulateDataSource(IPatternScope scope, DataSource dataSource, ICodeElementInfo codeElement)
 {
     var invoker = new FixtureMemberInvoker<IEnumerable>(factoryType, scope, factoryMethodName);
     XDocument xdocument = OpenXDocument(codeElement);
     var parameters = new object[] { GetElementList(xdocument, xPath) };
     var dataSet = new FactoryDataSet(() => invoker.Invoke(parameters), kind, columnCount);
     dataSource.AddDataSet(dataSet);
 }
예제 #13
0
 /// <inheritdoc />
 protected override void PopulateDataSource(IPatternScope scope, DataSource dataSource, ICodeElementInfo codeElement)
 {
     using (var textReader = OpenTextReader(codeElement))
     {
         var text = textReader.ReadToEnd();
         var dataSet = new ValueSequenceDataSet(new[] { text }, null, false);
         dataSource.AddDataSet(dataSet);
     }
 }
        /// <inheritdoc />
        public override void Process(IPatternScope scope, ICodeElementInfo codeElement)
        {
            //TODO: Review: Issue 762: Shouldn't the base method be invoked here?
            //base.Process(scope, codeElement);
            Validate(scope, codeElement);

            foreach (KeyValuePair<string, string> pair in GetMetadata())
                scope.TestComponentBuilder.AddMetadata(pair.Key, pair.Value);
        }
예제 #15
0
        /// <inheritdoc />
        protected override void Validate(IPatternScope containingScope, IMethodInfo method)
        {
            base.Validate(containingScope, method);

            if (method.ReturnType.Resolve(true) != typeof(string))
                ThrowUsageErrorException(String.Format("Expected the custom formatting method '{0}' to return a value of type '{1}', but found '{2}'.", method.Name, typeof(string), method.ReturnType));

            if (method.Parameters.Count != 1)
                ThrowUsageErrorException(String.Format("Expected the custom formatting method '{0}' to take only one parameter, but found {1}.", method.Name, method.Parameters.Count));
        }
예제 #16
0
 /// <inheritdoc />
 protected override void PopulateDataSource(IPatternScope scope, DataSource dataSource, ICodeElementInfo codeElement)
 {
     using (var stream = OpenStream(codeElement))
     {
         var bytes = new byte[stream.Length];
         stream.Read(bytes, 0, bytes.Length);
         var dataSet = new ValueSequenceDataSet(new[] { bytes }, null, false);
         dataSource.AddDataSet(dataSet);
     }
 }
예제 #17
0
        /// <inheritdoc />
        protected override void Validate(IPatternScope containingScope, IMethodInfo method)
        {
            base.Validate(containingScope, method);

            if (method.ReturnType.Resolve(true) == typeof(void))
                ThrowUsageErrorException(String.Format("Expected the custom conversion method '{0}' to not return void.", method.Name));

            if (method.Parameters.Count != 1)
                ThrowUsageErrorException(String.Format("Expected the custom conversion method '{0}' to take only one parameter, but found {1}.", method.Name, method.Parameters.Count));
        }
        /// <inheritdoc />
        public override void Consume(IPatternScope containingScope, ICodeElementInfo codeElement, bool skipChildren)
        {
            //TODO: Review: Issue 762: Shouldn't the base method be invoked here?
            //base.Consume(containingScope, codeElement, skipChildren);
            var type = codeElement as ITypeInfo;
            Validate(containingScope, type);

            ITestBuilder assemblyTest = containingScope.TestBuilder;
            InitializeTest(containingScope, type);
            SetTestSemantics(assemblyTest, type);
        }
        /// <inheritdoc />
        public override void Process(IPatternScope scope, ICodeElementInfo codeElement)
        {
            //TODO: Review: Issue 762: Shouldn't the base method be invoked here?
            //base.Process(scope, codeElement);
            Validate(scope, codeElement);

            scope.TestBuilder.AddDeferredAction(codeElement, Order, delegate
            {
                DecorateTest(scope, codeElement);
            });
        }
        /// <inheritdoc />
        public override void Consume(IPatternScope containingScope, ICodeElementInfo codeElement, bool skipChildren)
        {
            //TODO: Review: Issue 762: Shouldn't the base method be invoked here?
            //base.Consume(containingScope, codeElement, skipChildren);
            IConstructorInfo constructor = codeElement as IConstructorInfo;
            Validate(containingScope, constructor);

            IPatternScope dataContextScope = containingScope.CreateChildTestDataContextScope(codeElement);

            InitializeDataContext(dataContextScope, constructor);
        }
 private IGenerator SafeGetGenerator(IPatternScope scope)
 {
     try
     {
         return GetGenerator(scope);
     }
     catch (ArgumentException exception)
     {
         throw new PatternUsageErrorException(String.Format("The MbUnit data generator was incorrectly initialized ({0}).", exception.Message), exception);
     }
 }
예제 #22
0
 /// <inheritdoc />
 protected override void DecorateContainingScope(IPatternScope containingScope, IMethodInfo method)
 {
     containingScope.TestBuilder.TestInstanceActions.DecorateChildTestChain.After(
         delegate(PatternTestInstanceState testInstanceState, PatternTestActions decoratedChildActions)
         {
             decoratedChildActions.TestInstanceActions.SetUpTestInstanceChain.Before(delegate
             {
                 testInstanceState.InvokeFixtureMethod(method, EmptyArray<KeyValuePair<ISlotInfo, object>>.Instance);
             });
         });
 }
        /// <inheritdoc />
        public override void Consume(IPatternScope containingScope, ICodeElementInfo codeElement, bool skipChildren)
        {
            //TODO: Review: Issue 762: Shouldn't the base method be invoked here?
            //base.Consume(containingScope, codeElement, skipChildren);
            var slot = codeElement as ISlotInfo;
            Validate(containingScope, slot);

            IPatternScope testParameterScope = containingScope.CreateTestParameterScope(slot.Name, slot);
            InitializeTestParameter(testParameterScope, slot);

            testParameterScope.TestParameterBuilder.ApplyDeferredActions();
        }
예제 #24
0
        /// <inheritdoc />
        public override void Process(IPatternScope scope, ICodeElementInfo codeElement)
        {
            //TODO: Review: Issue 762: Shouldn't the base method be invoked here?
            //base.Process(scope, codeElement);
            Validate(scope, codeElement);

            IJoinStrategy strategy = GetJoinStrategy();
            scope.TestBuilder.TestActions.BeforeTestChain.Before(delegate(PatternTestState state)
            {
                state.BindingContext.Strategy = strategy;
            });
        }
 /// <inheritdoc />
 public override void Initialize(IPatternScope rootScope, IAssemblyInfo assembly)
 {
     try
     {
         IAssemblyResolver resolver = (IAssemblyResolver)Activator.CreateInstance(assemblyResolverType);
         rootScope.TestModelBuilder.AddAssemblyResolver(resolver);
     }
     catch (Exception ex)
     {
         throw new PatternUsageErrorException(String.Format("Failed to create custom assembly resolver type '{0}'.", assemblyResolverType), ex);
     }
 }
        /// <inheritdoc />
        protected override void Validate(IPatternScope containingScope, IMethodInfo method)
        {
            base.Validate(containingScope, method);

            if (method.ReturnType.Resolve(true) != typeof(bool))
                ThrowUsageErrorException(String.Format("Expected the custom equality conversion method '{0}' to return '{1}', but found '{2}'.", method.Name, typeof(bool), method.ReturnType));

            if (method.Parameters.Count != 2)
                ThrowUsageErrorException(String.Format("Expected the custom equality conversion method '{0}' to take 2 parameters, but found {1}.", method.Name, method.Parameters.Count));

            if (!method.Parameters[0].ValueType.Equals(method.Parameters[1].ValueType))
                ThrowUsageErrorException(String.Format("Expected the custom equality conversion method '{0}' to take 2 parameters of the same type, but found '{1}' and '{2}'.", method.Name, method.Parameters[0], method.Parameters[1]));
        }
        /// <inheritdoc />
        protected override void DecorateTest(IPatternScope scope, ICodeElementInfo codeElement)
        {
            scope.TestBuilder.TestInstanceActions.RunTestInstanceBodyChain.Around((state, inner) =>
            {
                CultureInfo current = Thread.CurrentThread.CurrentCulture;
                TestOutcome outcome = TestOutcome.Passed;
                int passedCount = 0;

                try
                {
                    foreach (string culture in cultures)
                    {
                        string name = String.Format("Culture {0}", culture);

                        TestContext context = TestStep.RunStep(name, () =>
                        {
                            CultureInfo cultureInfo;

                            try
                            {
                                cultureInfo = new CultureInfo(culture);
                            }
                            catch (Exception exception)
                            {
                                TestContext.CurrentContext.LogWriter.Default.WriteException(exception,
                                    String.Format("An exception occurred while setting the culture to '{0}'.", culture));
                                throw new SilentTestException(TestOutcome.Error);
                            }

                            Thread.CurrentThread.CurrentCulture = cultureInfo;
                            TestOutcome innerOutcome = inner(state);

                            if (innerOutcome.Status != TestStatus.Passed)
                                throw new SilentTestException(innerOutcome);
                        }, null, false, codeElement);

                        outcome = outcome.CombineWith(context.Outcome);

                        if (context.Outcome.Status == TestStatus.Passed)
                            passedCount ++;
                    }
                }
                finally
                {
                    Thread.CurrentThread.CurrentCulture = current;
                }

                TestLog.WriteLine(String.Format("{0} of {1} cultures passed.", passedCount, cultures.Length));
                return outcome;
            });
        }
 /// <inheritdoc />
 protected override void DecorateTest(IPatternScope scope, ICodeElementInfo codeElement)
 {
     // Note: We do this as a test instance decorator to ensure that all of
     //       the setup actions registered by the test or its containing fixture
     //       can be wrapped because this is the last possible opportunity for new
     //       actions to be added.
     scope.TestBuilder.TestActions.DecorateTestInstanceChain.After(delegate(PatternTestState testState, PatternTestInstanceActions decoratedTestInstanceActions)
     {
         WrapDefaultAction(decoratedTestInstanceActions.InitializeTestInstanceChain, Initialize);
         WrapDefaultAction(decoratedTestInstanceActions.SetUpTestInstanceChain, SetUp);
         WrapDefaultAction(decoratedTestInstanceActions.ExecuteTestInstanceChain, Execute);
         WrapDefaultAction(decoratedTestInstanceActions.TearDownTestInstanceChain, TearDown);
         WrapDefaultAction(decoratedTestInstanceActions.DisposeTestInstanceChain, Dispose);
     });
 }
        /// <summary>
        /// Creates a pattern evaluator.
        /// </summary>
        /// <param name="testModelBuilder">The test model builder.</param>
        /// <param name="patternResolver">The pattern resolver.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="testModelBuilder"/> or
        /// <paramref name="patternResolver"/> is null.</exception>
        public DefaultPatternEvaluator(ITestModelBuilder testModelBuilder, IPatternResolver patternResolver)
        {
            if (testModelBuilder == null)
                throw new ArgumentNullException("testModelBuilder");
            if (patternResolver == null)
                throw new ArgumentNullException("patternResolver");

            this.testModelBuilder = testModelBuilder;
            this.patternResolver = patternResolver;

            registeredScopes = new MultiMap<ICodeElementInfo, IPatternScope>();

            var rootDataContextBuilder = new DefaultTestDataContextBuilder(testModelBuilder, new PatternTestDataContext(null));
            rootDataContextBuilder.DefineDataSource("");
            rootScope = new DefaultPatternScope(this, null, testModelBuilder.RootTestBuilder, null, rootDataContextBuilder, false);
        }
예제 #30
0
        /// <inheritdoc />
        protected override void PopulateDataSource(IPatternScope scope, DataSource dataSource, ICodeElementInfo codeElement)
        {
            // Create the invoker object which Gallio will call by reflection
            var invoker = new FixtureMemberInvoker<IEnumerable>(factoryType, scope, factoryMethodName);

            // Get an ADO DataTable from the implementation.
            DataTable dataTable = BuildDataTable();
            
            // Create the array of arguments which will be passed to the method called by the invoker
            var parameters = new object[] {dataTable, 
                this.RowIndexIncludeFilterArray, this.RowIndexExcludeFilterArray,
                this.CellValueIncludeFilterArray, this.CellValueExcludeFilterArray};

            // Create a FactoryDataSet with an invoker of our factory methods in the delegate 
            var dataSet = new FactoryDataSet(() => invoker.Invoke(parameters), FactoryKind.Auto, 0);
            dataSource.AddDataSet(dataSet);
        }
예제 #31
0
 /// <inheritdoc />
 public virtual void Consume(IPatternScope containingScope, ICodeElementInfo codeElement, bool skipChildren)
 {
 }
예제 #32
0
 protected override void PopulateDataSource(IPatternScope scope, DataSource dataSource, Gallio.Common.Reflection.ICodeElementInfo codeElement)
 {
     dataSource.AddDataSet(new SharedDataSet());
     base.PopulateDataSource(scope, dataSource, codeElement);
 }
예제 #33
0
        //private readonly int numRepetitions;
        // private int _maxNumberOfAttempts;

        /// <summary>
        /// Executes the test method repeatedly.
        /// </summary>
        /// <example>
        /// <code><![CDATA[
        /// [Test]
        /// [Repeat(10)]
        /// public void Test()
        /// {
        ///     // This test will be executed 10 times.
        /// }
        /// ]]></code>
        /// </example>
        /// <param name="numRepetitions">The number of times to repeat the test.</param>
        /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="numRepetitions"/>
        /// is less than 1.</exception>



        protected override void DecorateTest(IPatternScope scope, ICodeElementInfo codeElement)
        {
            scope.TestBuilder.TestInstanceActions.RunTestInstanceBodyChain.Around(delegate(PatternTestInstanceState state, Gallio.Common.Func <PatternTestInstanceState, TestOutcome> inner)
            {
                TestOutcome outcome = TestOutcome.Passed;
                int failureCount    = 0;
                // we will try up to 'max' times to get a pass, if we do, then break out and don't run the test anymore
                for (int i = 0; i < FrameGlobals.repeatCount; i++)
                {
                    string name         = String.Format("Repetition #{0}", i + 1);
                    TestContext context = TestStep.RunStep(name, delegate
                    {
                        TestOutcome innerOutcome = inner(state);
                        // if we get a fail, and we have used up the number of attempts allowed to get a pass, throw an error
                        if (innerOutcome.Status != TestStatus.Passed)
                        {
                            throw new SilentTestException(innerOutcome);
                        }
                    }, null, false, codeElement);

                    outcome = context.Outcome;
                    // escape the loop if the test has pa   -0ssed, otherwise increment the failure count
                    if (context.Outcome.Status == TestStatus.Passed)
                    {
                        break;
                    }
                    failureCount++;
                }



                TestLog.WriteLine(String.Format(
                                      failureCount == FrameGlobals.repeatCount
                            ? "Tried {0} times to get a pass test result but didn't get it"
                            : "The test passed on attempt {1} out of {0}", FrameGlobals.repeatCount, failureCount + 1));


                Queue tcStatus2          = new Queue();
                BaseTest.TestDetails tc2 = new BaseTest.TestDetails();

                string parent = Gallio.Framework.TestContext.CurrentContext.Test.Parent.ToString();
                tc2.Name      = Gallio.Framework.TestContext.CurrentContext.Test.Name;
                if (outcome.Status == TestStatus.Passed)
                {
                    tc2.Status = "Pass";
                }
                else
                {
                    tc2.Status = "Fail";
                }

                if (BaseTest.thirdStatus.ContainsKey(parent + tc2.Name))
                {
                    tc2.Status = BaseTest.thirdStatus[parent + tc2.Name];
                }

                if (BaseTest.testStatus.ContainsKey(parent))
                {
                    tcStatus2 = BaseTest.testStatus[parent];
                    tcStatus2.Enqueue(tc2);
                    BaseTest.testStatus.Remove(parent);
                    BaseTest.testStatus.Add(parent, tcStatus2);
                }
                else
                {
                    tcStatus2.Enqueue(tc2);
                    BaseTest.testStatus.Add(Gallio.Framework.TestContext.CurrentContext.Test.Parent.ToString(), tcStatus2);
                }


                return(outcome);
            });
        }
예제 #34
0
 /// <summary>
 /// Returns a generator of random values.
 /// </summary>
 /// <param name="scope">The containing scope.</param>
 /// <returns>A generator.</returns>
 protected abstract IGenerator GetGenerator(IPatternScope scope);
예제 #35
0
 /// <summary>
 /// Populates the data source with the contributions of this attribute.
 /// </summary>
 /// <param name="scope">The scope.</param>
 /// <param name="dataSource">The data source.</param>
 /// <param name="codeElement">The code element.</param>
 protected virtual void PopulateDataSource(IPatternScope scope, DataSource dataSource, ICodeElementInfo codeElement)
 {
 }
예제 #36
0
 /// <inheritdoc />
 protected override void DecorateTest(IPatternScope scope, ICodeElementInfo codeElement)
 {
     scope.TestBuilder.TimeoutFunc = () => Timeout;
 }
 /// <inheritdoc />
 public override void Process(IPatternScope scope, ICodeElementInfo codeElement)
 {
     //TODO: Review: Issue 762: Shouldn't the base method be invoked here?
     //base.Process(scope, codeElement);
     scope.TestModelBuilder.AddAnnotation(new Annotation(type, codeElement, message, details));
 }
예제 #38
0
 /// <summary>
 /// Performs early initialization for the specified assembly.
 /// </summary>
 /// <param name="rootScope">The root scope that will eventually contain the assembly-level test.</param>
 /// <param name="assembly">The assembly to process.</param>
 public abstract void Initialize(IPatternScope rootScope, IAssemblyInfo assembly);
예제 #39
0
 /// <inheritdoc />
 protected override void DecorateTest(IPatternScope scope, ICodeElementInfo codeElement)
 {
     scope.TestBuilder.ApartmentState = apartmentState;
 }
예제 #40
0
 /// <inheritdoc />
 protected override int?GetRandomGeneratorSeed(IPatternScope scope)
 {
     return(GetGeneratorImpl(scope).Seed);
 }
예제 #41
0
 /// <inheritdoc />
 protected override void Validate(IPatternScope scope, ICodeElementInfo codeElement)
 {
     base.Validate(scope, codeElement);
     ValidateSource(scope, codeElement);
 }
예제 #42
0
 protected override void PopulateDataSource(IPatternScope scope, DataSource dataSource, ICodeElementInfo codeElement)
 {
     object[] values = Enumerable.Range(1, count).Select <int, object>(i => Convert.ToChar((Convert.ToInt32('A') + i - 1)).ToString()).ToArray();
     dataSource.AddDataSet(new ValueSequenceDataSet(values, GetMetadata(), false));
 }
예제 #43
0
        /// <inheritdoc />
        protected override void DecorateTest(IPatternScope scope, ICodeElementInfo codeElement)
        {
            scope.TestBuilder.TestInstanceActions.RunTestInstanceBodyChain.Around((state, inner) =>
            {
                TaskContainer container = new TaskContainer();
                try
                {
                    TestOutcome[] threadOutcomes = new TestOutcome[numThreads];
                    TestContext context          = TestContext.CurrentContext;

                    for (int i = 0; i < numThreads; i++)
                    {
                        int index = i;

                        string name = String.Format("Threaded Repetition #{0}", index + 1);
                        var task    = new TestEnvironmentAwareThreadTask(name, delegate
                        {
                            TestContext threadContext = TestStep.RunStep(name, delegate
                            {
                                TestOutcome innerOutcome = inner(state);
                                if (innerOutcome.Status != TestStatus.Passed)
                                {
                                    throw new SilentTestException(innerOutcome);
                                }
                            }, null, false, codeElement);

                            threadOutcomes[index] = threadContext.Outcome;
                        }, null);

                        task.Terminated += delegate
                        {
                            if (!task.Result.HasValue)
                            {
                                threadOutcomes[index] = TestOutcome.Error;
                                context.LogWriter.Default.WriteException(task.Result.Exception,
                                                                         String.Format("An exception occurred while starting Threaded Repetition #{0}.",
                                                                                       index));
                            }
                        };

                        container.Watch(task);
                        task.Start();
                    }

                    container.JoinAll(null);

                    TestOutcome outcome = TestOutcome.Passed;
                    int passedCount     = 0;
                    foreach (TestOutcome threadOutcome in threadOutcomes)
                    {
                        outcome = outcome.CombineWith(threadOutcome);
                        if (threadOutcome.Status == TestStatus.Passed)
                        {
                            passedCount += 1;
                        }
                    }

                    context.LogWriter.Default.WriteLine(String.Format("{0} of {1} threaded repetitions passed.",
                                                                      passedCount, numThreads));

                    return(outcome);
                }
                finally
                {
                    container.AbortAll();
                    container.JoinAll(null);
                }
            });
        }
예제 #44
0
        private IEnumerable GetSequence(IPatternScope scope)
        {
            IGenerator generator = SafeGetGenerator(scope);

            return(generator.Run());
        }
예제 #45
0
 /// <inheritdoc />
 protected override void DecorateTest(IPatternScope scope, ICodeElementInfo codeElement)
 {
     scope.TestBuilder.TestInstanceActions.SetUpTestInstanceChain.Before(state =>
                                                                         Capture.AutoEmbedScreenshot(triggerEvent, AttachmentName, parameters));
 }
예제 #46
0
 /// <summary>
 /// Builds a static test during test exploration.
 /// </summary>
 /// <remarks>
 /// <para>
 /// Subclasses may override this behavior to change how the static test
 /// gets added to the test model.
 /// </para>
 /// </remarks>
 /// <param name="containingScope">The containing pattern evaluation scope.</param>
 /// <param name="declaringCodeElement">The code element that represents the scope in which the test was defined.</param>
 /// <seealso cref="StaticTestFactoryAttribute" />
 protected abstract void BuildStaticTest(IPatternScope containingScope, ICodeElementInfo declaringCodeElement);
예제 #47
0
 /// <inheritdoc />
 protected override void DecorateContainingScope(IPatternScope containingScope, IMethodInfo method)
 {
     containingScope.TestBuilder.TestInstanceActions.TearDownTestInstanceChain.After(state =>
                                                                                     state.InvokeFixtureMethod(method, EmptyArray <KeyValuePair <ISlotInfo, object> > .Instance));
 }
예제 #48
0
 /// <summary>
 /// Gets the code element that declares the tests on which this test should depend.
 /// </summary>
 /// <param name="scope">The scope.</param>
 /// <param name="codeElement">The code element.</param>
 /// <returns>The code element representing the dependency.</returns>
 protected abstract ICodeElementInfo GetDependency(IPatternScope scope, ICodeElementInfo codeElement);
예제 #49
0
        /// <inheritdoc />
        protected override void DecorateTest(IPatternScope scope, ICodeElementInfo codeElement)
        {
            ActionChain <PatternTestInstanceState> executeTestInstanceChain = scope.TestBuilder.TestInstanceActions.ExecuteTestInstanceChain;

            executeTestInstanceChain.Around((state, inner) => ExecuteTestInstanceChainCatchExceptionDecorator(inner, state));
        }
예제 #50
0
 /// <summary>
 /// Verifies that the attribute is being used correctly.
 /// </summary>
 /// <param name="scope">The scope.</param>
 /// <param name="codeElement">The code element.</param>
 /// <exception cref="PatternUsageErrorException">Thrown if the attribute is being used incorrectly.</exception>
 protected virtual void Validate(IPatternScope scope, ICodeElementInfo codeElement)
 {
 }
예제 #51
0
 /// <inheritdoc />
 protected override void DecorateMethodTest(IPatternScope methodScope, IMethodInfo method)
 {
     methodScope.TestBuilder.TestInstanceActions.ExecuteTestInstanceChain.Around(WithMultiple);
 }
예제 #52
0
 /// <inheritdoc />
 protected override IGenerator GetGenerator(IPatternScope scope)
 {
     return(GetGeneratorImpl(scope));
 }
 /// <summary>
 /// Applies decorations to the containing test.
 /// </summary>
 /// <param name="containingScope">The containing scope.</param>
 /// <param name="method">The method to process.</param>
 protected virtual void DecorateContainingScope(IPatternScope containingScope, IMethodInfo method)
 {
 }
예제 #54
0
 /// <inheritdoc />
 public virtual void Process(IPatternScope scope, ICodeElementInfo codeElement)
 {
 }
예제 #55
0
        /// <inheritdoc />
        protected override void DecorateTestParameter(IPatternScope slotScope, ISlotInfo slot)
        {
            var binding = new DataBinding(index, path);

            slotScope.TestParameterBuilder.Binder = new ScalarDataBinder(binding, Source ?? @"");
        }
예제 #56
0
 /// <inheritdoc />
 protected override void BuildStaticTest(IPatternScope containingScope, ICodeElementInfo declaringCodeElement)
 {
     containingScope.Evaluator.Consume(containingScope, Reflector.Wrap(testFixtureType), false, TestTypePatternAttribute.AutomaticInstance);
 }
예제 #57
0
        /// <summary>
        /// Generates static or dynamic tests from the contract.
        /// </summary>
        /// <param name="fieldScope">The field scope.</param>
        /// <param name="field">The field.</param>
        /// <param name="containingScope">The containing scope.</param>
        protected virtual void GenerateTestsFromContract(IPatternScope fieldScope, IFieldInfo field, IPatternScope containingScope)
        {
            if (field.IsStatic)
            {
                FieldInfo resolvedField = field.Resolve(false);
                if (resolvedField == null)
                {
                    fieldScope.TestModelBuilder.AddAnnotation(new Annotation(AnnotationType.Info, field,
                                                                             "This test runner does not fully support static contract verifier methods "
                                                                             + "because the code that defines the contract cannot be executed "
                                                                             + "at test exploration time.  Consider making the contract field non-static instead."));
                    return;
                }

                var contract = resolvedField.GetValue(null) as IContract;
                if (contract == null)
                {
                    fieldScope.TestModelBuilder.AddAnnotation(new Annotation(AnnotationType.Error, field,
                                                                             "Expected the contract field to contain a value that is assignable "
                                                                             + "to type IContract."));
                    return;
                }

                IEnumerable <Test> contractTests = GetContractVerificationTests(contract, field);
                Test.BuildStaticTests(contractTests, fieldScope, field);
            }
            else
            {
                fieldScope.TestBuilder.TestInstanceActions.ExecuteTestInstanceChain.After(state =>
                {
                    var invoker = new FixtureMemberInvoker <IContract>(null, containingScope, field.Name);
                    IContract contract;

                    try
                    {
                        contract = invoker.Invoke(FixtureMemberInvokerTargets.Field);
                    }
                    catch (PatternUsageErrorException exception)
                    {
                        throw new TestFailedException(
                            String.Format(
                                "The field '{0}' must contain an instance of type IContract that describes a contract to be verified.",
                                field.Name), exception);
                    }

                    IEnumerable <Test> contractTests = GetContractVerificationTests(contract, field);

                    TestOutcome outcome = Test.RunDynamicTests(contractTests, field, null, null);
                    if (outcome != TestOutcome.Passed)
                    {
                        throw new SilentTestException(outcome);
                    }
                });
            }
        }
예제 #58
0
 /// <summary>
 /// Applies decorations to a method-level test.
 /// </summary>
 /// <remarks>
 /// <para>
 /// A typical use of this method is to augment the test with additional metadata
 /// or to add additional behaviors to the test.
 /// </para>
 /// </remarks>
 /// <param name="methodScope">The method scope.</param>
 /// <param name="method">The method.</param>
 protected virtual void DecorateMethodTest(IPatternScope methodScope, IMethodInfo method)
 {
 }
예제 #59
0
 protected override void PopulateDataSource(IPatternScope scope, DataSource dataSource, ICodeElementInfo codeElement)
 {
     dataSource.AddDataSet(new ValueSequenceDataSet(Series.I8NotZero, GetMetadata(), false));
 }
예제 #60
0
 /// <inheritdoc />
 protected override void PopulateDataSource(IPatternScope scope, DataSource dataSource, ICodeElementInfo codeElement)
 {
     dataSource.AddDataSet(new ItemSequenceDataSet(new IDataItem[] { new ListDataItem <object>(values, GetMetadata(), false) }, values.Length));
 }