/// <inheritdoc />
 public override IList <TestPart> GetTestParts(IPatternEvaluator evaluator, ICodeElementInfo codeElement)
 {
     return(new[] { new TestPart()
                    {
                        IsTestContainer = true
                    } });
 }
Esempio n. 2
0
 /// <summary>
 /// Creates an annotation with a detail message string.
 /// </summary>
 /// <param name="type">The annotation type.</param>
 /// <param name="codeElement">The associated code element, or null if none.</param>
 /// <param name="message">The annotation message.</param>
 /// <param name="details">Additional details such as exception text or null if none.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="message"/> is null.</exception>
 public Annotation(AnnotationType type, ICodeElementInfo codeElement, string message, string details)
 {
     this.type        = type;
     this.codeElement = codeElement;
     this.message     = message;
     this.details     = details;
 }
Esempio n. 3
0
            private bool EvalTestPartPredicate(IDeclaredElement element, Predicate <TestPart> predicate)
            {
#if RESHARPER_45_OR_NEWER
                using (ReadLockCookie.Create())
#endif
                {
                    if (!element.IsValid())
                    {
                        return(false);
                    }

                    try
                    {
                        PsiReflectionPolicy reflectionPolicy = new PsiReflectionPolicy(element.GetManager());
                        ICodeElementInfo    elementInfo      = reflectionPolicy.Wrap(element);
                        if (elementInfo == null)
                        {
                            return(false);
                        }

                        ITestDriver      driver    = CreateTestDriver();
                        IList <TestPart> testParts = driver.GetTestParts(reflectionPolicy, elementInfo);
                        return(GenericCollectionUtils.Exists(testParts, predicate));
                    }
                    catch (Exception ex)
                    {
                        HandleEmbeddedProcessCancelledException(ex);
                        throw;
                    }
                }
            }
Esempio n. 4
0
        /// <summary>
        /// Opens the contents as a stream.
        /// </summary>
        /// <remarks>
        /// <para>
        /// If you override this method to return data from a different stream, consider
        /// also overriding <see cref="ValidateSource" /> in case the manner in which the
        /// data source location is specified has also changed.
        /// </para>
        /// </remarks>
        /// <param name="codeElementInfo">The code element to which the attribute was applied.</param>
        /// <returns>The stream.</returns>
        protected virtual Stream OpenStream(ICodeElementInfo codeElementInfo)
        {
            var content = GetContent();

            content.CodeElementInfo = codeElementInfo;
            return(content.OpenStream());
        }
Esempio n. 5
0
 /// <summary>
 /// Validates the data source properties of the content attribute.
 /// </summary>
 /// <remarks>
 /// <para>
 /// Throws a <see cref="PatternUsageErrorException" /> if none of the source
 /// properties, such as <see cref="Contents"/>, <see cref="FilePath" /> or
 /// <see cref="ResourcePath"/> have been set.
 /// </para>
 /// </remarks>
 /// <param name="scope">The pattern scope.</param>
 /// <param name="codeElement">The code element to which the attribute was applied.</param>
 /// <exception cref="PatternUsageErrorException">Thrown if none of the source properties, such as <see cref="Contents"/>,
 /// <see cref="FilePath" /> or <see cref="ResourcePath"/> have been set.</exception>
 protected virtual void ValidateSource(IPatternScope scope, ICodeElementInfo codeElement)
 {
     if (Contents == null && FilePath == null && ResourcePath == null)
     {
         ThrowUsageErrorException("At least one source property must be specified.");
     }
 }
 /// <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)
 {
     if (!scope.IsTestDeclaration && !scope.IsTestParameterDeclaration)
     {
         ThrowUsageErrorException("This attribute can only be used on a test or test parameter.");
     }
 }
