/// <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; }); }
/// <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); }); }
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)); } }
/// <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)); }
/// <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); }
/// <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); }
/// <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)); }
/// <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); } }
/// <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); } }
/// <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(); }
/// <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); }
/// <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); }
/// <inheritdoc /> public virtual void Consume(IPatternScope containingScope, ICodeElementInfo codeElement, bool skipChildren) { }
protected override void PopulateDataSource(IPatternScope scope, DataSource dataSource, Gallio.Common.Reflection.ICodeElementInfo codeElement) { dataSource.AddDataSet(new SharedDataSet()); base.PopulateDataSource(scope, dataSource, codeElement); }
//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); }); }
/// <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);
/// <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) { }
/// <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)); }
/// <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);
/// <inheritdoc /> protected override void DecorateTest(IPatternScope scope, ICodeElementInfo codeElement) { scope.TestBuilder.ApartmentState = apartmentState; }
/// <inheritdoc /> protected override int?GetRandomGeneratorSeed(IPatternScope scope) { return(GetGeneratorImpl(scope).Seed); }
/// <inheritdoc /> protected override void Validate(IPatternScope scope, ICodeElementInfo codeElement) { base.Validate(scope, codeElement); ValidateSource(scope, codeElement); }
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)); }
/// <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); } }); }
private IEnumerable GetSequence(IPatternScope scope) { IGenerator generator = SafeGetGenerator(scope); return(generator.Run()); }
/// <inheritdoc /> protected override void DecorateTest(IPatternScope scope, ICodeElementInfo codeElement) { scope.TestBuilder.TestInstanceActions.SetUpTestInstanceChain.Before(state => Capture.AutoEmbedScreenshot(triggerEvent, AttachmentName, parameters)); }
/// <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);
/// <inheritdoc /> protected override void DecorateContainingScope(IPatternScope containingScope, IMethodInfo method) { containingScope.TestBuilder.TestInstanceActions.TearDownTestInstanceChain.After(state => state.InvokeFixtureMethod(method, EmptyArray <KeyValuePair <ISlotInfo, object> > .Instance)); }
/// <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);
/// <inheritdoc /> protected override void DecorateTest(IPatternScope scope, ICodeElementInfo codeElement) { ActionChain <PatternTestInstanceState> executeTestInstanceChain = scope.TestBuilder.TestInstanceActions.ExecuteTestInstanceChain; executeTestInstanceChain.Around((state, inner) => ExecuteTestInstanceChainCatchExceptionDecorator(inner, state)); }
/// <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) { }
/// <inheritdoc /> protected override void DecorateMethodTest(IPatternScope methodScope, IMethodInfo method) { methodScope.TestBuilder.TestInstanceActions.ExecuteTestInstanceChain.Around(WithMultiple); }
/// <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) { }
/// <inheritdoc /> public virtual void Process(IPatternScope scope, ICodeElementInfo codeElement) { }
/// <inheritdoc /> protected override void DecorateTestParameter(IPatternScope slotScope, ISlotInfo slot) { var binding = new DataBinding(index, path); slotScope.TestParameterBuilder.Binder = new ScalarDataBinder(binding, Source ?? @""); }
/// <inheritdoc /> protected override void BuildStaticTest(IPatternScope containingScope, ICodeElementInfo declaringCodeElement) { containingScope.Evaluator.Consume(containingScope, Reflector.Wrap(testFixtureType), false, TestTypePatternAttribute.AutomaticInstance); }
/// <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); } }); } }
/// <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) { }
protected override void PopulateDataSource(IPatternScope scope, DataSource dataSource, ICodeElementInfo codeElement) { dataSource.AddDataSet(new ValueSequenceDataSet(Series.I8NotZero, GetMetadata(), false)); }
/// <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)); }