Esempio n. 7
0
 /// <summary>
 /// Gets the attributes of the specified type.
 /// </summary>
 /// <param name="element">The code element.</param>
 /// <param name="inherit">If true, includes inherited attributes.</param>
 /// <typeparam name="T">The attribute type.</typeparam>
 /// <returns>The attributes.</returns>
 public static IEnumerable <T> GetAttributes <T>(ICodeElementInfo element, bool inherit) where T : class
 {
     foreach (T attrib in element.GetAttributes(Reflector.Wrap(typeof(T)), inherit))
     {
         yield return(attrib);
     }
 }
Esempio n. 8
0
 /// <inheritdoc />
 protected override void DecorateTest(IPatternScope scope, ICodeElementInfo codeElement)
 {
     scope.TestBuilder.TestActions.BeforeTestChain.Before(state =>
     {
         throw new SilentTestException(TestOutcome.Skipped, reason);
     });
 }
Esempio n. 9
0
        public override void SetUp()
        {
            fixture1 = Mocks.StrictMock <ITestDescriptor>();
            fixture2 = Mocks.StrictMock <ITestDescriptor>();
            fixture3 = Mocks.StrictMock <ITestDescriptor>();
            fixture4 = Mocks.StrictMock <ITestDescriptor>();

            ICodeElementInfo codeElement1 = Reflector.Wrap(typeof(SimpleTest));

            SetupResult.For(fixture1.CodeElement).Return(codeElement1);
            fixture1TypeName = codeElement1.Name;

            ICodeElementInfo codeElement2 = Reflector.Wrap(typeof(ParameterizedTest));

            SetupResult.For(fixture2.CodeElement).Return(codeElement2);
            fixture2TypeName = codeElement2.Name;

            ICodeElementInfo codeElement3 = Reflector.Wrap(typeof(FixtureInheritanceSample));

            SetupResult.For(fixture3.CodeElement).Return(codeElement3);
            fixture3TypeName = codeElement3.Name;

            ICodeElementInfo codeElement4 = Reflector.Wrap(typeof(DerivedFixture));

            SetupResult.For(fixture4.CodeElement).Return(codeElement4);

            Mocks.ReplayAll();
        }
Esempio n. 10
0
 /// <summary>
 /// Creates an annotation with a detail message string.
 /// </summary>
 /// <param name="type">The annotation type.</param>
 /// <param name="codeElement">The associated code element, or null if none.</param>
 /// <param name="message">The annotation message.</param>
 /// <param name="details">Additional details such as exception text or null if none.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="message"/> is null.</exception>
 public Annotation(AnnotationType type, ICodeElementInfo codeElement, string message, string details)
 {
     this.type = type;
     this.codeElement = codeElement;
     this.message = message;
     this.details = details;
 }
Esempio n. 11
0
        /// <inheritdoc />
        protected override void DecorateTest(IPatternScope scope, ICodeElementInfo codeElement)
        {
            if (IncludeSetUpAndTearDown)
            {
                scope.TestBuilder.TestInstanceActions.BeforeTestInstanceChain.Before(delegate(PatternTestInstanceState state)
                {
                    state.Data.SetValue(TransactionScopeKey, CreateAndEnterTransactionScope(state));
                });

                scope.TestBuilder.TestInstanceActions.AfterTestInstanceChain.After(delegate(PatternTestInstanceState state)
                {
                    TransactionScope transactionScope;
                    if (state.Data.TryGetValue(TransactionScopeKey, out transactionScope))
                    {
                        transactionScope.Dispose();
                    }
                });
            }
            else
            {
                scope.TestBuilder.TestInstanceActions.ExecuteTestInstanceChain.Around(delegate(PatternTestInstanceState state, Action <PatternTestInstanceState> inner)
                {
                    using (CreateAndEnterTransactionScope(state))
                    {
                        inner(state);
                    }
                });
            }
        }
        protected override void ExploreImpl(IReflectionPolicy reflectionPolicy, ICodeElementInfo codeElement)
        {
            InitializeExplorerIfNeeded(reflectionPolicy);

            IAssemblyInfo assembly = ReflectionUtils.GetAssembly(codeElement);
            if (assembly != null)
            {
                bool skipChildren = ! (codeElement is IAssemblyInfo);
                if (BuildAssemblyTest(assembly, skipChildren))
                {
                    foreach (IPatternScope scope in evaluator.GetScopes(assembly))
                        scope.PopulateDeferredComponents(null);

                    assemblies[assembly] = true;
                }
                else
                {
                    ITypeInfo type = ReflectionUtils.GetType(codeElement);
                    if (type != null)
                    {
                        foreach (IPatternScope scope in evaluator.GetScopes(assembly))
                            scope.PopulateDeferredComponents(type);
                    }
                }
            }
        }
 /// <summary>
 /// Use the Gallio's plumbing to locate Files
 /// </summary>
 private XDocument OpenXDocument(string FilePath, ICodeElementInfo codeElement)
 {
     using (TextReader reader = new ContentFile(FilePath).OpenTextReader())
     {
         return(XDocument.Load(reader));
     }
 }
Esempio n. 14
0
 /// <summary>
 /// Uses the existing Gallio plumbing to locate files
 /// </summary>
 protected XDocument OpenXDocument(ICodeElementInfo codeElement)
 {
     using (TextReader reader = OpenTextReader(codeElement))
     {
         return(XDocument.Load(reader));
     }
 }
Esempio n. 15
0
 /// <inheritdoc />
 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.Skipped;
         if (_configValue == "Default")
         {
             TestLog.Warnings.WriteLine("RepeatForConfigValueAttribue did not find a key matching '" + _configKey + "' in the App.Config, using a default value of 1");
             _numberOfRepetitions = 1;
         }
         else
         {
             _numberOfRepetitions = int.Parse(_configValue);
         }
         for (int i = 0; i < _numberOfRepetitions; 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 = context.Outcome;
         }
         return(outcome);
     });
 }
Esempio n. 16
0
        private static void PopulateMethodMetadata(ICodeElementInfo codeElement, PropertyBag metadata)
        {
            foreach (TestAttribute attr in AttributeUtils.GetAttributes <TestAttribute>(codeElement, true))
            {
                // Add timeout
                if (attr.Timeout > 0)
                {
                    TimeSpan timeout = TimeSpan.FromMilliseconds(attr.Timeout);
                    metadata.Add("Timeout", timeout.Seconds.ToString("0.000"));
                }

                // Add categories
                string categories = attr.Categories;
                if (!String.IsNullOrEmpty(categories))
                {
                    foreach (string category in categories.Split(','))
                    {
                        metadata.Add(MetadataKeys.Category, category);
                    }
                }
            }

            // Add expected exception type
            foreach (ExpectedExceptionAttribute attr in AttributeUtils.GetAttributes <ExpectedExceptionAttribute>(codeElement, true))
            {
                metadata.Add(MetadataKeys.ExpectedException, attr.ExceptionType.FullName);
            }

            PopulateCommonMetadata(codeElement, metadata);
        }
Esempio n. 17
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;
            });
        }
Esempio n. 18
0
 /// <summary>
 /// Starts a child step of the context.
 /// </summary>
 /// <param name="name">The name of the step.</param>
 /// <param name="codeElement">The code element, or null if none.</param>
 /// <param name="isTestCase">True if the step represents an independent test case.</param>
 /// <returns>The context of the child step.</returns>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="name"/> is null.</exception>
 internal TestContext StartChildStep(string name, ICodeElementInfo codeElement, bool isTestCase)
 {
     Model.Tree.TestStep testStep = new Model.Tree.TestStep(inner.TestStep.Test, inner.TestStep, name, codeElement, false);
     testStep.IsTestCase = isTestCase;
     testStep.IsDynamic  = true;
     return(PrepareContext(inner.StartChildStep(testStep), Sandbox.CreateChild()));
 }
Esempio n. 19
0
 /// <summary>
 /// Gets the attributes of the specified type.
 /// </summary>
 /// <param name="element">The code element.</param>
 /// <param name="attributeType">The attribute type.</param>
 /// <param name="inherit">If true, includes inherited attributes.</param>
 /// <returns>The attributes.</returns>
 public static IEnumerable <object> GetAttributes(ICodeElementInfo element, Type attributeType, bool inherit)
 {
     foreach (object attrib in element.GetAttributes(Reflector.Wrap(attributeType), inherit))
     {
         yield return(attrib);
     }
 }
Esempio n. 20
0
        /// <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 assembly = codeElement as IAssemblyInfo;

            Validate(containingScope, assembly);

            IPatternScope assemblyScope = containingScope.CreateChildTestScope(assembly.Name, assembly);

            assemblyScope.TestBuilder.Kind = TestKinds.Assembly;
            assemblyScope.TestBuilder.AddMetadata(MetadataKeys.File, assembly.Path);

            InitializeAssemblyTest(assemblyScope, assembly);
            SetTestSemantics(assemblyScope.TestBuilder, assembly);

            if (skipChildren)
            {
                PrepareToPopulateChildrenOnDemand(assemblyScope, assembly);
            }
            else
            {
                PopulateChildrenImmediately(assemblyScope, assembly);
            }

            assemblyScope.TestBuilder.ApplyDeferredActions();
        }
Esempio n. 21
0
        protected override void ExploreImpl(IReflectionPolicy reflectionPolicy, ICodeElementInfo codeElement)
        {
            InitializeExplorerIfNeeded(reflectionPolicy);

            IAssemblyInfo assembly = ReflectionUtils.GetAssembly(codeElement);

            if (assembly != null)
            {
                bool skipChildren = !(codeElement is IAssemblyInfo);
                if (BuildAssemblyTest(assembly, skipChildren))
                {
                    foreach (IPatternScope scope in evaluator.GetScopes(assembly))
                    {
                        scope.PopulateDeferredComponents(null);
                    }

                    assemblies[assembly] = true;
                }
                else
                {
                    ITypeInfo type = ReflectionUtils.GetType(codeElement);
                    if (type != null)
                    {
                        foreach (IPatternScope scope in evaluator.GetScopes(assembly))
                        {
                            scope.PopulateDeferredComponents(type);
                        }
                    }
                }
            }
        }
Esempio n. 22
0
        /// <inheritdoc />
        protected override void DecorateTest(IPatternScope scope, ICodeElementInfo codeElement)
        {
            scope.TestBuilder.TestInstanceActions.RunTestInstanceBodyChain.Around(delegate(PatternTestInstanceState state, GallioFunc <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);
            });
        }
Esempio n. 23
0
        /// <inheritdoc />
        protected override ICodeElementInfo GetDependency(IPatternScope scope, ICodeElementInfo codeElement)
        {
            ITypeInfo resolvedFixtureType;

            if (testFixtureType != null)
            {
                resolvedFixtureType = Reflector.Wrap(testFixtureType);
            }
            else
            {
                resolvedFixtureType = ReflectionUtils.GetType(codeElement);
                if (resolvedFixtureType == null)
                {
                    ThrowUsageErrorException(String.Format("Could not resolve dependency on test method '{0}' because the declaring fixture type is not known.", testMethodName));
                }
            }

            if (testMethodName == null)
            {
                return(resolvedFixtureType);
            }

            IMethodInfo resolvedMethod = resolvedFixtureType.GetMethod(testMethodName, BindingFlags.Public | BindingFlags.Instance);

            if (resolvedMethod == null)
            {
                ThrowUsageErrorException(String.Format("Could not resolve dependency on test method '{0}' of test fixture type '{1}' because the method was not found.",
                                                       testMethodName, resolvedFixtureType));
            }
            return(resolvedMethod);
        }
        /// <summary>
        /// Constructs an execution context for the verification tests of a contract verifier.
        /// </summary>
        /// <param name="codeElement">The code element for the contract read-only field.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="codeElement"/> is null.</exception>
        public ContractVerificationContext(ICodeElementInfo codeElement)
        {
            if (codeElement == null)
                throw new ArgumentNullException("codeElement");

            this.codeElement = codeElement;
        }
Esempio n. 25
0
 /// <summary>
 /// Uses the existing Gallio plumbing to locate files
 /// </summary>
 protected XDocument OpenXDocument(ICodeElementInfo codeElement)
 {
     using (TextReader reader = OpenTextReader(codeElement))
     {
         return XDocument.Load(reader);
     }
 }
Esempio n. 26
0
        /// <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);
            if (!IsReadableFieldOrProperty(codeElement))
            {
                ThrowUsageErrorException("This attribute may only be applied to fields and properties with getters.");
            }

            ISlotInfo slot      = (ISlotInfo)codeElement;
            ITypeInfo mixinType = slot.ValueType;

            if (!mixinType.IsClass || !AttributeUtils.HasAttribute(mixinType, typeof(MixinAttribute), true))
            {
                ThrowUsageErrorException(String.Format("The field or property value type must be a class with the [Mixin] attribute applied.  "
                                                       + "The type {0} does not appear to be a valid mixin class.", mixinType));
            }

            // TODO: Detect cycles.
            // TODO: Modify how fixture types and instances are interpreted in the mixin.

            IPatternScope mixinScope = containingScope.CreateScope(codeElement,
                                                                   containingScope.TestBuilder, null, containingScope.TestDataContextBuilder.CreateChild(), false);

            mixinScope.Consume(mixinType, skipChildren, null);
        }
Esempio n. 27
0
        public static GallioTestElement CreateFromTest(TestData test, ICodeElementInfo codeElement, IUnitTestProvider provider, 
			GallioTestElement parent)
        {
            if (test == null)
                throw new ArgumentNullException("test");

            // The idea here is to generate a test element object that does not retain any direct
            // references to the code element info and other heavyweight objects.  A test element may
            // survive in memory for quite a long time so we don't want it holding on to all sorts of
            // irrelevant stuff.  Basically we flatten out the test to just those properties that we
            // need to keep.
            var element = new GallioTestElement(provider, parent,
                test.Id,
                test.Name,
                test.Metadata.GetValue(MetadataKeys.TestKind) ?? "Unknown",
                test.IsTestCase,
                ReSharperReflectionPolicy.GetProject(codeElement),
                ReSharperReflectionPolicy.GetDeclaredElementResolver(codeElement),
                GetAssemblyPath(codeElement),
                GetTypeName(codeElement),
                GetNamespaceName(codeElement));

            var categories = test.Metadata[MetadataKeys.Category];
            if (categories.Count != 0)
                element.Categories = UnitTestElementCategory.Create(categories);

            var reason = test.Metadata.GetValue(MetadataKeys.IgnoreReason);
            if (reason != null)
                element.ExplicitReason = reason;

            return element;
        }
        /// <inheritdoc />
        public IEnumerable<IPattern> GetPatterns(ICodeElementInfo codeElement)
        {
            if (codeElement == null)
                throw new ArgumentNullException("codeElement");

            foreach (PatternAttribute attribute in AttributeUtils.GetAttributes<PatternAttribute>(codeElement, true))
                yield return attribute;
        }
Esempio n. 29
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;
        }
Esempio n. 30
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);
 }
Esempio n. 31
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 />
 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));
 }
Esempio n. 33
0
        private Test CreateTest(string testName, ICodeElementInfo codeElement)
        {
            var test = new Test(testName, codeElement);

            test.Kind = TestKinds.Unsupported;
            test.Metadata.Add(MetadataKeys.IgnoreReason, FallbackExplanation);
            return(test);
        }
 protected override void DecorateTest(IPatternScope scope, ICodeElementInfo codeElement)
 {
     scope.TestBuilder.TestInstanceActions.DecorateChildTestChain.After(
         delegate(PatternTestInstanceState state, PatternTestActions actions)
         {
             AddDecorator(actions.TestInstanceActions.ExecuteTestInstanceChain);
         });
 }
Esempio n. 35
0
        /// <inheritdoc />
        public IPatternScope CreateScope(ICodeElementInfo codeElement,
                                         ITestBuilder testBuilder, ITestParameterBuilder testParameterBuilder, ITestDataContextBuilder testDataContextBuilder, bool isDeclaration)
        {
            var scope = new DefaultPatternScope(evaluator, codeElement, testBuilder, testParameterBuilder, testDataContextBuilder, isDeclaration);

            evaluator.RegisterScope(scope);
            return(scope);
        }
Esempio n. 36
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));
     }
 }
 protected override void DecorateTest(IPatternScope scope, ICodeElementInfo codeElement)
 {
     scope.TestBuilder.TestInstanceActions.DecorateChildTestChain.After(
         delegate(PatternTestInstanceState state, PatternTestActions actions)
     {
         AddDecorator(actions.TestInstanceActions.ExecuteTestInstanceChain);
     });
 }
Esempio n. 38
0
 /// <summary>
 /// Copies the contents of an annotation.
 /// </summary>
 /// <param name="source">The source annotation.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="source"/> is null.</exception>
 public AnnotationData(Annotation source)
     : this(source.Type,
            source.CodeElement != null ? source.CodeElement.GetCodeLocation() : CodeLocation.Unknown,
            source.CodeElement != null ? source.CodeElement.CodeReference : CodeReference.Unknown,
            source.Message, source.Details)
 {
     codeElement = source.CodeElement;
 }
 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);
     if (IsTest(containingScope.Evaluator, codeElement))
     {
         base.Consume(containingScope, codeElement, skipChildren);
     }
 }
        void AddXmlComment(Test test, ICodeElementInfo element)
        {
            string xml = element.GetXmlDocumentation();

            if (!string.IsNullOrEmpty(xml))
            {
                test.Metadata.Add(MetadataKeys.XmlDocumentation, xml);
            }
        }
Esempio n. 41
0
        /// <summary>
        /// Initializes a test initially without a parent.
        /// </summary>
        /// <param name="name">The name of the test.</param>
        /// <param name="codeElement">The point of definition of the test, or null if unknown.</param>
        /// <param name="dataContext">The data context.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="name"/> or <paramref name="dataContext"/> is null.</exception>
        public PatternTest(string name, ICodeElementInfo codeElement, PatternTestDataContext dataContext)
            : base(name, codeElement)
        {
            if (dataContext == null)
                throw new ArgumentNullException("dataContext");

            this.dataContext = dataContext;
            testActions = new PatternTestActions();
        }
Esempio n. 42
0
        /// <summary>
        /// Explores tests defined by the specified code element and populates the explorer's test model.
        /// </summary>
        /// <param name="reflectionPolicy">The reflection policy.</param>
        /// <param name="codeElement">The code element.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="reflectionPolicy"/>,
        /// <paramref name="codeElement"/> is null.</exception>
        public void Explore(IReflectionPolicy reflectionPolicy, ICodeElementInfo codeElement)
        {
            if (reflectionPolicy == null)
                throw new ArgumentNullException("reflectionPolicy");
            if (codeElement == null)
                throw new ArgumentNullException("codeElement");

            ExploreImpl(reflectionPolicy, codeElement);
        }
        /// <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);
        }
Esempio n. 44
0
        /// <inheritdoc />
        public IEnumerable <IPatternScope> GetScopes(ICodeElementInfo codeElement)
        {
            if (codeElement == null)
            {
                throw new ArgumentNullException("codeElement");
            }

            return(registeredScopes[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);
            var method = codeElement as IMethodInfo;

            Validate(containingScope, method);
            containingScope.TestComponentBuilder.AddDeferredAction(codeElement, Order, () => DecorateContainingScope(containingScope, method));
        }
Esempio n. 46
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);
     }
 }
Esempio n. 47
0
        /// <summary>
        /// Initializes a test initially without a parent.
        /// </summary>
        /// <param name="name">The name of the component.</param>
        /// <param name="codeElement">The point of definition, or null if none.</param>
        /// <param name="typeInfo">The Xunit test type information.</param>
        /// <param name="methodInfo">The Xunit test method information, or null if none.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="name"/> or <paramref name="typeInfo"/> is null.</exception>
        public XunitTest(string name, ICodeElementInfo codeElement, XunitTypeInfoAdapter typeInfo, XunitMethodInfoAdapter methodInfo)
            : base(name, codeElement)
        {
            if (typeInfo == null)
                throw new ArgumentNullException(@"typeInfo");

            this.typeInfo = typeInfo;
            this.methodInfo = methodInfo;
        }
Esempio n. 48
0
        /// <inheritdoc />
        public IList<TestPart> GetTestParts(IReflectionPolicy reflectionPolicy, ICodeElementInfo codeElement)
        {
            if (reflectionPolicy == null)
                throw new ArgumentNullException("reflectionPolicy");
            if (codeElement == null)
                throw new ArgumentNullException("codeElement");

            return GetTestPartsImpl(reflectionPolicy, codeElement);
        }
 /// <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);
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="ConcordionTest"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="codeElement">The code element.</param>
        /// <param name="typeInfo">The type info.</param>
        /// <param name="resource">The resource.</param>
        /// <param name="fixtureType">The fixture type.</param>
        public ConcordionTest(string name, ICodeElementInfo codeElement, ConcordionTypeInfoAdapter typeInfo, Resource resource, Type fixtureType)
            : base(name, codeElement)
        {
            if (typeInfo == null)
                throw new ArgumentNullException(@"typeInfo");

            this.TypeInfo = typeInfo;
            this.Resource = resource;
            this.FixtureType = fixtureType;
        }
Esempio n. 51
0
        /// <summary>
        /// Initializes a test component.
        /// </summary>
        /// <param name="name">The name of the component.</param>
        /// <param name="codeElement">The point of definition of the component, or null if unknown.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="name"/> is null.</exception>
        public TestComponent(string name, ICodeElementInfo codeElement)
        {
            if (name == null)
                throw new ArgumentNullException(@"name");

            this.name = name;
            this.codeElement = codeElement;

            metadata = new PropertyBag();
        }
        /// <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);
            });
        }
Esempio n. 53
0
 private void RunDeferredAction(ICodeElementInfo codeElement, Action deferredAction)
 {
     try
     {
         deferredAction();
     }
     catch (Exception ex)
     {
         GetTestModelBuilder().PublishExceptionAsAnnotation(codeElement, ex);
     }
 }
        /// <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);
        }
        /// <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);
        }
Esempio n. 56
0
        /// <inheritdoc />
        public void AddDeferredAction(ICodeElementInfo codeElement, int order, Action deferredAction)
        {
            if (codeElement == null)
                throw new ArgumentNullException("codeElement");
            if (deferredAction == null)
                throw new ArgumentNullException("deferredAction");

            if (deferredActions == null)
                deferredActions = new List<Triple<ICodeElementInfo, int, Action>>();

            deferredActions.Add(new Triple<ICodeElementInfo, int, Action>(codeElement, order, deferredAction));
        }
Esempio n. 57
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;
            });
        }
Esempio n. 58
0
        private static bool IsReadableFieldOrProperty(ICodeElementInfo codeElement)
        {
            IFieldInfo field = codeElement as IFieldInfo;
            if (field != null)
                return true;

            IPropertyInfo property = codeElement as IPropertyInfo;
            if (property != null)
                return property.GetMethod != null;

            return false;
        }
        /// <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();
        }
Esempio n. 60
0
        protected override void ExploreImpl(IReflectionPolicy reflectionPolicy, ICodeElementInfo codeElement)
        {
            IAssemblyInfo assembly = ReflectionUtils.GetAssembly(codeElement);
            if (assembly != null)
            {
                Version frameworkVersion = GetFrameworkVersion(assembly);

                if (frameworkVersion != null)
                {
                    GetAssemblyTest(assembly, TestModel.RootTest, frameworkVersion);
                }
            }
        }